示例#1
0
def main():
    module_name = ModuleName(sys.argv[1])

    setMainScriptDirectory(os.getcwd())

    my_print(" ".join(
        locateModule(module_name=module_name, parent_package=None, level=0)))
示例#2
0
    def _buildPackage(self, build_lib):
        # Nuitka wants the main package by filename, probably we should stop
        # needing that.
        from nuitka.importing.Importing import findModule, setMainScriptDirectory
        from nuitka.utils.Execution import getExecutablePath

        old_dir = os.getcwd()
        os.chdir(build_lib)

        # Search in the build directory preferrably.
        setMainScriptDirectory('.')

        package, main_filename, finding = findModule(
            importing=None,
            module_name=self.main_package,
            parent_package=None,
            level=0,
            warn=False)

        # Check expectations, e.g. do not compile built-in modules.
        assert finding == "absolute", finding
        assert package is None, package

        recurse_packages = self.compile_packages.copy()
        if os.path.isdir(self.main_package):
            # Include all python files in wheel
            for root, dirs, files in os.walk(self.main_package):
                for fn in fnmatch.filter(files, '*.py'):
                    module = os.path.join(
                        root, fn)[:-3] if fn != '__init__.py' else root
                    pypath = ".".join(module.split(os.sep))
                    recurse_packages.append(pypath)

        command = [
            sys.executable,
            "-m",
            "nuitka",
            "--module",
            "--plugin-enable=pylint-warnings",
            "--output-dir=%s" % build_lib,
            "--recurse-dir=%s" % self.main_package,
            "--recurse-not-to=*.tests",
            "--show-modules",
            "--remove-output",
            main_filename,
        ] + ["--recurse-to=%s" % p for p in recurse_packages]

        subprocess.check_call(command)
        os.chdir(old_dir)

        self.build_lib = build_lib
示例#3
0
    def _buildPackage(self, build_lib):
        # Nuitka wants the main package by filename, probably we should stop
        # needing that.
        from nuitka.importing.Importing import findModule, setMainScriptDirectory
        from nuitka.utils.Execution import getExecutablePath

        old_dir = os.getcwd()
        os.chdir(build_lib)

        # Search in the build directory preferrably.
        setMainScriptDirectory('.')

        package, main_filename, finding = findModule(
            importing=None,
            module_name=self.main_package,
            parent_package=None,
            level=0,
            warn=False)

        # Check expectations, e.g. do not compile built-in modules.
        assert finding == "absolute", finding
        assert package is None, package

        nuitka_binary = getExecutablePath("nuitka")
        if nuitka_binary is None:
            sys.exit("Error, cannot find nuitka binary in PATH.")

        command = [
            sys.executable,
            nuitka_binary,
            "--module",
            "--plugin-enable=pylint-warnings",
            "--output-dir=%s" % build_lib,
            "--recurse-to={%s}" % ','.join(self.compile_packages),
            "--recurse-dir=%s" % self.main_package,
            "--recurse-not-to=*.tests",
            "--show-modules",
            "--remove-output",
            main_filename,
        ]

        subprocess.check_call(command)
        os.chdir(old_dir)

        self.build_lib = build_lib
示例#4
0
    def _build(self, build_lib):
        # High complexity, pylint: disable=too-many-branches,too-many-locals

        # Nuitka wants the main package by filename, probably we should stop
        # needing that.
        from nuitka.importing.Importing import findModule, setMainScriptDirectory
        from nuitka.utils.ModuleNames import ModuleName
        from nuitka.__past__ import (  # pylint: disable=I0021,redefined-builtin
            Iterable,
            unicode,
        )

        old_dir = os.getcwd()
        os.chdir(build_lib)

        # Search in the build directory preferably.
        setMainScriptDirectory(".")

        to_builds = self._find_to_build()
        for to_build in to_builds:
            package, main_filename, finding = findModule(
                importing=None,
                module_name=ModuleName(to_build.module_name),
                parent_package=None,
                level=0,
                warn=False,
            )

            # Check expectations, e.g. do not compile built-in modules.
            assert finding == "absolute", finding

            if package is not None:
                output_dir = os.path.join(build_lib, package)
            else:
                output_dir = build_lib

            command = [
                sys.executable,
                "-m",
                "nuitka",
                "--module",
                "--plugin-enable=pylint-warnings",
                "--output-dir=%s" % output_dir,
                "--nofollow-import-to=*.tests",
                "--show-modules",
                "--remove-output",
            ]

            if type(to_build) is PyPackage:
                command += [
                    "--include-package=%s" % package_name.replace("/", ".")
                    for package_name in to_build.related_packages
                ]

            else:  # type(to_build) is PyModule
                command += [
                    "--include-module=%s" % module_name
                    for module_name in to_build.related_modules
                ]

            # Process any extra options from setuptools
            if "nuitka" in self.distribution.command_options:
                for option, value in self.distribution.command_options[
                    "nuitka"
                ].items():
                    option = "--" + option.lstrip("-")
                    if value is None:
                        command.append(option)
                    elif isinstance(value, bool):
                        option = "--" + ("no" if not value else "") + option.lstrip("-")
                        command.append(option)
                    elif isinstance(value, Iterable) and not isinstance(
                        value, (unicode, bytes, str)
                    ):
                        for val in value:
                            command.append("%s=%s" % (option, val))
                    else:
                        command.append("%s=%s" % (option, value))

            command.append(main_filename)

            # added for clarity
            my_print("Building: %s" % to_build, style="yellow")
            subprocess.check_call(command, cwd=build_lib)

            for root, _, filenames in os.walk(build_lib):
                for filename in filenames:
                    fullpath = os.path.join(root, filename)

                    if fullpath.lower().endswith((".py", ".pyw", ".pyc", ".pyo")):
                        os.unlink(fullpath)

            os.chdir(old_dir)

            self.build_lib = build_lib
示例#5
0
    def _buildPackage(self, build_lib):
        # High complexity, pylint: disable=too-many-branches,too-many-locals

        # Nuitka wants the main package by filename, probably we should stop
        # needing that.
        from nuitka.importing.Importing import findModule, setMainScriptDirectory

        old_dir = os.getcwd()
        os.chdir(build_lib)

        # Search in the build directory preferably.
        setMainScriptDirectory(".")

        package, main_filename, finding = findModule(
            importing=None,
            module_name=self.main_package,
            parent_package=None,
            level=0,
            warn=False,
        )

        # Check expectations, e.g. do not compile built-in modules.
        assert finding == "absolute", finding
        assert package is None, package

        # If there are other files left over in the wheel after python scripts
        # are compiled, we'll keep the folder structure with the files in the wheel
        keep_resources = False

        python_files = []
        if os.path.isdir(main_filename):
            # Include all python files in wheel
            for root, dirs, files in os.walk(main_filename):
                if "__pycache__" in dirs:
                    dirs.remove("__pycache__")
                    shutil.rmtree(os.path.join(root, "__pycache__"))

                for fn in files:
                    if fn.lower().endswith((".py", ".pyc", ".pyo")):
                        # These files will definitely be deleted once nuitka
                        # has compiled the main_package
                        python_files.append(os.path.join(root, fn))
                    else:
                        keep_resources = True

        output_dir = build_lib

        command = [
            sys.executable,
            "-m",
            "nuitka",
            "--module",
            "--plugin-enable=pylint-warnings",
            "--output-dir=%s" % output_dir,
            "--include-package=%s" % self.main_package,
            "--nofollow-import-to=*.tests",
            "--show-modules",
            "--remove-output",
        ]

        # Process any extra options from setuptools
        if "nuitka" in self.distribution.command_options:
            for option, details in self.distribution.command_options["nuitka"].items():
                option = "--" + option.lstrip("-")
                _source, value = details
                if value is None:
                    command.append(option)
                elif isinstance(value, collections.Iterable) and not isinstance(
                    value, (unicode, bytes, str)
                ):
                    for val in value:
                        command.append("%s=%s" % (option, val))
                else:
                    command.append("%s=%s" % (option, value))

        command.append(main_filename)

        subprocess.check_call(command, cwd=build_lib)
        os.chdir(old_dir)

        self.build_lib = build_lib

        if keep_resources:
            # Delete the individual source files
            for fn in python_files:
                os.unlink(fn)
        else:
            # Delete the entire source copy of the module
            shutil.rmtree(os.path.join(self.build_lib, self.main_package))
示例#6
0
    def _build(self, build_lib):
        # High complexity, pylint: disable=too-many-branches,too-many-locals

        # Nuitka wants the main package by filename, probably we should stop
        # needing that.

        old_dir = os.getcwd()
        os.chdir(build_lib)

        if self.distribution.package_dir and "" in self.distribution.package_dir:
            main_package_dir = self.distribution.package_dir.get("")
        else:
            main_package_dir = os.path.abspath(old_dir)

        # Search in the build directory preferably.
        setMainScriptDirectory(main_package_dir)

        for is_package, module_name in self._find_to_build():
            module_name, main_filename, finding = locateModule(
                module_name=module_name,
                parent_package=None,
                level=0,
            )

            package = module_name.getPackageName()

            # Check expectations, e.g. do not compile built-in modules.
            assert finding == "absolute", finding

            if package is not None:
                output_dir = os.path.join(build_lib, package.asPath())
            else:
                output_dir = build_lib

            command = [
                sys.executable,
                "-m",
                "nuitka",
                "--module",
                "--enable-plugin=pylint-warnings",
                "--output-dir=%s" % output_dir,
                "--nofollow-import-to=*.tests",
                "--remove-output",
            ]

            if is_package:
                command.append("--include-package=%s" % module_name)

            else:
                command.append("--include-module=%s" % module_name)

            toml_filename = os.environ.get("NUITKA_TOML_FILE")
            if toml_filename:
                # Import toml parser like "build" module does.
                try:
                    from tomli import loads as toml_loads
                except ImportError:
                    from toml import loads as toml_loads

                # Cannot use FileOperations.getFileContents() here, because of non-Nuitka process
                # pylint: disable=unspecified-encoding

                with open(toml_filename) as toml_file:
                    toml_options = toml_loads(toml_file.read())

                for option, value in toml_options.get("nuitka", {}).items():
                    command.extend(self._parseOptionsEntry(option, value))

            # Process any extra options from setuptools
            if "nuitka" in self.distribution.command_options:
                for option, value in self.distribution.command_options[
                        "nuitka"].items():
                    command.extend(self._parseOptionsEntry(option, value))

            command.append(main_filename)

            # Adding traces for clarity
            wheel_logger.info(
                "Building: '%s' with command %r" %
                (module_name.asString(), command),
                style="blue",
            )
            check_call(command, cwd=build_lib)
            wheel_logger.info("Finished compilation of '%s'." %
                              module_name.asString(),
                              style="green")

            for root, _, filenames in os.walk(build_lib):
                for filename in filenames:
                    fullpath = os.path.join(root, filename)

                    if fullpath.lower().endswith(
                        (".py", ".pyw", ".pyc", ".pyo")):
                        os.unlink(fullpath)

        self.build_lib = build_lib

        os.chdir(old_dir)
示例#7
0
    def _buildPackage(self, build_lib):
        # Nuitka wants the main package by filename, probably we should stop
        # needing that, pylint: disable=too-many-locals
        from nuitka.importing.Importing import findModule, setMainScriptDirectory

        old_dir = os.getcwd()
        os.chdir(build_lib)

        # Search in the build directory preferably.
        setMainScriptDirectory('.')

        package, main_filename, finding = findModule(
            importing      = None,
            module_name    = self.main_package,
            parent_package = None,
            level          = 0,
            warn           = False
        )

        # Check expectations, e.g. do not compile built-in modules.
        assert finding == "absolute", finding
        assert package is None, package

        # If there are other files left over in the wheel after python scripts
        # are compiled, we'll keep the folder structure with the files in the wheel
        keep_resources = False

        python_files = []
        if os.path.isdir(main_filename):
            # Include all python files in wheel
            for root, dirs, files in os.walk(main_filename):
                if "__pycache__" in dirs:
                    dirs.remove("__pycache__")
                    shutil.rmtree(os.path.join(root, "__pycache__"))

                for fn in files:
                    if fn.lower().endswith((".py", ".pyc", ".pyo")):
                        # These files will definitely be deleted once nuitka
                        # has compiled the main_package
                        python_files.append(os.path.join(root, fn))
                    else:
                        keep_resources = True

        output_dir = build_lib

        command = [
            sys.executable,
            "-m", "nuitka",
            "--module",
            "--plugin-enable=pylint-warnings",
            "--output-dir=%s" % output_dir,
            "--recurse-dir=%s" % self.main_package,
            "--recurse-to=%s" % self.main_package,
            "--recurse-not-to=*.tests",
            "--show-modules",
            "--remove-output",
            main_filename,
        ]

        subprocess.check_call(
            command
        )
        os.chdir(old_dir)

        self.build_lib = build_lib

        if keep_resources:
            # Delete the individual source files
            for fn in python_files:
                os.unlink(fn)
        else:
            # Delete the entire source copy of the module
            shutil.rmtree(os.path.join(self.build_lib, self.main_package))
示例#8
0
    def _build(self, build_lib):
        # High complexity, pylint: disable=too-many-branches,too-many-locals

        # Nuitka wants the main package by filename, probably we should stop
        # needing that.

        old_dir = os.getcwd()
        os.chdir(build_lib)

        # Search in the build directory preferably.
        setMainScriptDirectory(os.path.abspath(old_dir))

        for is_package, module_name in self._find_to_build():
            module_name, main_filename, finding = locateModule(
                module_name=module_name,
                parent_package=None,
                level=0,
            )

            package = module_name.getPackageName()

            # Check expectations, e.g. do not compile built-in modules.
            assert finding == "absolute", finding

            if package is not None:
                output_dir = os.path.join(build_lib, package.asPath())
            else:
                output_dir = build_lib

            command = [
                sys.executable,
                "-m",
                "nuitka",
                "--module",
                "--enable-plugin=pylint-warnings",
                "--output-dir=%s" % output_dir,
                "--nofollow-import-to=*.tests",
                "--remove-output",
            ]

            if is_package:
                command.append("--include-package=%s" % module_name)

            else:
                command.append("--include-module=%s" % module_name)

            # Process any extra options from setuptools
            if "nuitka" in self.distribution.command_options:
                for option, value in self.distribution.command_options[
                        "nuitka"].items():
                    option = "--" + option.lstrip("-")

                    if (type(value) is tuple and len(value) == 2
                            and value[0] == "setup.py"):
                        value = value[1]

                    if value is None:
                        command.append(option)
                    elif isinstance(value, bool):
                        option = "--" + ("no" if not value else
                                         "") + option.lstrip("-")
                        command.append(option)
                    elif isinstance(value, Iterable) and not isinstance(
                            value, (unicode, bytes, str)):
                        for val in value:
                            command.append("%s=%s" % (option, val))
                    else:
                        command.append("%s=%s" % (option, value))

            command.append(main_filename)

            # Adding traces for clarity
            wheel_logger.info(
                "Building: '%s' with command %r" %
                (module_name.asString(), command),
                style="blue",
            )
            check_call(command, cwd=build_lib)
            wheel_logger.info("Finished compilation of '%s'." %
                              module_name.asString(),
                              style="green")

            for root, _, filenames in os.walk(build_lib):
                for filename in filenames:
                    fullpath = os.path.join(root, filename)

                    if fullpath.lower().endswith(
                        (".py", ".pyw", ".pyc", ".pyo")):
                        os.unlink(fullpath)

        self.build_lib = build_lib

        os.chdir(old_dir)