Пример #1
0
 def makeIncludedEmptyDirectories(self, source_path, dest_paths, reason,
                                  tags):
     return makeIncludedEmptyDirectories(
         source_path=source_path,
         dest_paths=dest_paths,
         reason=reason,
         tracer=self,
         tags=tags,
     )
Пример #2
0
def _getSubDirectoryFolders(module, subdirs):
    """Get dirnames in given subdirs of the module.

    Notes:
        All dirnames in folders below one of the subdirs are recursively
        retrieved and returned shortened to begin with the string of subdir.
    Args:
        module: module object
        subdirs: sub folder name(s) - tuple
    Returns:
        makeIncludedEmptyDirectories of found dirnames.
    """

    module_dir = module.getCompileTimeDirectory()
    file_list = []

    data_dirs = [os.path.join(module_dir, subdir) for subdir in subdirs]

    # Gather the full file list, probably makes no sense to include bytecode files
    file_list = sum(
        (
            getFileList(
                data_dir, ignore_dirs=("__pycache__",), ignore_suffixes=(".pyc",)
            )
            for data_dir in data_dirs
        ),
        [],
    )

    if not file_list:
        msg = "No files or folders found for '%s' in subfolder(s) %r (%r)." % (
            module.getFullName(),
            subdirs,
            data_dirs,
        )
        NuitkaPluginDataFileCollector.warning(msg)

    is_package = module.isCompiledPythonPackage() or module.isUncompiledPythonPackage()

    # We need to preserve the package target path in the dist folder.
    if is_package:
        package_part = module.getFullName().asPath()
    else:
        package = module.getFullName().getPackageName()

        if package is None:
            package_part = ""
        else:
            package_part = package.asPath()

    item_set = OrderedSet()

    for f in file_list:
        target = os.path.join(package_part, os.path.relpath(f, module_dir))

        dir_name = os.path.dirname(target)
        item_set.add(dir_name)

    return makeIncludedEmptyDirectories(
        source_path=module_dir,
        dest_paths=item_set,
        reason="Subdirectories of module %s" % module.getFullName(),
    )
Пример #3
0
    def considerDataFiles(self, module):
        # Many cases to deal with, pylint: disable=too-many-branches

        module_name = module.getFullName()
        module_folder = module.getCompileTimeDirectory()

        config = self.config.get(module_name)

        if config:
            target_dir = config.get("dest_path")

            # Default to near module or inside package folder.
            if target_dir is None:
                if (
                    module.isCompiledPythonPackage()
                    or module.isUncompiledPythonPackage()
                ):
                    target_dir = module_name.asPath()
                else:
                    package_name = module_name.getPackageName()

                    if package_name is not None:
                        target_dir = module_name.getPackageName().asPath()
                    else:
                        target_dir = "."

            patterns = config.get("patterns")
            if patterns is not None:
                if type(patterns) is not list or not patterns:
                    self.sysexit(
                        "Error, requiring list below 'pattern' entry for '%s' entry."
                        % module_name
                    )

                # TODO: Pattern should be data file kind potentially.
                for pattern in patterns:
                    pattern = os.path.join(module_folder, pattern)

                    for filename in resolveShellPatternToFilenames(pattern):
                        yield makeIncludedDataFile(
                            source_path=filename,
                            dest_path=os.path.normpath(
                                os.path.join(target_dir, os.path.basename(filename))
                            ),
                            reason="package data for %r" % module_name.asString(),
                        )

            empty_dirs = config.get("empty_dirs")
            if empty_dirs is not None:
                if type(empty_dirs) is not list or not empty_dirs:
                    self.sysexit(
                        "Error, requiring list below 'empty_dirs' entry for '%s' entry."
                        % module_name
                    )

                yield makeIncludedEmptyDirectories(
                    source_path=target_dir,
                    dest_paths=tuple(
                        os.path.join(target_dir, empty_dir) for empty_dir in empty_dirs
                    ),
                    reason="empty dir needed for %r" % module_name.asString(),
                )

            empty_dir_structures = config.get("empty_dir_structures")
            if empty_dir_structures is not None:
                if type(empty_dir_structures) is not list or not empty_dir_structures:
                    self.sysexit(
                        "Error, requiring list below 'empty_dirs_structure' entry for '%s' entry."
                        % module_name
                    )

                # TODO: This ignored dest_path, which is unused, but not consistent.
                yield _getSubDirectoryFolders(module, empty_dir_structures)

            dirs = config.get("dirs")
            if dirs is not None:
                if type(dirs) is not list or not dirs:
                    self.sysexit(
                        "Error, requiring list below 'empty_dirs_structure' entry for '%s' entry."
                        % module_name
                    )

                for data_dir in dirs:
                    source_path = os.path.join(module_folder, data_dir)

                    if os.path.isdir(source_path):
                        yield makeIncludedDataDirectory(
                            source_path=source_path,
                            dest_path=os.path.join(target_dir, data_dir),
                            reason="package data directory for %r"
                            % module_name.asString(),
                        )
Пример #4
0
def _getSubDirectoryFiles2(module, subdirs, folders_only):
    """Get filenames or dirnames in given subdirs of the module.

    Notes:
        All filenames in folders below one of the subdirs are recursively
        retrieved and returned shortened to begin with the string of subdir.
    Args:
        module: module object
        subdirs: sub folder name(s) - str or None or tuple
        folders_only: (bool) indicate, whether just the folder structure should
            be generated. In that case, an empty file named DUMMY will be
            placed in each of these folders.
    Yields:
        Tuples of paths (source, dest) are yielded if folders_only is False,
        else IncludedDataFile instances for empty dirs.
    """

    module_dir = module.getCompileTimeDirectory()
    file_list = []

    if subdirs is None:
        data_dirs = [module_dir]
    elif isinstance(subdirs, basestring):
        data_dirs = [os.path.join(module_dir, subdirs)]
    else:
        data_dirs = [os.path.join(module_dir, subdir) for subdir in subdirs]

    # Gather the full file list, probably makes no sense to include bytecode files
    file_list = sum(
        (getFileList(data_dir,
                     ignore_dirs=("__pycache__", ),
                     ignore_suffixes=(".pyc", )) for data_dir in data_dirs),
        [],
    )

    if not file_list:
        msg = "No files or folders found for '%s' in subfolder(s) %r (%r)." % (
            module.getFullName(),
            subdirs,
            data_dirs,
        )
        NuitkaPluginDataFileCollector.warning(msg)

    is_package = module.isCompiledPythonPackage(
    ) or module.isUncompiledPythonPackage()

    # We need to preserve the package target path in the dist folder.
    if is_package:
        package_part = module.getFullName().asPath()
    else:
        package = module.getFullName().getPackageName()

        if package is None:
            package_part = ""
        else:
            package_part = package.asPath()

    item_set = OrderedSet()

    for f in file_list:
        target = os.path.join(package_part, os.path.relpath(f, module_dir))

        if folders_only:
            dir_name = os.path.dirname(target)
            item_set.add(dir_name)
        else:
            item_set.add((f, target))

    if folders_only:
        return makeIncludedEmptyDirectories(
            source_path=module_dir,
            dest_paths=item_set,
            reason="Subdirectories of module %s" % module.getFullName(),
        )

    return item_set