Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
plugins.
User plugins are enabled as a first step, because they themselves may
enable standard plugins.
Returns:
None
"""
# load user plugins first to allow any preparative action
importUserPlugins()
# now enable standard plugins
loadStandardPlugins()
# ensure plugin is known and not both, enabled and disabled
for plugin_name in Options.getPluginsEnabled() + Options.getPluginsDisabled():
if plugin_name not in plugin_name2plugin_classes:
sys.exit("Error, unknown plug-in '%s' referenced." % plugin_name)
if (
plugin_name in Options.getPluginsEnabled()
and plugin_name in Options.getPluginsDisabled()
):
sys.exit("Error, conflicting enable/disable of plug-in '%s'." % plugin_name)
for (
plugin_name,
(plugin_class, plugin_detector),
) in plugin_name2plugin_classes.items():
if plugin_name in Options.getPluginsEnabled():
active_plugin_list.append(plugin_class())
elif plugin_name not in Options.getPluginsDisabled():
writeSourceCode(
filename=os.path.join(source_dir, "__frozen.c"), source_code=frozen_code
)
if not isWin32Windows():
writeBinaryData(
filename=os.path.join(source_dir, "__constants.bin"),
binary_data=ConstantCodes.stream_data.getBytes(),
)
else:
source_dir = getSourceDirectoryPath(main_module)
if not os.path.isfile(os.path.join(source_dir, "__helpers.h")):
sys.exit("Error, no previous build directory exists.")
if Options.isShowProgress() or Options.isShowMemory():
info(
"Total memory usage before running scons: {memory}:".format(
memory=MemoryUsage.getHumanReadableProcessMemoryUsage()
)
)
if Options.isShowMemory():
InstanceCounters.printStats()
if Options.isDebug():
Reports.doMissingOptimizationReport()
if Options.shallNotDoExecCCompilerCall():
return True, {}
# Run the Scons to build things.
Applies constraint collection on all so far known modules until no more
optimization is possible. Every successful optimization to anything might
make others possible.
"""
from logging import debug
from nuitka import ModuleRegistry, Options, Utils
from nuitka.Tracing import printLine
from .ConstraintCollections import ConstraintCollectionModule
from .Tags import TagSet
_progress = Options.isShowProgress()
def _attemptRecursion(module):
new_modules = module.attemptRecursion()
for new_module in new_modules:
debug(
"{source_ref} : {tags} : {message}".format(
source_ref = new_module.getSourceReference().getAsString(),
tags = "new_code",
message = "Recursed to module package."
)
)
tag_set = None
if Options.isStandaloneMode():
options["standalone_mode"] = "true"
if (
not Options.isStandaloneMode()
and not Options.shallMakeModule()
and isUninstalledPython()
):
options["uninstalled_python"] = "true"
if ModuleRegistry.getUncompiledTechnicalModules():
options["frozen_modules"] = str(
len(ModuleRegistry.getUncompiledTechnicalModules())
)
if Options.isShowScons():
options["show_scons"] = "true"
if Options.isMingw64():
options["mingw_mode"] = "true"
if Options.getMsvcVersion():
msvc_version = Options.getMsvcVersion()
msvc_version = msvc_version.replace("exp", "Exp")
if "." not in msvc_version:
msvc_version += ".0"
options["msvc_version"] = msvc_version
if Utils.getOS() == "Windows":
options["noelf_mode"] = "true"
return None
assert statement_sequence.isStatementsSequence(), statement_sequence
if statement_sequence.isStatementsFrame():
guard_mode = statement_sequence.getGuardMode()
context.setFrameGuardMode( guard_mode )
statements = statement_sequence.getStatements()
codes = []
for statement in statements:
source_ref = statement.getSourceReference()
if Options.shallTraceExecution():
statement_repr = repr( statement )
if Utils.python_version >= 300:
statement_repr = statement_repr.encode( "utf8" )
codes.append(
Generator.getStatementTrace(
source_ref.getAsString(),
statement_repr
)
)
if statement.isStatementsSequence():
code = "\n".join(
generateStatementSequenceCode(
statement_sequence = statement,
context = context
module_filename, module_name, module_package, module_kind, extra_recursion=False
):
# Many branches, which make decisions immediately, by returning
# pylint: disable=too-many-branches,too-many-return-statements
if module_name == "__main__":
return False, "Main program is not recursed to again."
plugin_decision = Plugins.onModuleEncounter(
module_filename, module_name, module_package, module_kind
)
if plugin_decision:
return plugin_decision
if module_kind == "shlib":
if Options.isStandaloneMode():
return True, "Shared library for inclusion."
else:
return False, "Shared library cannot be inspected."
if module_package is None:
full_name = module_name
else:
full_name = module_package + "." + module_name
no_case, reason = matchesModuleNameToPatterns(
module_name=full_name, patterns=Options.getShallFollowInNoCase()
)
if no_case:
return (False, "Module %s instructed by user to not recurse to." % reason)
e.__class__.__name__,
)
return None, False
except Building.CodeTooComplexCode:
if module_filename not in Importing.warned_about:
Importing.warned_about.add(module_filename)
warning(
"""\
Cannot recurse to import module '%s' (%s) because code is too complex.""",
module_relpath,
module_filename,
)
if Options.isStandaloneMode():
module = makeUncompiledPythonModule(
module_name=module.getFullName(),
filename=module_filename,
bytecode=marshal.dumps(
compile(
source_code, module_filename, "exec", dont_inherit=True
)
),
is_package=module.isCompiledPythonPackage(),
user_provided=True,
technical=False,
)
ModuleRegistry.addUncompiledModule(module)
return None, False
def getConstantAccess(to_name, constant, emit, context):
# Many cases, because for each type, we may copy or optimize by creating
# empty. pylint: disable=too-many-branches,too-many-statements
if to_name.c_type == "nuitka_bool" and Options.isDebug():
info("Missing optimization for constant to C bool.")
if type(constant) is dict:
if constant:
for key, value in iterItems(constant):
# key cannot be mutable.
assert not isMutable(key)
if isMutable(value):
needs_deep = True
break
else:
needs_deep = False
if needs_deep:
code = "DEEP_COPY( %s )" % context.getConstantCode(constant)
else:
if statements_sequence is not None and \
not statements_sequence.getStatements():
function_body.setStatements( None )
statements_sequence = None
if statements_sequence is not None:
result = statements_sequence.computeStatementsSequence(
constraint_collection = self
)
if result is not statements_sequence:
function_body.setBody(result)
self.makeVariableTraceOptimizations(function_body)
if not Options.isExperimental() or self.removes_knowledge:
return
# self.dumpTrace()
# Cannot mess with locals yet.
if self.unclear_locals:
return
# Trace based optimization goes here:
for variable_trace in self.variable_traces.values():
variable = variable_trace.getVariable()
# print variable
if variable.isLocalVariable() and not isSharedLogically(variable):
if variable_trace.isAssignTrace():
sys.path = eval(os.environ["NUITKA_PYTHONPATH"])
del os.environ["NUITKA_PYTHONPATH"]
else:
# Remove path element added for being called via "__main__.py", this can
# only lead to trouble, having e.g. a "distutils" in sys.path that comes
# from "nuitka.distutils".
sys.path = [
path_element
for path_element in sys.path
if os.path.dirname(os.path.abspath(__file__)) != path_element
]
# For re-execution, we might not have done this.
from nuitka import Options # isort:skip
Options.parseArgs()
import logging # isort:skip
logging.basicConfig(format="Nuitka:%(levelname)s:%(message)s")
# We don't care, and these are triggered by run time calculations of "range" and
# others, while on python2.7 they are disabled by default.
warnings.simplefilter("ignore", DeprecationWarning)
# We will run with the Python configuration as specified by the user, if it does
# not match, we restart ourselves with matching configuration.
needs_reexec = False
current_version = "%d.%d" % (sys.version_info[0], sys.version_info[1])