示例#1
0
def action(stage_dir, root, path):
    command = [
        sys.executable,
        os.path.join("..", "..", "bin", "nuitka"),
        "--stand",
        "--run",
        "--output-dir",
        stage_dir,
        "--remove-output",
        "--plugin-enable=pylint-warnings",
    ]

    filename = os.path.join(stage_dir, "importer.py")

    assert path.startswith(root)

    module_name = path[len(root) + 1:]
    module_name = module_name.split(".")[0]
    module_name = module_name.replace(os.path.sep, ".")

    with open(filename, "w") as output:
        output.write("import " + module_name + "\n")
        output.write("print('OK')")

    command += os.environ.get("NUITKA_EXTRA_OPTIONS", "").split()

    command.append(filename)

    if checkSucceedsWithCPython(filename):
        try:
            output = check_output(command).splitlines()
        except Exception:  # only trying to check for no exception, pylint: disable=try-except-raise
            raise
        else:
            assert os.path.exists(filename[:-3] + ".dist")

            loaded_filenames = getRuntimeTraceOfLoadedFiles(
                logger=test_logger,
                path=os.path.join(filename[:-3] + ".dist", "importer.exe"),
            )

            outside_accesses = checkRuntimeLoadedFilesForOutsideAccesses(
                loaded_filenames,
                [
                    filename[:-3] + ".dist", current_dir,
                    os.path.expanduser("~/.config")
                ],
            )

            if output[-1] != b"OK":
                sys.exit("FAIL")

            my_print("OK")

            assert not outside_accesses, outside_accesses

            shutil.rmtree(filename[:-3] + ".dist")
    else:
        my_print("SKIP (does not work with CPython)")
def action(stage_dir, root, path):
    command = [
        sys.executable,
        os.path.join(
            "..",
            "..",
            "bin",
            "nuitka"
        ),
        "--stand",
        "--run",
        "--output-dir",
        stage_dir,
        "--remove-output",
        "--plugin-enable=pylint-warnings"
    ]

    filename = os.path.join(stage_dir, "importer.py")

    assert path.startswith(root)

    module_name = path[len(root)+1:]
    module_name = module_name.split(".")[0]
    module_name = module_name.replace(os.path.sep, ".")

    with open(filename, "w") as output:
        output.write("import " + module_name + "\n")
        output.write("print('OK')")

    command += os.environ.get("NUITKA_EXTRA_OPTIONS", "").split()

    command.append(filename)

    if checkSucceedsWithCPython(filename):
        try:
            output = check_output(command).splitlines()
        except Exception:
            raise
        else:
            assert os.path.exists(filename[:-3] + ".dist")

            loaded_filenames = getRuntimeTraceOfLoadedFiles(
                path = os.path.join(
                    filename[:-3] + ".dist",
                     "importer.exe"
                )
            )

            outside_accesses = checkRuntimeLoadedFilesForOutsideAccesses(
                loaded_filenames,
                [
                    filename[:-3] + ".dist",
                    current_dir,
                    os.path.expanduser("~/.config")
                ]
            )

            if output[-1] != b"OK":
                sys.exit("FAIL")

            my_print("OK")

            assert not outside_accesses, outside_accesses

            shutil.rmtree(filename[:-3] + ".dist")
    else:
        my_print("SKIP (does not work with CPython)")