Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
command = [
os.environ["PYTHON"],
nuitka_main_path,
path,
"--output-dir=%s" % tmp_dir,
"--python-flag=-S",
"--follow-imports",
]
result = subprocess.call(command)
if result != 0:
sys.exit(result)
shutil.rmtree(build_path)
my_print("OK.")
for package in PACKAGE_LIST:
package = package.replace("/", os.path.sep)
source_dir = os.path.join(base_dir, package)
for path, filename in listDir(source_dir):
if not filename.endswith(".py"):
continue
if filename.startswith(".#"):
continue
path = os.path.join(source_dir, filename)
if filename != "__init__.py":
my_print("Compiling '%s'." % path)
target = filename.replace(".py", ".build")
target_dir = os.path.join(tmp_dir, target)
removeDirectory(path=target_dir, ignore_errors=False)
command = [
nuitka,
"--module",
"--plugin-enable=pylint-warnings",
"--output-dir=%s" % tmp_dir,
"--no-pyi-file",
path,
]
command += os.environ.get("NUITKA_EXTRA_OPTIONS", "").split()
os.system("find | sort")
# Inform about the extra path, format is NUITKA_PACKAGE_fullname where
# dots become "_" and should point to the directory where external code
# to be loaded will live under. Probably should be an absolute path, but
# we avoid it here.
os.environ["NUITKA_PACKAGE_package"] = "./package.ext/package"
# Lets make sure these to not work. These will be used in the compiled
# form only.
for module_path in ("__init__.py", "sub_package1__init__.py"):
with open(os.path.join("./package.ext/package", module_path), "w") as output:
output.write("assert False")
# Check the compiled package is functional for importing.
my_print("Running package as basic test:")
command = [os.environ["PYTHON"], "-c", "import package"]
result = subprocess.call(command)
if result != 0:
sys.exit(result)
my_print("Running nose tests:")
# assert os.system(os.environ["PYTHON"] + " -m nose --first-package-wins -s package.sub_package1.tests") == 0
my_print("Running py.test tests:")
command = [
os.environ["PYTHON"],
"-m",
"pytest",
"-v",
# Lets make sure these to not work. These will be used in the compiled
# form only.
for module_path in ("__init__.py", "sub_package1__init__.py"):
with open(os.path.join("./package.ext/package", module_path), "w") as output:
output.write("assert False")
# Check the compiled package is functional for importing.
my_print("Running package as basic test:")
command = [os.environ["PYTHON"], "-c", "import package"]
result = subprocess.call(command)
if result != 0:
sys.exit(result)
my_print("Running nose tests:")
# assert os.system(os.environ["PYTHON"] + " -m nose --first-package-wins -s package.sub_package1.tests") == 0
my_print("Running py.test tests:")
command = [
os.environ["PYTHON"],
"-m",
"pytest",
"-v",
"--pyargs",
"package.sub_package1.tests",
]
result = subprocess.call(command)
if result != 0:
sys.exit(result)
target_dir = os.path.join(tmp_dir, target)
removeDirectory(path=target_dir, ignore_errors=False)
command = [
nuitka,
"--module",
"--plugin-enable=pylint-warnings",
"--output-dir=%s" % tmp_dir,
"--no-pyi-file",
path,
]
command += os.environ.get("NUITKA_EXTRA_OPTIONS", "").split()
my_print("Command: ", " ".join(command))
result = subprocess.call(command)
if result != 0:
sys.exit(result)
has_diff = diffRecursive(os.path.join(package, target), target_dir)
# TODO: Temporary, until we have something better than marshal which behaves
# differently in compiled Nuitka:
if has_diff and filename not in (
"Contexts.py",
"Whitelisting.py",
"ImplicitImports.py",
):
sys.exit("There were differences!")
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
else:
assert os.path.exists(runner_binary + ".exe")
process = subprocess.Popen(
args=[runner_binary + ".exe"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout_nuitka, stderr_nuitka = process.communicate()
exit_nuitka = process.returncode
my_print("STDOUT Nuitka:")
my_print(stdout_nuitka)
my_print("STDERR Nuitka:")
my_print(stderr_nuitka)
assert exit_nuitka == 0, exit_nuitka
my_print("EXIT was OK.")
exit_code_stdout = compareOutput(
"stdout",
stdout_cpython,
stdout_nuitka,
ignore_warnings=True,
ignore_infos=True,
syntax_errors=True,
)
command.append(path)
try:
subprocess.check_call(command)
except subprocess.CalledProcessError:
if os.path.basename(path) in nosyntax_errors:
my_print("Syntax error is known unreliable with file file.")
else:
my_print("Falling back to full comparison due to error exit.")
checkCompilesNotWithCPython(
dirname=None, filename=path, search_mode=search_mode
)
else:
my_print("OK")
if os.name == "nt":
suffix = "pyd"
else:
suffix = "so"
target_filename = os.path.basename(path).replace(".py", "." + suffix)
target_filename = target_filename.replace("(", "").replace(")", "")
os.unlink(os.path.join(stage_dir, target_filename))
try:
checkSequence(filename, module_statements)
for function in root.xpath('role[@name="functions"]/node'):
function_body, = function.xpath('role[@name="body"]')
function_statements_sequence = function_body[0]
assert len(function_statements_sequence) == 1
function_statements = next(iter(function_statements_sequence))
checkSequence(filename, function_statements)
if changed:
os.unlink(filename)
except SystemExit:
my_print("FAIL.")
raise
my_print("OK.")
if search_mode.abortIfExecuted():
break
else:
my_print("Skipping", filename)
search_mode.finish()
my_print(
package_name,
"-",
end=" ",
style="red" if (stdout_diff or stderr_diff) else "green",
)
my_print(
"stdout:", stdout_diff, end=" ", style="red" if stdout_diff else "green"
)
my_print(
"stderr:", stderr_diff, end="", style="red" if stderr_diff else "green"
)
my_print(
"\n---------------------------------------------------------------------------------"
)
my_print("TOTAL NUMBER OF PACKAGES TESTED: %s" % len(results), style="yellow")
num_failed = 0
num_errors = 0
# tally the number of errors and failed
for _, y, z in results:
if type(y) is str:
# this means the package ran into an exception
num_errors += 1
elif y or z:
num_failed += 1
return False
filenames = [
filename
for filename in
filenames
if not hasPyLintBugTrigger(filename)
]
extra_options = os.environ.get("PYLINT_EXTRA_OPTIONS", "").split()
if "" in extra_options:
extra_options.remove("")
if one_by_one:
for filename in filenames:
my_print("Checking", filename, ':')
_executePylint([filename], pylint_options, extra_options)
else:
_executePylint(filenames, pylint_options, extra_options)