Пример #1
0
def checkRequirements(filename):
    for line in readSourceCodeFromFilename(None, filename).splitlines():
        if line.startswith("# nuitka-skip-unless-"):
            if line[21:33] == "expression: ":
                expression = line[33:]
                with open(os.devnull, "w") as devnull:
                    result = subprocess.call(
                        (
                            os.environ["PYTHON"],
                            "-c",
                            "import sys, os; sys.exit(not bool(%s))" %
                            expression,
                        ),
                        stdout=devnull,
                        stderr=subprocess.STDOUT,
                    )
                if result != 0:
                    return (False,
                            "Expression '%s' evaluated to false" % expression)

            elif line[21:30] == "imports: ":
                imports_needed = line[30:].rstrip().split(",")
                for i in imports_needed:
                    if not hasModule(i):
                        return (
                            False,
                            i +
                            " not installed for this Python version, but test needs it",
                        )
    # default return value
    return (True, "")
Пример #2
0
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:
        with open(os.devnull, "w") as devnull:
            pylint_version = Execution.check_output(
                [os.environ["PYTHON"], "-m", "pylint", "--version"], stderr=devnull
            )

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

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

    if pylint_version < "1.6.5":
        sys.exit("Error, needs PyLint 1.6.5 or higher not %r." % pylint_version)

    my_print("Using PyLint version:", pylint_version)
Пример #3
0
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)
Пример #4
0
def checkVersion():
    # pylint: disable=global-statement
    global pylint_version

    if not hasModule("pylint"):
        sys.exit("Error, pylint is not installed for this interpreter version.")

    if pylint_version is None:
        with open(os.devnull, "w") as devnull:
            pylint_version = Execution.check_output(
                [os.environ["PYTHON"], "-m", "pylint", "--version"], stderr=devnull
            )

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

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

    if pylint_version < "1.6.5":
        sys.exit("Error, needs PyLint 1.6.5 or higher not %r." % pylint_version)

    my_print("Using PyLint version:", pylint_version)
Пример #5
0
def main():
    setup()
    goHome()

    # So PyLint finds nuitka package.
    addPYTHONPATH(os.getcwd())
    setupPATH()

    parser = OptionParser()

    parser.add_option(
        "--show-todos",
        "--todos",
        action="store_true",
        dest="todos",
        default=False,
        help="""\
Show TODO items. Default is %default.""",
    )

    parser.add_option(
        "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="""\
Be verbose in output. Default is %default.""",
    )

    parser.add_option(
        "--one-by-one",
        action="store_true",
        dest="one_by_one",
        default=False,
        help="""\
Check files one by one. Default is %default.""",
    )

    parser.add_option(
        "--not-installed-is-no-error",
        action="store_true",
        dest="not_installed_is_no_error",
        default=False,
        help="""\
Insist on PyLint to be installed. Default is %default.""",
    )

    options, positional_args = parser.parse_args()

    if options.not_installed_is_no_error and not hasModule("pylint"):
        print("PyLint is not installed for this interpreter version: SKIPPED")
        sys.exit(0)

    if not positional_args:
        positional_args = ["bin", "nuitka", "tests/*/run_all.py"]

    positional_args = sum(
        (resolveShellPatternToFilenames(positional_arg)
         for positional_arg in positional_args),
        [],
    )

    print("Working on:", positional_args)

    blacklist = ["oset.py", "odict.py"]

    # Avoid checking the Python2 runner with Python3, it has name collisions.
    if python_version >= 300:
        blacklist.append("nuitka")

    filenames = list(scanTargets(positional_args, (".py", ), blacklist))
    PyLint.executePyLint(
        filenames=filenames,
        show_todos=options.todos,
        verbose=options.verbose,
        one_by_one=options.one_by_one,
    )

    if not filenames:
        sys.exit("No files found.")

    sys.exit(PyLint.our_exit_code)
Пример #6
0
def main():
    setup(go_main=False)

    # So PyLint finds nuitka package.
    addPYTHONPATH(getHomePath())
    setupPATH()

    parser = OptionParser()

    parser.add_option(
        "--diff",
        action="store_true",
        dest="diff",
        default=False,
        help="""\
Analyse the changed files in git. Default is %default.""",
    )

    parser.add_option(
        "--show-todos",
        "--todos",
        action="store_true",
        dest="todos",
        default=False,
        help="""\
Show TODO items. Default is %default.""",
    )

    parser.add_option(
        "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="""\
Be verbose in output. Default is %default.""",
    )

    parser.add_option(
        "--one-by-one",
        action="store_true",
        dest="one_by_one",
        default=False,
        help="""\
Check files one by one. Default is %default.""",
    )

    parser.add_option(
        "--not-installed-is-no-error",
        action="store_true",
        dest="not_installed_is_no_error",
        default=False,
        help="""\
Insist on PyLint to be installed. Default is %default.""",
    )

    options, positional_args = parser.parse_args()

    if options.not_installed_is_no_error and not hasModule("pylint"):
        print("PyLint is not installed for this interpreter version: SKIPPED")
        sys.exit(0)

    if positional_args:
        if options.diff:
            sys.exit("Error, no filenames argument allowed in git diff mode.")
    else:
        goHome()

        if options.diff:
            positional_args = [
                filename for filename in getModifiedPaths()
                if isPythonFile(filename)
            ]
        else:
            positional_args = [
                "bin", "nuitka", "setup.py", "tests/*/run_all.py"
            ]

    positional_args = sum(
        (resolveShellPatternToFilenames(positional_arg)
         for positional_arg in positional_args),
        [],
    )

    if not positional_args:
        sys.exit("No files found.")

    print("Working on:", positional_args)

    ignore_list = []

    # Avoid checking the Python2 runner along with the one for Python3, it has name collisions.
    if python_version >= 0x300:
        ignore_list.append("nuitka")

    filenames = list(
        scanTargets(positional_args,
                    suffixes=(".py", ".scons"),
                    ignore_list=ignore_list))
    PyLint.executePyLint(
        filenames=filenames,
        show_todos=options.todos,
        verbose=options.verbose,
        one_by_one=options.one_by_one,
    )

    if not filenames:
        sys.exit("No files found.")

    sys.exit(PyLint.our_exit_code)
Пример #7
0
    active = search_mode.consider(dirname=None, filename=filename)

    if not active:
        my_print("Skipping", filename)
        continue

    extra_flags = ["expect_success", "standalone", "remove_output"]

    if filename == "PySideUsing.py":
        # Don't test on platforms not supported by current Debian testing, and
        # which should be considered irrelevant by now.
        if python_version.startswith("2.6") or python_version.startswith("3.2"):
            reportSkip("irrelevant Python version", ".", filename)
            continue

        if not hasModule("PySide.QtCore"):
            reportSkip(
                "PySide not installed for this Python version, but test needs it",
                ".",
                filename,
            )
            continue

        # For the warnings.
        extra_flags.append("ignore_stderr")

    if "PyQt4" in filename:
        # Don't test on platforms not supported by current Debian testing, and
        # which should be considered irrelevant by now.
        if python_version.startswith("2.6") or python_version.startswith("3.2"):
            reportSkip("irrelevant Python version", ".", filename)
Пример #8
0
# Find nuitka package relative to us.
sys.path.insert(
    0,
    os.path.normpath(
        os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..")))

from nuitka.tools.testing.Common import (  # isort:skip
    check_output, convertUsing2to3, createSearchMode,
    decideFilenameVersionSkip, hasModule, my_print, setup)

from nuitka.TreeXML import toString

python_version = setup()

# The Python version used by Nuitka needs "lxml" too.
if not hasModule("lxml.etree"):
    print("Warning, no 'lxml' module installed, cannot run XML based tests.")
    sys.exit(0)

search_mode = createSearchMode()


def getKind(node):
    result = node.attrib["kind"]

    result = result.replace("Statements", "")
    result = result.replace("Statement", "")
    result = result.replace("Expression", "")

    return result
Пример #9
0
    extra_flags = [
        "expect_success",
        "standalone",
        "remove_output"
    ]

    if filename == "PySideUsing.py":
        # Don't test on platforms not supported by current Debian testing, and
        # which should be considered irrelevant by now.
        if python_version.startswith("2.6") or \
           python_version.startswith("3.2"):
            reportSkip("irrelevant Python version", ".", filename)
            continue

        if not hasModule("PySide.QtCore"):
            reportSkip("PySide not installed for this Python version, but test needs it", ".", filename )
            continue

        # For the warnings.
        extra_flags.append("ignore_stderr")

    if "PyQt4" in filename:
        # Don't test on platforms not supported by current Debian testing, and
        # which should be considered irrelevant by now.
        if python_version.startswith("2.6") or \
           python_version.startswith("3.2"):
            reportSkip("irrelevant Python version", ".", filename)
            continue

        if not hasModule("PyQt4.QtGui"):
Пример #10
0
from nuitka.tools.testing.Common import (  # isort:skip
    check_output,
    convertUsing2to3,
    createSearchMode,
    decideFilenameVersionSkip,
    hasModule,
    my_print,
    setup
)

from nuitka.TreeXML import toString

python_version = setup()

# The Python version used by Nuitka needs "lxml" too.
if not hasModule("lxml.etree"):
    print("Warning, no 'lxml' module installed, cannot run XML based tests.")
    sys.exit(0)

search_mode = createSearchMode()


def getKind(node):
    result = node.attrib[ "kind" ]

    result = result.replace("Statements", "")
    result = result.replace("Statement", "")
    result = result.replace("Expression", "")

    return result
Пример #11
0
def main():
    setup()
    goHome()

    # So PyLint finds nuitka package.
    addPYTHONPATH(os.getcwd())
    setupPATH()

    parser = OptionParser()

    parser.add_option(
        "--show-todos",
        "--todos",
        action="store_true",
        dest="todos",
        default=False,
        help="""\
Show TODO items. Default is %default.""",
    )

    parser.add_option(
        "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="""\
Be version in output. Default is %default.""",
    )

    parser.add_option(
        "--one-by-one",
        action="store_true",
        dest="one_by_one",
        default=False,
        help="""\
Check files one by one. Default is %default.""",
    )

    parser.add_option(
        "--not-installed-is-no-error",
        action="store_true",
        dest="not_installed_is_no_error",
        default=False,
        help="""\
Insist on PyLint to be installed. Default is %default.""",
    )

    options, positional_args = parser.parse_args()

    if options.not_installed_is_no_error and not hasModule("pylint"):
        print("PyLint is not installed for this interpreter version: SKIPPED")
        sys.exit(0)

    if not positional_args:
        positional_args = ["bin", "nuitka"]

    print("Working on:", positional_args)

    blacklist = ["oset.py", "odict.py", "SyntaxHighlighting.py"]

    # Avoid checking the Python2 runner with Python3, it has name collisions.
    if python_version >= 300:
        blacklist.append("nuitka")

    filenames = list(scanTargets(positional_args, (".py",), blacklist))
    PyLint.executePyLint(
        filenames=filenames,
        show_todos=options.todos,
        verbose=options.verbose,
        one_by_one=options.one_by_one,
    )

    if not filenames:
        sys.exit("No files found.")

    sys.exit(PyLint.our_exit_code)