Example #1
0
    def considerDataFiles(self, module):
        # Many cases to deal with, pylint: disable=too-many-branches

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

        if module_name in self.known_data_files:
            for target_dir, filename in self.known_data_files[module_name]:
                source_path = os.path.join(module_folder, filename)

                if os.path.isfile(source_path):
                    if target_dir is None:
                        target_dir = module_name.asPath()

                    yield (
                        source_path,
                        os.path.normpath(os.path.join(target_dir, filename)),
                    )

        if module_name in self.known_data_dirs:
            data_dirs = self.known_data_dirs[module_name]

            if type(data_dirs) is not tuple:
                data_dirs = (data_dirs, )

            for data_dir in data_dirs:
                yield makeIncludedDataDirectory(
                    os.path.join(module_folder, data_dir),
                    os.path.join(module_name.asPath(), data_dir),
                    "package data for %r" % module_name.asString(),
                )

        if module_name in self.known_data_dir_structure:
            empty_dirs = self.known_data_dir_structure[module_name]

            yield _getSubDirectoryFolders(module, empty_dirs)

        if module_name in self.generated_data_files:
            for target_dir, filename, func in self.generated_data_files[
                    module_name]:
                if target_dir is None:
                    target_dir = module_name.replace(".", os.path.sep)

                yield (func,
                       os.path.normpath(os.path.join(target_dir, filename)))

        if module_name == "lib2to3.pgen2":
            # TODO: Support patterns of files in known_data_files as
            # that would cover this.
            for source_path, filename in listDir(
                    os.path.join(module_folder, "..")):
                if not filename.endswith(".pickle"):
                    continue

                yield makeIncludedDataFile(
                    source_path,
                    os.path.join("lib2to3", filename),
                    "package data for %r" % module_name.asString(),
                )
Example #2
0
    def considerDataFiles(self, module):
        if module.getFullName() != "matplotlib":
            return

        matplotlib_info = self._getMatplotlibInfo()

        if not os.path.isdir(matplotlib_info.data_path):
            self.sysexit(
                "mpl-data missing, matplotlib installation appears to be broken"
            )

        # Include the "mpl-data" files.
        yield makeIncludedDataDirectory(
            source_path=matplotlib_info.data_path,
            dest_path=os.path.join("matplotlib", "mpl-data"),
            ignore_dirs=("sample_data",),
            ignore_filenames=("matplotlibrc",),
            reason="package data for 'matplotlib",
        )

        # Handle the config file with an update.
        new_lines = []  # new config file lines

        found = False  # checks whether backend definition encountered
        for line in getFileContentByLine(matplotlib_info.matplotlibrc_filename):
            line = line.rstrip()

            # omit meaningless lines
            if line.startswith("#") and matplotlib_info.matplotlib_version < "3":
                continue

            new_lines.append(line)

            if line.startswith(("backend ", "backend:")):
                # old config file has a backend definition
                found = True

        if not found and matplotlib_info.matplotlib_version < "3":
            # Set the backend, so even if it was run time determined, we now enforce it.
            new_lines.append("backend: %s" % matplotlib_info.backend)

        yield makeIncludedGeneratedDataFile(
            data=new_lines,
            dest_path=os.path.join("matplotlib", "mpl-data", "matplotlibrc"),
            reason="Updated matplotlib config file with backend to use.",
        )
Example #3
0
    def considerDataFiles(self, module):
        """Copy typelib files from the default installation path"""
        if module.getFullName() == "gi":
            path = self.queryRuntimeInformationMultiple(
                info_name="gi_info",
                setup_codes="import gi; from gi.repository import GObject",
                values=((
                    "introspection_module",
                    "gi.Repository.get_default().get_typelib_path('GObject')",
                ), ),
            )

            gi_repository_path = os.path.dirname(path.introspection_module)
            yield makeIncludedDataDirectory(
                source_path=gi_repository_path,
                dest_path="girepository",
                reason="typelib files for gi modules",
            )
Example #4
0
 def makeIncludedDataDirectory(
         self,
         source_path,
         dest_path,
         reason,
         tags="",
         ignore_dirs=(),
         ignore_filenames=(),
         ignore_suffixes=(),
         only_suffixes=(),
         normalize=True,
 ):
     return makeIncludedDataDirectory(
         source_path=source_path,
         dest_path=dest_path,
         reason=reason,
         tracer=self,
         tags=tags,
         ignore_dirs=ignore_dirs,
         ignore_filenames=ignore_filenames,
         ignore_suffixes=ignore_suffixes,
         only_suffixes=only_suffixes,
         normalize=normalize,
     )
Example #5
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(),
                        )
Example #6
0
    def considerDataFiles(self, module):
        """Provide TCL libraries to the dist folder.

        Notes:
            We will provide the copy the TCL/TK directories to the program's root directory,
            that might be shiftable with some work.

        Args:
            module: the module in question, maybe ours

        Yields:
            IncludedDataFile objects.
        """
        if not _isTkInterModule(module):
            return

        # Check typical locations of the dirs
        candidates_tcl = (
            os.environ.get("TCL_LIBRARY"),
            os.path.join(sys.prefix, "tcl", "tcl8.5"),
            os.path.join(sys.prefix, "tcl", "tcl8.6"),
            os.path.join(sys.prefix, "lib", "tcl8.5"),
            os.path.join(sys.prefix, "lib", "tcl8.6"),
            "/usr/share/tcltk/tcl8.6",
            "/usr/share/tcltk/tcl8.5",
            "/usr/share/tcl8.6",
            "/usr/share/tcl8.5",
            "/usr/lib64/tcl/tcl8.5",
            "/usr/lib64/tcl/tcl8.6",
        )

        candidates_tk = (
            os.environ.get("TK_LIBRARY"),
            os.path.join(sys.prefix, "tcl", "tk8.5"),
            os.path.join(sys.prefix, "tcl", "tk8.6"),
            os.path.join(sys.prefix, "lib", "tk8.5"),
            os.path.join(sys.prefix, "lib", "tk8.6"),
            "/usr/share/tcltk/tk8.6",
            "/usr/share/tcltk/tk8.5",
            "/usr/share/tk8.6",
            "/usr/share/tk8.5",
            "/usr/lib64/tcl/tk8.5",
            "/usr/lib64/tcl/tk8.6",
        )

        tcl = self.tcl_library_dir
        if tcl is None:
            for tcl in candidates_tcl:
                if tcl is not None and os.path.exists(tcl):
                    break

        if tcl is None or not os.path.exists(tcl):
            self.sysexit(
                "Could not find Tcl, you might need to set 'TCL_LIBRARY' and if that works, report a bug."
            )

        tk = self.tk_library_dir
        if tk is None:
            for tk in candidates_tk:
                if tk is not None and os.path.exists(tk):
                    break

        if tk is None or not os.path.exists(tk):
            self.sysexit(
                "Could not find Tk, you might need to set 'TK_LIBRARY' and if that works, report a bug."
            )

        # survived the above, now do provide the locations
        yield makeIncludedDataDirectory(
            source_path=tk,
            dest_path="tk",
            reason="Tk copy needed for standalone Tcl",
            ignore_dirs=("demos",),
        )
        yield makeIncludedDataDirectory(
            source_path=tcl,
            dest_path="tcl",
            reason="Tcl needed for tkinter usage",
        )