Пример #1
0
def _cleanupClangFormat(filename):
    """ Call clang-format on a given filename to format C code.

    Args:
        filename: What file to re-format.
    """

    # Using global here, as this is really a singleton, in
    # the form of a module, pylint: disable=global-statement
    global warned_clang_format

    clang_format_path = getExecutablePath("clang-format-7")

    # Extra ball on Windows, check default installation PATH too.
    if not clang_format_path and getOS() == "Windows":
        with withEnvironmentPathAdded(
                "PATH",
                r"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\8.0.0\bin",
        ):
            with withEnvironmentPathAdded("PATH",
                                          r"C:\Program Files\LLVM\bin"):
                clang_format_path = getExecutablePath("clang-format")

    if clang_format_path:
        subprocess.call([
            clang_format_path,
            "-i",
            "-style={BasedOnStyle: llvm, IndentWidth: 4, ColumnLimit: 120}",
            filename,
        ])
    else:
        if not warned_clang_format:

            warning("Need to install LLVM for C files format.")
            warned_clang_format = True
Пример #2
0
def _cleanupClangFormat(filename):
    # Using global here, as this is really a singleton, in
    # the form of a module, pylint: disable=global-statement
    global warned_clang_format

    clang_format_path = getExecutablePath("clang-format")

    # Extra ball on Windows, check default installation PATH too.
    if not clang_format_path and getOS() == "Windows":
        with withEnvironmentPathAdded("PATH", r"C:\Program Files\LLVM\bin"):
            clang_format_path = getExecutablePath("clang-format")

    if clang_format_path:
        subprocess.call(
            [
                clang_format_path,
                "-i",
                "-style={BasedOnStyle: llvm, IndentWidth: 4, ColumnLimit: 120}",
                filename,
            ]
        )
    else:
        if not warned_clang_format:

            warning("Need to install LLVM for C files format.")
            warned_clang_format = True
Пример #3
0
def _getPythonBinaryCall(binary_name):
    if binary_name not in _binary_calls:
        messages = []

        # Try running Python installation.
        try:
            __import__(binary_name)
        except ImportError:
            pass
        else:
            call = [sys.executable, "-m", binary_name]

            ok, message = _checkRequiredVersion(binary_name, call)

            if ok:
                _binary_calls[binary_name] = call
                return _binary_calls[binary_name]
            else:
                messages.append(message)

        with withEnvironmentPathAdded(
            "PATH", os.path.join(sys.prefix, "Scripts"), os.path.join(sys.prefix, "bin")
        ):
            binary_path = getExecutablePath(binary_name)

        if binary_path:
            call = [binary_path]

            ok, message = _checkRequiredVersion(binary_name, call)

            if ok:
                _binary_calls[binary_name] = call
                return _binary_calls[binary_name]
            else:
                messages.append(message)

        if messages:
            my_print("ERROR")
        for message in messages:
            my_print(message, style="red")

        sys.exit(
            "Error, cannot find %r version %r, not installed or wrong version for this Python?"
            % (binary_name, _getRequiredVersion(binary_name))
        )

    return _binary_calls[binary_name]
Пример #4
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
Пример #5
0
def _getPythonBinaryCall(binary_name):
    if binary_name not in _binary_calls:
        # Try running Python installation.
        try:
            __import__(binary_name)
            _binary_calls[binary_name] = [sys.executable, "-m", binary_name]

            return _binary_calls[binary_name]
        except ImportError:
            pass

        binary_path = getExecutablePath(binary_name)

        if binary_path:
            _binary_calls[binary_name] = [binary_path]
            return _binary_calls[binary_name]

        sys.exit("Error, cannot find %s, not installed for this Python?" % binary_name)

    return _binary_calls[binary_name]
Пример #6
0
    def _nuitka_script():
        """
        TODO: setuptools.entry_points handling could probably be used to find the correct location for any platform
        :return:
        """
        from nuitka.utils.Execution import getExecutablePath
        nuitka_binary = getExecutablePath("nuitka")

        if nuitka_binary is None:
            # Fallback method, only works on windows
            path = Path(sys.executable).parent
            nuitka_binary = path / 'nuitka'

            bindir = 'Scripts' if os.name == 'nt' else 'bin'
            if not nuitka_binary.exists() and path.name != bindir:
                path = path / bindir
                if not path.exists():
                    raise ValueError("Cannot find scripts/bin directory? %s" % path)
                nuitka_binary = path / 'nuitka'

        if not Path(nuitka_binary).exists():
            raise ValueError("Nuitka binary cannot be found on path or python scripts dir")

        return nuitka_binary
Пример #7
0
    def execute_tests(where, use_python, flags):
        # Many cases, pylint: disable=too-many-branches,too-many-statements

        my_print(
            "Executing test case called '%s' with CPython '%s' and extra flags '%s'."
            % (where, use_python, flags))

        intended_version = use_python[6:]
        if sys.version.startswith(intended_version):
            os.environ["PYTHON"] = sys.executable
        else:
            if os.name == "nt":
                os.environ["PYTHON"] = getPythonExePathWindows(
                    search=intended_version, arch=None)
            else:
                os.environ["PYTHON"] = getExecutablePath(use_python)

        if options.basic_tests:
            my_print("Running the basic tests with options '%s' with '%s':" %
                     (flags, use_python))
            setExtraFlags(where, "basics", flags)
            executeSubTest("./tests/basics/run_all.py search")

        if options.syntax_tests:
            my_print("Running the syntax tests with options '%s' with '%s':" %
                     (flags, use_python))
            setExtraFlags(where, "syntax", flags)
            executeSubTest("./tests/syntax/run_all.py search")

        if options.program_tests:
            my_print("Running the program tests with options '%s' with '%s':" %
                     (flags, use_python))
            setExtraFlags(where, "programs", flags)
            executeSubTest("./tests/programs/run_all.py search")

        if options.package_tests:
            my_print("Running the package tests with options '%s' with '%s':" %
                     (flags, use_python))
            setExtraFlags(where, "packages", flags)
            executeSubTest("./tests/packages/run_all.py search")

        if options.plugin_tests:
            my_print("Running the plugin tests with options '%s' with '%s':" %
                     (flags, use_python))
            setExtraFlags(where, "plugins", flags)
            executeSubTest("./tests/plugins/run_all.py search")

        # At least one Debian Jessie, these versions won't have lxml installed, so
        # don't run them there. Also these won't be very version dependent in their
        # results.
        if use_python != "python2.6":
            if options.optimization_tests:
                my_print(
                    "Running the optimizations tests with options '%s' with '%s':"
                    % (flags, use_python))
                setExtraFlags(where, "optimizations", flags)
                executeSubTest("./tests/optimizations/run_all.py search")

        if options.standalone_tests and not options.coverage:
            my_print(
                "Running the standalone tests with options '%s' with '%s':" %
                (flags, use_python))
            setExtraFlags(None, "standalone", flags)
            executeSubTest("./tests/standalone/run_all.py search")

        if options.reflection_test and not options.coverage:
            my_print(
                "Running the reflection test with options '%s' with '%s':" %
                (flags, use_python))
            setExtraFlags(None, "reflected", flags)
            executeSubTest("./tests/reflected/compile_itself.py search")

        if not use_python.startswith("python3"):
            if os.path.exists("./tests/CPython26/run_all.py"):
                if options.cpython26:
                    my_print(
                        "Running the CPython 2.6 tests with options '%s' with '%s':"
                        % (flags, use_python))

                    setExtraFlags(where, "26tests", flags)
                    executeSubTest("./tests/CPython26/run_all.py search")
            else:
                my_print("The CPython2.6 tests are not present, not run.")

            # Running the Python 2.7 test suite with CPython 2.6 gives little
            # insight, because "importlib" will not be there and that's it.
            if use_python != "python2.6":
                if os.path.exists("./tests/CPython27/run_all.py"):
                    if options.cpython27:
                        my_print(
                            "Running the CPython 2.7 tests with options '%s' with '%s':"
                            % (flags, use_python))
                        setExtraFlags(where, "27tests", flags)
                        executeSubTest("./tests/CPython27/run_all.py search")
                else:
                    my_print("The CPython2.7 tests are not present, not run.")

        if "--debug" not in flags:
            # Not running the Python 3.2 test suite with CPython2.6, as that's about
            # the same as CPython2.7 and won't have any new insights.
            if use_python not in ("python2.6",
                                  "python2.7") or not options.coverage:
                if os.path.exists("./tests/CPython32/run_all.py"):
                    if options.cpython32:
                        setExtraFlags(where, "32tests", flags)
                        executeSubTest("./tests/CPython32/run_all.py search")
                else:
                    my_print("The CPython3.2 tests are not present, not run.")

            # Running the Python 3.3 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython33/run_all.py"):
                    if options.cpython33:
                        setExtraFlags(where, "33tests", flags)
                        executeSubTest("./tests/CPython33/run_all.py search")
                else:
                    my_print("The CPython3.3 tests are not present, not run.")

            # Running the Python 3.4 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython34/run_all.py"):
                    if options.cpython34:
                        setExtraFlags(where, "34tests", flags)
                        executeSubTest("./tests/CPython34/run_all.py search")
                else:
                    my_print("The CPython3.4 tests are not present, not run.")

            # Running the Python 3.5 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython35/run_all.py"):
                    if options.cpython35:
                        setExtraFlags(where, "35tests", flags)
                        executeSubTest("./tests/CPython35/run_all.py search")
                else:
                    my_print("The CPython3.5 tests are not present, not run.")

            # Running the Python 3.6 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython36/run_all.py"):
                    if options.cpython36:
                        setExtraFlags(where, "36tests", flags)
                        executeSubTest("./tests/CPython36/run_all.py search")
                else:
                    my_print("The CPython3.6 tests are not present, not run.")

            # Running the Python 3.7 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython37/run_all.py"):
                    if options.cpython36:
                        setExtraFlags(where, "37tests", flags)
                        executeSubTest("./tests/CPython37/run_all.py search")
                else:
                    my_print("The CPython3.7 tests are not present, not run.")

            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython38/run_all.py"):
                    if options.cpython36:
                        setExtraFlags(where, "38tests", flags)
                        executeSubTest("./tests/CPython38/run_all.py search")
                else:
                    my_print("The CPython3.8 tests are not present, not run.")

        if "NUITKA_EXTRA_OPTIONS" in os.environ:
            del os.environ["NUITKA_EXTRA_OPTIONS"]
Пример #8
0
def main():
    goHome()

    if os.name == "nt":
        git_path = getExecutablePath("git")

        if git_path is None:
            git_path = r"C:\Program Files\Git\bin\sh.exe"

            if not os.path.exists(git_path):
                git_path = None

        if git_path is None:
            sys.exit("""\
Error, cannot locate 'git.exe' which we need to install git hooks. Add it to
PATH while executing this will be sufficient.""")

        sh_path = os.path.join(os.path.dirname(git_path), "sh.exe")

        if not os.path.exists(sh_path):
            sh_path = os.path.join(os.path.dirname(git_path), "..", "..",
                                   "bin", "sh.exe")

        sh_path = os.path.normpath(sh_path)

        if not os.path.exists(sh_path):
            sys.exit("""\
Error, cannot locate 'sh.exe' near 'git.exe' which we need to install git hooks,
please improve this script.""")

        # For MinGW and #! we will need a path without spaces, so use this
        # code to find the short name, that won't have it.
        sh_path = getWindowsShortPathName(sh_path)

    for hook in os.listdir(".githooks"):
        full_path = os.path.join(".githooks", hook)

        hook_contents = getFileContents(full_path)

        if hook_contents.startswith("#!/bin/sh"):
            if os.name == "nt":
                # Correct shebang for Windows git to work.
                hook_contents = "#!%s\n%s" % (
                    sh_path.replace("\\", "/").replace(" ", r"\ "),
                    hook_contents[10:],
                )

                # Also use sys.executable to make sure we find autoformat.
                hook_contents = hook_contents.replace(
                    "./bin/autoformat-nuitka-source",
                    "'%s' ./bin/autoformat-nuitka-source" % sys.executable,
                )
        else:
            sys.exit("Error, unknown hook contents.")

        hook_target = os.path.join(".git/hooks/", hook)
        with open(hook_target, "wb") as out_file:
            out_file.write(hook_contents.encode("utf8"))

        st = os.stat(hook_target)
        os.chmod(hook_target, st.st_mode | stat.S_IEXEC)
Пример #9
0
def main():
    goHome()

    parser = OptionParser()

    parser.add_option(
        "--upload",
        action="store_true",
        dest="upload",
        default=False,
        help="""\
Upload to http://nuitka.net/apidoc requires access rights and is done by the
official servers automatically only. Without this, create the local html folder
only.

Default is %default.""",
    )

    options, _positional_args = parser.parse_args()

    shutil.rmtree("html", ignore_errors=True)

    doxygen_path = getExecutablePath("doxygen")

    # Extra ball on Windows, check default installation PATH too.
    if not doxygen_path and getOS() == "Windows":
        with withEnvironmentPathAdded("PATH", r"C:\Program Files\Doxygen\bin"):
            doxygen_path = getExecutablePath("doxygen")

    if not doxygen_path:
        sys.exit(
            "Error, need to install Doxygen and add it to PATH for this to work."
        )

    try:
        import doxypypy  # @UnusedImport pylint: disable=I0021,unused-import,unused-variable
    except ImportError:
        sys.exit("Error, needs to install doxypypy into this Python.")

    with withTemporaryFile(suffix=".doxyfile", delete=False) as doxy_file:
        doxy_config = getFileContents("doc/Doxyfile.template")

        with withTemporaryFile(
                suffix=".bat" if getOS() == "Windows" else ".sh",
                delete=False) as doxy_batch_file:
            if getOS() == "Windows":
                doxy_batch_file.write("%s -m doxypypy.doxypypy -a -c %%1" %
                                      sys.executable)
            else:
                doxy_batch_file.write(
                    "#!/bin/sh\nexec '%s' -m doxypypy.doxypypy -a -c $1" %
                    sys.executable)

        doxy_batch_filename = doxy_batch_file.name

        doxy_config = doxy_config.replace("%DOXYPYPY%", doxy_batch_filename)
        doxy_file.write(doxy_config)

        doxy_filename = doxy_file.name

    print("Running doxygen:")
    try:
        subprocess.check_call([doxygen_path, doxy_filename])
    finally:
        os.unlink(doxy_filename)
        os.unlink(doxy_batch_filename)

    # Update the repository on the web site.
    if options.upload:
        assert (os.system(
            "rsync -avz --delete html/ --chown www-data [email protected]:/var/www/apidoc/"
        ) == 0)

    print("Finished.")
Пример #10
0
def parseArgs():
    """Parse the command line arguments

    :meta private:
    """
    # singleton with many cases checking the options right away.
    # pylint: disable=global-statement,too-many-branches,too-many-locals,too-many-statements
    global is_nuitka_run, options, positional_args, extra_args, is_debug, is_nondebug
    global is_fullcompat, is_report_missing, is_verbose

    if os.name == "nt":
        # Windows store Python's don't allow looking at the python, catch that.
        try:
            with openTextFile(sys.executable, "rb"):
                pass
        except OSError:
            Tracing.general.sysexit(
                "Error, the Python from Windows store is not supported, check the User Manual of Nuitka ."
            )

    is_nuitka_run, options, positional_args, extra_args = parseOptions(
        logger=Tracing.options_logger)

    is_debug = _isDebug()
    is_nondebug = not is_debug
    is_fullcompat = _isFullCompat()

    # TODO: Have dedicated option for it.
    is_report_missing = is_debug

    if options.quiet or int(os.environ.get("NUITKA_QUIET", "0")):
        Tracing.setQuiet()

    if not shallDumpBuiltTreeXML():
        Tracing.options_logger.info("Used command line options: %s" %
                                    " ".join(sys.argv[1:]))

    if os.environ.get("NUITKA_REEXECUTION") and not isAllowedToReexecute():
        Tracing.general.sysexit(
            "Error, not allowed to re-execute, but that has happened.")

    if options.progress_bar:
        Progress.enableProgressBar()

    if options.verbose_output:
        Tracing.optimization_logger.setFileHandle(
            # Can only have unbuffered binary IO in Python3, therefore not disabling buffering here.
            openTextFile(options.verbose_output, "w", encoding="utf8"))

        options.verbose = True

    is_verbose = options.verbose

    Tracing.optimization_logger.is_quiet = not options.verbose

    if options.show_inclusion_output:
        Tracing.inclusion_logger.setFileHandle(
            # Can only have unbuffered binary IO in Python3, therefore not disabling buffering here.
            openTextFile(options.show_inclusion_output, "w", encoding="utf8"))

        options.show_inclusion = True

    Tracing.progress_logger.is_quiet = not options.show_progress

    # Onefile implies standalone build.
    if options.is_onefile:
        options.is_standalone = True

    # Standalone implies no_site build
    if options.is_standalone:
        options.python_flags.insert(0, "no_site")

    # Provide a tempdir spec implies onefile tempdir, even on Linux.
    if options.onefile_tempdir_spec:
        options.is_onefile_tempdir = True

        if os.path.normpath(options.onefile_tempdir_spec) == ".":
            Tracing.options_logger.sysexit("""\
Error, using '.' as a value for '--onefile-tempdir-spec' is not supported,
you cannot unpack the onefile payload into the same directory as the binary,
as that would overwrite it and cause locking issues as well.""")

        if options.onefile_tempdir_spec.count("%") % 2 != 0:
            Tracing.options_logger.warning(
                """Unmatched '%%' is suspicious for '--onefile-tempdir-spec' and may
not do what you want it to do: '%s'""" % options.onefile_tempdir_spec)

        if options.onefile_tempdir_spec.count("%") == 0:
            Tracing.options_logger.warning(
                """Not using any variables for '--onefile-tempdir-spec' should only be
done if your program absolutely needs to be in the same path always: '%s'""" %
                options.onefile_tempdir_spec)

        if os.path.isabs(options.onefile_tempdir_spec):
            Tracing.options_logger.warning(
                """Using an absolute path should be avoided unless you are targeting a
very well known environment: '%s'""" % options.onefile_tempdir_spec)
        elif relpath(options.onefile_tempdir_spec):
            Tracing.options_logger.warning(
                """Using an relative path above the executable should be avoided unless you are targeting a
very well known environment: '%s'""" % options.onefile_tempdir_spec)

    # Standalone mode implies an executable, not importing "site" module, which is
    # only for this machine, recursing to all modules, and even including the
    # standard library.
    if options.is_standalone:
        if options.module_mode:
            Tracing.options_logger.sysexit("""\
Error, conflicting options, cannot make standalone module, only executable.

Modules are supposed to be imported to an existing Python installation, therefore it
makes no sense to include a Python runtime.""")

    for any_case_module in getShallFollowModules():
        if any_case_module.startswith("."):
            bad = True
        else:
            for char in "/\\:":
                if char in any_case_module:
                    bad = True
                    break
            else:
                bad = False

        if bad:
            Tracing.options_logger.sysexit("""\
Error, '--follow-import-to' takes only module names or patterns, not directory path '%s'."""
                                           % any_case_module)

    for no_case_module in getShallFollowInNoCase():
        if no_case_module.startswith("."):
            bad = True
        else:
            for char in "/\\:":
                if char in no_case_module:
                    bad = True
                    break
            else:
                bad = False

        if bad:
            Tracing.options_logger.sysexit("""\
Error, '--nofollow-import-to' takes only module names or patterns, not directory path '%s'."""
                                           % no_case_module)

    scons_python = getPythonPathForScons()

    if scons_python is not None and not os.path.isfile(scons_python):
        Tracing.options_logger.sysexit(
            "Error, no such Python binary %r, should be full path." %
            scons_python)

    if options.output_filename is not None and (
        (isStandaloneMode() and not isOnefileMode()) or shallMakeModule()):
        Tracing.options_logger.sysexit("""\
Error, may only specify output filename for acceleration and onefile mode,
but not for module mode where filenames are mandatory, and not for
standalone where there is a sane default used inside the dist folder.""")

    if isLinux():
        if len(getIconPaths()) > 1:
            Tracing.options_logger.sysexit(
                "Error, can only use one icon file on Linux.")

    if isMacOS():
        if len(getIconPaths()) > 1:
            Tracing.options_logger.sysexit(
                "Error, can only use one icon file on macOS.")

    for icon_path in getIconPaths():
        if "#" in icon_path and isWin32Windows():
            icon_path, icon_index = icon_path.rsplit("#", 1)

            if not icon_index.isdigit() or int(icon_index) < 0:
                Tracing.options_logger.sysexit(
                    "Error, icon number in %r not valid." %
                    (icon_path + "#" + icon_index))

        if not os.path.exists(icon_path):
            Tracing.options_logger.sysexit(
                "Error, icon path %r does not exist." % icon_path)

        if getWindowsIconExecutablePath():
            Tracing.options_logger.sysexit(
                "Error, can only use icons from template executable or from icon files, but not both."
            )

    icon_exe_path = getWindowsIconExecutablePath()
    if icon_exe_path is not None and not os.path.exists(icon_exe_path):
        Tracing.options_logger.sysexit("Error, icon path %r does not exist." %
                                       icon_exe_path)

    try:
        file_version = getWindowsFileVersion()
    except Exception:  # Catch all the things, don't want any interface, pylint: disable=broad-except
        Tracing.options_logger.sysexit(
            "Error, file version must be a tuple of up to 4 integer values.")

    try:
        product_version = getWindowsProductVersion()
    except Exception:  # Catch all the things, don't want any interface, pylint: disable=broad-except
        Tracing.options_logger.sysexit(
            "Error, product version must be a tuple of up to 4 integer values."
        )

    if getWindowsCompanyName() == "":
        Tracing.options_logger.sysexit(
            """Error, empty string is not an acceptable company name.""")

    if getWindowsProductName() == "":
        Tracing.options_logger.sysexit(
            """Error, empty string is not an acceptable product name.""")

    splash_screen_filename = getWindowsSplashScreen()

    if splash_screen_filename is not None:
        if not os.path.isfile(splash_screen_filename):
            Tracing.options_logger.sysexit(
                "Error, specified splash screen image '%s' does not exist." %
                splash_screen_filename)

    if file_version or product_version or getWindowsVersionInfoStrings():
        if not (file_version or product_version) and getWindowsCompanyName():
            Tracing.options_logger.sysexit(
                "Error, company name and file or product version need to be given when any version information is given."
            )

    if isOnefileMode() and not hasOnefileSupportedOS():
        Tracing.options_logger.sysexit("Error, unsupported OS for onefile %r" %
                                       getOS())

    if options.follow_none and options.follow_all:
        Tracing.options_logger.sysexit(
            "Conflicting options '--follow-imports' and '--nofollow-imports' given."
        )

    for module_pattern in getShallIncludePackageData():
        if (module_pattern.startswith("-") or "/" in module_pattern
                or "\\" in module_pattern):
            Tracing.options_logger.sysexit(
                "Error, '--include-package-data' needs module name or pattern as an argument, not %r."
                % module_pattern)

    for module_pattern in getShallFollowModules():
        if (module_pattern.startswith("-") or "/" in module_pattern
                or "\\" in module_pattern):
            Tracing.options_logger.sysexit(
                "Error, '--follow-import-to' options needs module name or pattern as an argument, not %r."
                % module_pattern)
    for module_pattern in getShallFollowInNoCase():
        if (module_pattern.startswith("-") or "/" in module_pattern
                or "\\" in module_pattern):
            Tracing.options_logger.sysexit(
                "Error, '--nofollow-import-to' options needs module name or pattern as an argument, not %r."
                % module_pattern)

    for data_file in options.data_files:
        if "=" not in data_file:
            Tracing.options_logger.sysexit(
                "Error, malformed data file description, must specify relative target path separated with '='."
            )

        if data_file.count("=") == 1:
            src, dst = data_file.split("=", 1)

            filenames = resolveShellPatternToFilenames(src)

            if len(filenames) > 1 and not dst.endswith(("/", os.path.sep)):
                Tracing.options_logger.sysexit(
                    "Error, pattern '%s' matches more than one file, but target has no trailing slash, not a directory."
                    % src)
        else:
            src, dst, pattern = data_file.split("=", 2)

            filenames = resolveShellPatternToFilenames(
                os.path.join(src, pattern))

        if not filenames:
            Tracing.options_logger.sysexit(
                "Error, '%s' does not match any files." % src)

        if os.path.isabs(dst):
            Tracing.options_logger.sysexit(
                "Error, must specify relative target path for data file, not absolute path '%s'."
                % data_file)

    for data_dir in options.data_dirs:
        if "=" not in data_dir:
            Tracing.options_logger.sysexit(
                "Error, malformed data dir description, must specify relative target path with '=' separating it."
            )

        src, dst = data_dir.split("=", 1)

        if os.path.isabs(dst):
            Tracing.options_logger.sysexit(
                "Error, must specify relative target path for data dir, not %r as in %r."
                % (dst, data_dir))

        if not os.path.isdir(src):
            Tracing.options_logger.sysexit(
                "Error, must specify existing source data directory, not %r as in %r."
                % (dst, data_dir))

    for pattern in getShallFollowExtraFilePatterns():
        if os.path.isdir(pattern):
            Tracing.options_logger.sysexit(
                "Error, pattern %r given to '--include-plugin-files' cannot be a directory name."
                % pattern)

    if options.static_libpython == "yes" and getSystemStaticLibPythonPath(
    ) is None:
        Tracing.options_logger.sysexit(
            "Error, static libpython is not found or not supported for this Python installation."
        )

    if shallUseStaticLibPython() and getSystemStaticLibPythonPath() is None:
        Tracing.options_logger.sysexit(
            """Error, usable static libpython is not found for this Python installation. You \
might be missing required packages. Disable with --static-libpython=no" if you don't \
want to install it.""")

    if isApplePython():
        if isStandaloneMode():
            Tracing.options_logger.sysexit(
                "Error, for standalone mode, Apple Python from macOS is not supported, use e.g. CPython instead."
            )

        if str is bytes:
            Tracing.options_logger.sysexit(
                "Error, Apple Python 2.7 from macOS is not usable as per Apple decision, use e.g. CPython 2.7 instead."
            )

    if isStandaloneMode() and isLinux(
    ) and getExecutablePath("patchelf") is None:
        Tracing.options_logger.sysexit(
            "Error, standalone mode on Linux requires 'patchelf' to be installed. Use 'apt/dnf/yum install patchelf' first."
        )

    pgo_executable = getPgoExecutable()
    if pgo_executable and not isPathExecutable(pgo_executable):
        Tracing.options_logger.sysexit(
            "Error, path '%s' to binary to use for PGO is not executable." %
            pgo_executable)
Пример #11
0
    def __init__(self, upx_path, upx_nocache):
        self.upx_binary = getExecutablePath("upx", upx_path)
        self.upx_binary_hash = None
        self.upx_nocache = upx_nocache

        self.warning_given = False
Пример #12
0
def main():
    goHome()

    parser = OptionParser()

    parser.add_option(
        "--upload",
        action="store_true",
        dest="upload",
        default=False,
        help="""\
Upload to http://nuitka.net/apidoc requires access rights and is done by the
official servers automatically only. Without this, create the local html folder
only.

Default is %default.""",
    )

    options, _positional_args = parser.parse_args()

    shutil.rmtree("html", ignore_errors=True)

    doxygen_path = getExecutablePath("doxygen")

    # Extra ball on Windows, check default installation PATH too.
    if not doxygen_path and getOS() == "Windows":
        with withEnvironmentPathAdded("PATH", r"C:\Program Files\Doxygen\bin"):
            doxygen_path = getExecutablePath("doxygen")

    if not doxygen_path:
        sys.exit("Error, need to install Doxygen and add it to PATH for this to work.")

    try:
        import doxypypy  # @UnusedImport pylint: disable=I0021,unused-import,unused-variable
    except ImportError:
        sys.exit("Error, needs to install doxypypy into this Python.")

    with withTemporaryFile(suffix=".doxyfile", delete=False) as doxy_file:
        doxy_config = getFileContents("doc/Doxyfile.template")

        with withTemporaryFile(
            suffix=".bat" if getOS() == "Windows" else ".sh", delete=False
        ) as doxy_batch_file:
            if getOS() == "Windows":
                doxy_batch_file.write(
                    "%s -m doxypypy.doxypypy -a -c %%1" % sys.executable
                )
            else:
                doxy_batch_file.write(
                    "#!/bin/sh\nexec '%s' -m doxypypy.doxypypy -a -c $1"
                    % sys.executable
                )

        doxy_batch_filename = doxy_batch_file.name

        doxy_config = doxy_config.replace("%DOXYPYPY%", doxy_batch_filename)
        doxy_file.write(doxy_config)

        doxy_filename = doxy_file.name

    print("Running doxygen:")
    try:
        subprocess.check_call([doxygen_path, doxy_filename])
    finally:
        os.unlink(doxy_filename)
        os.unlink(doxy_batch_filename)

    # Update the repository on the web site.
    if options.upload:
        assert (
            os.system(
                "rsync -avz --delete html/ --chown www-data [email protected]:/var/www/apidoc/"
            )
            == 0
        )

    print("Finished.")
Пример #13
0
def main():
    goHome()

    if os.name == "nt":
        git_path = getExecutablePath("git")

        if git_path is None:
            git_path = r"C:\Program Files\Git\bin\sh.exe"

            if not os.path.exists(git_path):
                git_path = None

        if git_path is None:
            sys.exit(
                """\
Error, cannot locate 'git.exe' which we need to install git hooks. Add it to
PATH while executing this will be sufficient."""
            )

        sh_path = os.path.join(os.path.dirname(git_path), "sh.exe")

        if not os.path.exists(sh_path):
            sh_path = os.path.join(
                os.path.dirname(git_path), "..", "..", "bin", "sh.exe"
            )

        sh_path = os.path.normpath(sh_path)

        if not os.path.exists(sh_path):
            sys.exit(
                """\
Error, cannot locate 'sh.exe' near 'git.exe' which we need to install git hooks,
please improve this script."""
            )

        # For MinGW and #! we will need a path without spaces, so use this
        # code to find the short name, that won't have it.
        sh_path = getWindowsShortPathName(sh_path)

    for hook in os.listdir(".githooks"):
        full_path = os.path.join(".githooks", hook)

        hook_contents = getFileContents(full_path)

        if hook_contents.startswith("#!/bin/sh"):
            if os.name == "nt":
                # Correct shebang for Windows git to work.
                hook_contents = "#!%s\n%s" % (
                    sh_path.replace("\\", "/").replace(" ", r"\ "),
                    hook_contents[10:],
                )

                # Also use sys.executable to make sure we find autoformat.
                hook_contents = hook_contents.replace(
                    "./bin/autoformat-nuitka-source",
                    "'%s' ./bin/autoformat-nuitka-source" % sys.executable,
                )
        else:
            sys.exit("Error, unknown hook contents.")

        hook_target = os.path.join(".git/hooks/", hook)
        with open(hook_target, "wb") as out_file:
            out_file.write(hook_contents.encode("utf8"))

        st = os.stat(hook_target)
        os.chmod(hook_target, st.st_mode | stat.S_IEXEC)
Пример #14
0
import sys
import stat

# Unchanged, running from checkout, use the parent directory, the nuitka
# package ought be there.
sys.path.insert(
    0, os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))

from nuitka.tools.Basics import goHome  # isort:skip
from nuitka.utils.Execution import getExecutablePath  # isort:skip
from nuitka.utils.FileOperations import getFileContents  # isort:skip

goHome()

if os.name == "nt":
    git_path = getExecutablePath("git")

    if git_path is None:
        git_path = r"C:\Program Files\Git\bin\sh.exe"

        if not os.path.exists(git_path):
            git_path = None

    if git_path is None:
        sys.exit("""\
Error, cannot locate 'git.exe' which we need to install git hooks. Add it to
PATH while executing this will be sufficient.""")

    sh_path = os.path.join(os.path.dirname(git_path), "sh.exe")

    if not os.path.exists(sh_path):
Пример #15
0
    def execute_tests(where, use_python, flags):
        # Many cases, pylint: disable=too-many-branches,too-many-statements

        print(
            "Executing test case called %s with CPython %s and extra flags '%s'."
            % (where, use_python, flags)
        )

        intended_version = use_python[6:]
        if sys.version.startswith(intended_version):
            os.environ["PYTHON"] = sys.executable
        else:
            if os.name == "nt":
                os.environ["PYTHON"] = getPythonExePathWindows(
                    search=intended_version, arch=None
                )
            else:
                os.environ["PYTHON"] = getExecutablePath(use_python)

        if options.basic_tests:
            print(
                "Running the basic tests with options '%s' with %s:"
                % (flags, use_python)
            )
            setExtraFlags(where, "basics", flags)
            executeSubTest("./tests/basics/run_all.py search")

        if options.syntax_tests:
            print(
                "Running the syntax tests with options '%s' with %s:"
                % (flags, use_python)
            )
            setExtraFlags(where, "syntax", flags)
            executeSubTest("./tests/syntax/run_all.py search")

        if options.program_tests:
            print(
                "Running the program tests with options '%s' with %s:"
                % (flags, use_python)
            )
            setExtraFlags(where, "programs", flags)
            executeSubTest("./tests/programs/run_all.py search")

        if options.package_tests:
            print(
                "Running the package tests with options '%s' with %s:"
                % (flags, use_python)
            )
            setExtraFlags(where, "packages", flags)
            executeSubTest("./tests/packages/run_all.py search")

        # At least one Debian Jessie, these versions won't have lxml installed, so
        # don't run them there. Also these won't be very version dependent in their
        # results.
        if use_python != "python2.6":
            if options.optimization_tests:
                print(
                    "Running the optimizations tests with options '%s' with %s:"
                    % (flags, use_python)
                )
                setExtraFlags(where, "optimizations", flags)
                executeSubTest("./tests/optimizations/run_all.py search")

        if options.standalone_tests and not options.coverage:
            print(
                "Running the standalone tests with options '%s' with %s:"
                % (flags, use_python)
            )
            setExtraFlags(None, "standalone", flags)
            executeSubTest("./tests/standalone/run_all.py search")

        if options.reflection_test and not options.coverage:
            print(
                "Running the reflection test with options '%s' with %s:"
                % (flags, use_python)
            )
            setExtraFlags(None, "reflected", flags)
            executeSubTest("./tests/reflected/compile_itself.py search")

        if not use_python.startswith("python3"):
            if os.path.exists("./tests/CPython26/run_all.py"):
                if options.cpython26:
                    print(
                        "Running the CPython 2.6 tests with options '%s' with %s:"
                        % (flags, use_python)
                    )

                    setExtraFlags(where, "26tests", flags)
                    executeSubTest("./tests/CPython26/run_all.py search")
            else:
                print("The CPython2.6 tests are not present, not run.")

            # Running the Python 2.7 test suite with CPython 2.6 gives little
            # insight, because "importlib" will not be there and that's it.
            if use_python != "python2.6":
                if os.path.exists("./tests/CPython27/run_all.py"):
                    if options.cpython27:
                        print(
                            "Running the CPython 2.7 tests with options '%s' with %s:"
                            % (flags, use_python)
                        )
                        setExtraFlags(where, "27tests", flags)
                        executeSubTest("./tests/CPython27/run_all.py search")
                else:
                    print("The CPython2.7 tests are not present, not run.")

        if "--debug" not in flags:
            # Not running the Python 3.2 test suite with CPython2.6, as that's about
            # the same as CPython2.7 and won't have any new insights.
            if use_python not in ("python2.6", "python2.7") or not options.coverage:
                if os.path.exists("./tests/CPython32/run_all.py"):
                    if options.cpython32:
                        setExtraFlags(where, "32tests", flags)
                        executeSubTest("./tests/CPython32/run_all.py search")
                else:
                    print("The CPython3.2 tests are not present, not run.")

            # Running the Python 3.3 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython33/run_all.py"):
                    if options.cpython33:
                        setExtraFlags(where, "33tests", flags)
                        executeSubTest("./tests/CPython33/run_all.py search")
                else:
                    print("The CPython3.3 tests are not present, not run.")

            # Running the Python 3.4 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython34/run_all.py"):
                    if options.cpython34:
                        setExtraFlags(where, "34tests", flags)
                        executeSubTest("./tests/CPython34/run_all.py search")
                else:
                    print("The CPython3.4 tests are not present, not run.")

            # Running the Python 3.5 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython35/run_all.py"):
                    if options.cpython35:
                        setExtraFlags(where, "35tests", flags)
                        executeSubTest("./tests/CPython35/run_all.py search")
                else:
                    print("The CPython3.5 tests are not present, not run.")

            # Running the Python 3.6 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython36/run_all.py"):
                    if options.cpython36:
                        setExtraFlags(where, "36tests", flags)
                        executeSubTest("./tests/CPython36/run_all.py search")
                else:
                    print("The CPython3.6 tests are not present, not run.")

            # Running the Python 3.7 test suite only with CPython3.x.
            if not use_python.startswith("python2"):
                if os.path.exists("./tests/CPython36/run_all.py"):
                    if options.cpython36:
                        setExtraFlags(where, "37tests", flags)
                        executeSubTest("./tests/CPython37/run_all.py search")
                else:
                    print("The CPython3.7 tests are not present, not run.")

        if "NUITKA_EXTRA_OPTIONS" in os.environ:
            del os.environ["NUITKA_EXTRA_OPTIONS"]