示例#1
0
文件: PyLint.py 项目: psydox/Nuitka
def checkVersion():
    # pylint: disable=global-statement
    global pylint_version

    if not hasModule("pylint"):
        sys.exit(
            "Error, pylint is not installed for this interpreter %r version." %
            os.environ["PYTHON"])

    if pylint_version is None:
        pylint_version = check_output(
            [os.environ["PYTHON"], "-m", "pylint", "--version"],
            stderr=getNullOutput())

        if str is not bytes:
            pylint_version = pylint_version.decode("utf8")

        pylint_version = pylint_version.split("\n")[0].split()[-1].strip(",")

    my_print("Using PyLint version:", pylint_version)
示例#2
0
文件: __main__.py 项目: psydox/Nuitka
    def _executeSubTest(command, hide_output):
        if options.coverage and "search" in command:
            command = command.replace("search", "coverage")

        parts = command.split()
        parts[0] = parts[0].replace("/", os.path.sep)

        # The running Python will be good enough, on some platforms there is no
        # "python", and we need to pass this alone then.
        parts.insert(0, sys.executable)

        my_print("Run '%s' in '%s'." % (" ".join(parts), os.getcwd()))

        if hide_output:
            result = subprocess.call(parts, stdout=getNullOutput())
        else:
            result = subprocess.call(parts)

        if result != 0:
            sys.exit(result)
示例#3
0
def _cleanupImportSortOrder(filename):
    _cleanupImportRelative(filename)

    isort_call = _getPythonBinaryCall("isort")

    contents = getFileContents(filename, encoding="utf8")

    start_index = None
    if "\n# isort:start" in contents:
        parts = contents.splitlines()

        start_index = parts.index("# isort:start")
        contents = "\n".join(parts[start_index + 1:]) + "\n"

        putTextFileContents(filename, contents=contents)

    check_call(
        isort_call + [
            "-q",  # quiet, but stdout is still garbage
            "--overwrite-in-place",  # avoid using another temp file, this is already on one.
            "-ot",  # Order imports by type in addition to alphabetically
            "-m3",  # "vert-hanging"
            "-tc",  # Trailing commas
            "-p",  # make sure nuitka is first party package in import sorting.
            "nuitka",
            "-o",
            "SCons",
            filename,
        ],
        stdout=getNullOutput(),
    )

    if start_index is not None:
        contents = getFileContents(filename)

        contents = "\n".join(parts[:start_index + 1]) + "\n" + contents

        putTextFileContents(filename, contents=contents)
示例#4
0
    def _compressFile(self, filename, use_cache):
        upx_options = ["-q", "--no-progress"]

        if use_cache:
            if self.upx_binary_hash is None:
                self.upx_binary_hash = getFileContentsHash(self.upx_binary,
                                                           as_string=False)

            upx_hash = Hash()
            upx_hash.updateFromBytes(self.upx_binary_hash)
            upx_hash.updateFromValues(*upx_options)
            upx_hash.updateFromFile(filename)

            # TODO: Repeating pattern
            upx_cache_dir = os.path.join(getCacheDir(), "upx")
            makePath(upx_cache_dir)

            upx_cache_filename = os.path.join(upx_cache_dir,
                                              upx_hash.asHexDigest() + ".bin")

            if os.path.exists(upx_cache_filename):
                copyFile(upx_cache_filename, filename)
                return

        if use_cache:
            self.info("Uncached file, compressing '%s' may take a while." %
                      os.path.basename(filename))
        else:
            self.info("Compressing '%s'." % filename)

        check_call(
            [self.upx_binary] + upx_options + [filename],
            stdout=getNullOutput(),
            shell=False,
        )

        if use_cache:
            copyFile(filename, upx_cache_filename)
def packDistFolderToOnefileLinux(onefile_output_filename, dist_dir,
                                 binary_filename):
    """Pack to onefile binary on Linux.

    Notes: This is mostly a wrapper around AppImage, which does all the heavy
    lifting.
    """

    # This might be possible to avoid being done with --runtime-file.
    apprun_filename = os.path.join(dist_dir, "AppRun")
    with open(apprun_filename, "w") as output_file:
        output_file.write("""\
#!/bin/sh
exec $APPDIR/%s $@""" % os.path.basename(binary_filename))

    addFileExecutablePermission(apprun_filename)

    binary_basename = os.path.basename(getResultBasepath())

    icon_paths = getIconPaths()

    assert icon_paths
    extension = os.path.splitext(icon_paths[0])[1].lower()

    shutil.copyfile(icon_paths[0], getResultBasepath() + extension)

    with open(getResultBasepath() + ".desktop", "w") as output_file:
        output_file.write(
            """\
[Desktop Entry]
Name=%(binary_basename)s
Exec=%(binary_filename)s
Icon=%(binary_basename)s
Type=Application
Categories=Utility;""" % {
                "binary_basename": binary_basename,
                "binary_filename": os.path.basename(binary_filename),
            })

    postprocessing_logger.info(
        "Creating single file from dist folder, this may take a while.")

    # Starting the process while locked, so file handles are not duplicated.
    appimagetool_process = subprocess.Popen(
        (
            getAppImageToolPath(),
            dist_dir,
            "--comp",
            "xz",
            "-n",
            onefile_output_filename,
        ),
        shell=False,
        stderr=getNullOutput(),
        stdout=getNullOutput(),
    )

    # TODO: Exit code should be checked.
    result = appimagetool_process.wait()

    if not os.path.exists(onefile_output_filename):
        postprocessing_logger.sysexit(
            "Error, expected output file %s not created by AppImage." %
            onefile_output_filename)

    postprocessing_logger.info("Completed onefile creation.")

    assert result == 0, result