def getConstantsDefinitionCode(context): """ Create the code code "__constants.c" file. This needs to create code to make all global constants (used in more than one module) and create them. """ constant_inits, constant_checks = getConstantsInitCode(context=context) constant_declarations = getConstantsDeclCode(context=context) sys_executable = None sys_prefix = None sys_base_prefix = None sys_exec_prefix = None sys_base_exec_prefix = None if not Options.shallMakeModule(): sys_executable = context.getConstantCode(sys.executable) sys_prefix = context.getConstantCode(sys.prefix) sys_exec_prefix = context.getConstantCode(sys.exec_prefix) if python_version >= 300: sys_base_prefix = context.getConstantCode( sys.base_prefix # @UndefinedVariable ) sys_base_exec_prefix = context.getConstantCode( sys.base_exec_prefix # @UndefinedVariable ) major, minor, micro = getNuitkaVersion().split(".")[:3] if "rc" in micro: micro = micro[: micro.find("rc")] level = "candidate" else: level = "release" return template_constants_reading % { "constant_declarations": "\n".join(constant_declarations), "constant_inits": indented(constant_inits), "constant_checks": indented(constant_checks), "sys_executable": sys_executable, "sys_prefix": sys_prefix, "sys_base_prefix": sys_base_prefix, "sys_exec_prefix": sys_exec_prefix, "sys_base_exec_prefix": sys_base_exec_prefix, "nuitka_version_major": major, "nuitka_version_minor": minor, "nuitka_version_micro": micro, "nuitka_version_level": level, }
def checkBranchName(): branch_name = getBranchName() nuitka_version = getNuitkaVersion() assert branch_name in ( "master", "develop", "factory", "release/" + nuitka_version, "hotfix/" + nuitka_version, ), branch_name return branch_name
def getModuleCode(module_context, template_values): header = template_global_copyright % { "name": module_context.getName(), "version": getNuitkaVersion(), "year": getNuitkaVersionYear(), } decls, inits, checks = getConstantInitCodes(module_context) if module_context.needsModuleFilenameObject(): decls.append("static PyObject *module_filename_obj;") template_values["constant_decl_codes"] = indented(decls, 0) template_values["constant_init_codes"] = indented(inits, 1) template_values["constant_check_codes"] = indented(checks, 1) return header + template_module_body_template % template_values
def getModuleCode(module, function_decl_codes, function_body_codes, context): # For the module code, lots of arguments and attributes come together. # pylint: disable=too-many-locals # Temporary variable initializations # TODO: Move that to a place outside of functions. from .FunctionCodes import ( finalizeFunctionLocalVariables, setupFunctionLocalVariables, ) setupFunctionLocalVariables( context=context, parameters=None, closure_variables=(), user_variables=module.getOutlineLocalVariables(), temp_variables=module.getTempVariables(), ) module_codes = Emission.SourceCodeCollector() module = context.getOwner() module_body = module.getBody() generateStatementSequenceCode( statement_sequence=module_body, emit=module_codes, allow_none=True, context=context, ) for _identifier, code in sorted(iterItems(context.getHelperCodes())): function_body_codes.append(code) for _identifier, code in sorted(iterItems(context.getDeclarations())): function_decl_codes.append(code) function_body_codes = "\n\n".join(function_body_codes) function_decl_codes = "\n\n".join(function_decl_codes) _cleanup = finalizeFunctionLocalVariables(context) # TODO: Seems like a bug, classes could produce those. # assert not _cleanup, _cleanup local_var_inits = context.variable_storage.makeCFunctionLevelDeclarations() if module_body is not None and module_body.mayRaiseException( BaseException): module_exit = template_module_exception_exit else: module_exit = template_module_noexception_exit function_table_entries_decl = [] for func_impl_identifier in context.getFunctionCreationInfos(): function_table_entries_decl.append("%s," % func_impl_identifier) module_name = module.getFullName() is_package = module.isCompiledPythonPackage() is_top = module.isTopModule() module_identifier = module.getCodeName() template = template_global_copyright + template_module_body_template if is_top == 1 and Options.shallMakeModule(): template += template_module_external_entry_point module_code_objects_decl = getCodeObjectsDeclCode(context) module_code_objects_init = getCodeObjectsInitCode(context) return template % { "module_name": module_name, "version": getNuitkaVersion(), "year": getNuitkaVersionYear(), "is_main_module": 1 if module.isMainModule() else 0, "is_dunder_main": 1 if module_name == "__main__" and os.path.basename( module.getCompileTimeFilename()) == "__main__.py" else 0, "is_package": 1 if is_package else 0, "module_identifier": module_identifier, "module_functions_decl": function_decl_codes, "module_functions_code": function_body_codes, "module_function_table_entries": indented(function_table_entries_decl), "temps_decl": indented(local_var_inits), "module_code": indented(module_codes.codes), "module_exit": module_exit, "module_code_objects_decl": indented(module_code_objects_decl, 0), "module_code_objects_init": indented(module_code_objects_init, 1), "constants_count": context.getConstantsCount(), }
getSupportedPythonVersionStr, python_version_str) from nuitka.utils import Utils from nuitka.Version import getNuitkaVersion # Indicator if we were called as "nuitka-run" in which case we assume some # other defaults and work a bit different with parameters. is_nuitka_run = os.path.basename(sys.argv[0]).lower().startswith("nuitka-run")\ or '--run' in sys.argv if not is_nuitka_run: usage = "usage: %prog [--module] [--execute] [options] main_module.py" else: usage = "usage: %prog [options] main_module.py" parser = OptionParser(prog="nuitka", usage=usage, version=getNuitkaVersion()) # This option is obsolete, and module should be used. parser.add_option("--exe", action="store_true", dest="obsolete_executable", default=False, help=SUPPRESS_HELP) parser.add_option("--module", action="store_false", dest="executable", default=True, help="""\ Create an extension module executable instead of a program. Defaults to off.""" )
def main(): """Main program flow of Nuitka At this point, options will be parsed already, Nuitka will be executing in the desired version of Python with desired flags, and we just get to execute the task assigned. We might be asked to only re-compile generated C, dump only an XML representation of the internal node tree after optimization, etc. """ # Main has to fulfill many options, leading to many branches and statements # to deal with them. pylint: disable=too-many-branches,too-many-statements if not Options.shallDumpBuiltTreeXML(): general.info( "Starting Python compilation with Nuitka %r on Python %r commercial %r." % (getNuitkaVersion(), python_version_str, getCommercialVersion())) filename = Options.getPositionalArgs()[0] # Inform the importing layer about the main script directory, so it can use # it when attempting to follow imports. Importing.setMainScriptDirectory( main_dir=os.path.dirname(os.path.abspath(filename))) # Turn that source code into a node tree structure. try: main_module = _createNodeTree(filename=filename) except (SyntaxError, IndentationError) as e: handleSyntaxError(e) if Options.shallDumpBuiltTreeXML(): # XML output only. for module in ModuleRegistry.getDoneModules(): dumpTreeXML(module) else: # Make the actual compilation. result, options = compileTree() # Exit if compilation failed. if not result: sys.exit(1) if Options.shallNotDoExecCCompilerCall(): if Options.isShowMemory(): MemoryUsage.showMemoryTrace() sys.exit(0) executePostProcessing() if Options.shallMakeModule() and Options.shallCreatePyiFile(): pyi_filename = OutputDirectories.getResultBasepath() + ".pyi" putTextFileContents( filename=pyi_filename, contents="""\ # This file was generated by Nuitka and describes the types of the # created shared library. # At this time it lists only the imports made and can be used by the # tools that bundle libraries, including Nuitka itself. For instance # standalone mode usage of the created library will need it. # In the future, this will also contain type information for values # in the module, so IDEs will use this. Therefore please include it # when you make software releases of the extension module that it # describes. %(imports)s # This is not Python source even if it looks so. Make it clear for # now. This was decided by PEP 484 designers. __name__ = ... """ % { "imports": "\n".join("import %s" % module_name for module_name in getImportedNames()) }, ) if Options.isStandaloneMode(): binary_filename = options["result_exe"] setMainEntryPoint(binary_filename) dist_dir = OutputDirectories.getStandaloneDirectoryPath() for module in ModuleRegistry.getDoneModules(): addIncludedEntryPoints( Plugins.considerExtraDlls(dist_dir, module)) copyUsedDLLs( source_dir=OutputDirectories.getSourceDirectoryPath(), dist_dir=dist_dir, standalone_entry_points=getStandaloneEntryPoints(), ) copyDataFiles(dist_dir=dist_dir) Plugins.onStandaloneDistributionFinished(dist_dir) if Options.isOnefileMode(): packDistFolderToOnefile(dist_dir, binary_filename) if Options.isRemoveBuildDir(): general.info("Removing dist folder %r." % dist_dir) removeDirectory(path=dist_dir, ignore_errors=False) else: general.info( "Keeping dist folder %r for inspection, no need to use it." % dist_dir) # Remove the source directory (now build directory too) if asked to. source_dir = OutputDirectories.getSourceDirectoryPath() if Options.isRemoveBuildDir(): general.info("Removing build directory %r." % source_dir) removeDirectory(path=source_dir, ignore_errors=False) assert not os.path.exists(source_dir) else: general.info("Keeping build directory %r." % source_dir) final_filename = OutputDirectories.getResultFullpath( onefile=Options.isOnefileMode()) Plugins.onFinalResult(final_filename) general.info("Successfully created %r." % final_filename) # Execute the module immediately if option was given. if Options.shallExecuteImmediately(): general.info("Launching %r." % final_filename) if Options.shallMakeModule(): executeModule( tree=main_module, clean_path=Options.shallClearPythonPathEnvironment(), ) else: executeMain( binary_filename=final_filename, clean_path=Options.shallClearPythonPathEnvironment(), )
def main(): nuitka_version = getNuitkaVersion() branch_name = checkBranchName() shutil.rmtree("dist", ignore_errors=True) shutil.rmtree("build", ignore_errors=True) createReleaseDocumentation() assert os.system("python setup.py sdist --formats=gztar") == 0 # Upload stable releases to OpenSUSE Build Service: if ( branch_name.startswith("release") or branch_name.startswith("hotfix") or branch_name == "master" ): # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) os.makedirs("osc") # Stage the "osc" checkout from the ground up. assert ( os.system( """\ cd osc && \ osc init home:kayhayen Nuitka && osc repairwc && \ cp ../dist/Nuitka-*.tar.gz . && \ sed -e s/VERSION/%s/ ../rpm/nuitka.spec >./nuitka.spec && \ cp ../rpm/nuitka-rpmlintrc . && \ osc addremove && \ echo 'New release' >ci_message && \ osc ci --file ci_message """ % nuitka_version ) == 0 ) # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) elif branch_name == "develop": # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) os.makedirs("osc") # Stage the "osc" checkout from the ground up, but path the RPM spec to say # it is nuitks-unstable package. assert ( os.system( """\ cd osc && \ osc init home:kayhayen Nuitka-Unstable && \ osc repairwc && \ cp ../dist/Nuitka-*.tar.gz . && \ sed -e s/VERSION/%s/ ../rpm/nuitka.spec >./nuitka-unstable.spec && \ sed -i nuitka-unstable.spec -e 's/Name: *nuitka/Name: nuitka-unstable/' && \ cp ../rpm/nuitka-rpmlintrc . && \ osc addremove && echo 'New release' >ci_message && \ osc ci --file ci_message """ % nuitka_version ) == 0 ) # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) elif branch_name == "factory": # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) os.makedirs("osc") # Stage the "osc" checkout from the ground up, but path the RPM spec to say # it is nuitks-unstable package. assert ( os.system( """\ cd osc && \ osc init home:kayhayen Nuitka-experimental && \ osc repairwc && \ cp ../dist/Nuitka-*.tar.gz . && \ sed -e s/VERSION/%s/ ../rpm/nuitka.spec >./nuitka-experimental.spec && \ sed -i nuitka-experimental.spec -e 's/Name: *nuitka/Name: nuitka-experimental/' && \ cp ../rpm/nuitka-rpmlintrc . && \ osc addremove && \ echo 'New release' >ci_message && osc ci --file ci_message """ % nuitka_version ) == 0 ) # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) else: sys.exit("Skipping OSC for branch '%s'" % branch_name)
from nuitka.PythonVersions import (getSupportedPythonVersions, getSupportedPythonVersionStr, python_version_str) from nuitka.utils import Utils from nuitka.Version import getNuitkaVersion # Indicator if we were called as "nuitka-run" in which case we assume some # other defaults and work a bit different with parameters. is_nuitka_run = os.path.basename(sys.argv[0]).lower().startswith("nuitka-run") if not is_nuitka_run: usage = "usage: %prog [--module] [--execute] [options] main_module.py" else: usage = "usage: %prog [options] main_module.py" parser = OptionParser(usage=usage, version=getNuitkaVersion()) # This option is obsolete, and module should be used. parser.add_option("--exe", action="store_true", dest="obsolete_executable", default=False, help=SUPPRESS_HELP) parser.add_option("--module", action="store_false", dest="executable", default=True, help="""\ Create an extension module executable instead of a program. Defaults to off.""" )
def getConstantsDefinitionCode(): """Create the code code "__constants.c" and "__constants.h" files. This needs to create code to make all global constants (used in more than one module) and create them. """ constant_accessor = ConstantAccessor(data_filename="__constants.const", top_level_name="global_constants") lines = [] for constant_value in getConstantDefaultPopulation(): identifier = constant_accessor.getConstantCode(constant_value) assert "[" in identifier, (identifier, constant_value) lines.append("// %s" % repr(constant_value)) lines.append("#define const_%s %s" % (namifyConstant(constant_value), identifier)) sys_executable = None if not Options.shallMakeModule(): if Options.isStandaloneMode(): # The directory is added back at run time. sys_executable = constant_accessor.getConstantCode( os.path.basename(sys.executable)) else: sys_executable = constant_accessor.getConstantCode(sys.executable) sys_prefix = None sys_base_prefix = None sys_exec_prefix = None sys_base_exec_prefix = None # TODO: This part is needed for main program only, so do it there? if not Options.shallMakeModule() and not Options.isStandaloneMode(): sys_prefix = constant_accessor.getConstantCode(sys.prefix) sys_exec_prefix = constant_accessor.getConstantCode(sys.exec_prefix) if python_version >= 300: sys_base_prefix = constant_accessor.getConstantCode( sys.base_prefix) sys_base_exec_prefix = constant_accessor.getConstantCode( sys.base_exec_prefix) lines.insert( 0, "extern PyObject *global_constants[%d];" % constant_accessor.getConstantsCount(), ) header = template_header_guard % { "header_guard_name": "__NUITKA_GLOBAL_CONSTANTS_H__", "header_body": "\n".join(lines), } major, minor, micro = getNuitkaVersion().split(".")[:3] if "rc" in micro: micro = micro[:micro.find("rc")] level = "candidate" else: level = "release" body = template_constants_reading % { "global_constants_count": constant_accessor.getConstantsCount(), "sys_executable": sys_executable, "sys_prefix": sys_prefix, "sys_base_prefix": sys_base_prefix, "sys_exec_prefix": sys_exec_prefix, "sys_base_exec_prefix": sys_base_exec_prefix, "nuitka_version_major": major, "nuitka_version_minor": minor, "nuitka_version_micro": micro, "nuitka_version_level": level, } return header, body
def main(): """Main program flow of Nuitka At this point, options will be parsed already, Nuitka will be executing in the desired version of Python with desired flags, and we just get to execute the task assigned. We might be asked to only re-compile generated C, dump only an XML representation of the internal node tree after optimization, etc. """ # Main has to fulfill many options, leading to many branches and statements # to deal with them. pylint: disable=too-many-branches,too-many-statements # In case we are in a PGO run, we read its information first, so it becomes # available for later parts. pgo_filename = getPythonPgoInput() if pgo_filename is not None: readPGOInputFile(pgo_filename) if not Options.shallDumpBuiltTreeXML(): general.info( "Starting Python compilation with Nuitka %r on Python %r commercial %r." % (getNuitkaVersion(), python_version_str, getCommercialVersion()) ) filename = Options.getPositionalArgs()[0] # Inform the importing layer about the main script directory, so it can use # it when attempting to follow imports. Importing.setMainScriptDirectory( main_dir=os.path.dirname(os.path.abspath(filename)) ) addIncludedDataFilesFromFileOptions() # Turn that source code into a node tree structure. try: main_module = _createNodeTree(filename=filename) except (SyntaxError, IndentationError) as e: handleSyntaxError(e) addIncludedDataFilesFromPackageOptions() if Options.shallDumpBuiltTreeXML(): # XML output only. for module in ModuleRegistry.getDoneModules(): dumpTreeXML(module) else: # Make the actual compilation. result, options = compileTree() # Exit if compilation failed. if not result: sys.exit(1) # Relaunch in case of Python PGO input to be produced. if Options.shallCreatePgoInput(): # Will not return. pgo_filename = OutputDirectories.getPgoRunInputFilename() general.info( "Restarting compilation using collected information from '%s'." % pgo_filename ) reExecuteNuitka(pgo_filename=pgo_filename) if Options.shallNotDoExecCCompilerCall(): if Options.isShowMemory(): MemoryUsage.showMemoryTrace() sys.exit(0) executePostProcessing() copyDataFiles() if Options.isStandaloneMode(): binary_filename = options["result_exe"] setMainEntryPoint(binary_filename) dist_dir = OutputDirectories.getStandaloneDirectoryPath() for module in ModuleRegistry.getDoneModules(): addIncludedEntryPoints(Plugins.considerExtraDlls(dist_dir, module)) copyDllsUsed( source_dir=OutputDirectories.getSourceDirectoryPath(), dist_dir=dist_dir, standalone_entry_points=getStandaloneEntryPoints(), ) Plugins.onStandaloneDistributionFinished(dist_dir) if Options.isOnefileMode(): packDistFolderToOnefile(dist_dir, binary_filename) if Options.isRemoveBuildDir(): general.info("Removing dist folder %r." % dist_dir) removeDirectory(path=dist_dir, ignore_errors=False) else: general.info( "Keeping dist folder %r for inspection, no need to use it." % dist_dir ) # Remove the source directory (now build directory too) if asked to. source_dir = OutputDirectories.getSourceDirectoryPath() if Options.isRemoveBuildDir(): general.info("Removing build directory %r." % source_dir) removeDirectory(path=source_dir, ignore_errors=False) assert not os.path.exists(source_dir) else: general.info("Keeping build directory %r." % source_dir) final_filename = OutputDirectories.getResultFullpath( onefile=Options.isOnefileMode() ) if Options.isStandaloneMode() and isMacOS(): general.info( "Created binary that runs on macOS %s (%s) or higher." % (options["macos_min_version"], options["macos_target_arch"]) ) Plugins.onFinalResult(final_filename) general.info("Successfully created %r." % final_filename) report_filename = Options.getCompilationReportFilename() if report_filename: writeCompilationReport(report_filename) # Execute the module immediately if option was given. if Options.shallExecuteImmediately(): run_filename = OutputDirectories.getResultRunFilename( onefile=Options.isOnefileMode() ) general.info("Launching %r." % run_filename) if Options.shallMakeModule(): executeModule( tree=main_module, clean_path=Options.shallClearPythonPathEnvironment(), ) else: executeMain( binary_filename=run_filename, clean_path=Options.shallClearPythonPathEnvironment(), )
def main(): nuitka_version = getNuitkaVersion() branch_name = checkBranchName() shutil.rmtree("dist", ignore_errors=True) shutil.rmtree("build", ignore_errors=True) createReleaseDocumentation() assert os.system("python setup.py sdist --formats=gztar") == 0 # Upload stable releases to OpenSUSE Build Service: if branch_name.startswith("release") or \ branch_name.startswith("hotfix") or \ branch_name == "master": # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) os.makedirs("osc") # Stage the "osc" checkout from the ground up. assert os.system("""\ cd osc && \ osc init home:kayhayen Nuitka && osc repairwc && \ cp ../dist/Nuitka-*.tar.gz . && \ sed -e s/VERSION/%s/ ../rpm/nuitka.spec >./nuitka.spec && \ cp ../rpm/nuitka-rpmlintrc . && \ osc addremove && \ echo 'New release' >ci_message && \ osc ci --file ci_message """ % nuitka_version) == 0 # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) elif branch_name == "develop": # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) os.makedirs("osc") # Stage the "osc" checkout from the ground up, but path the RPM spec to say # it is nuitks-unstable package. assert os.system("""\ cd osc && \ osc init home:kayhayen Nuitka-Unstable && \ osc repairwc && \ cp ../dist/Nuitka-*.tar.gz . && \ sed -e s/VERSION/%s/ ../rpm/nuitka.spec >./nuitka-unstable.spec && \ sed -i nuitka-unstable.spec -e 's/Name: *nuitka/Name: nuitka-unstable/' && \ cp ../rpm/nuitka-rpmlintrc . && \ osc addremove && echo 'New release' >ci_message && \ osc ci --file ci_message """ % nuitka_version) == 0 # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) elif branch_name == "factory": # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) os.makedirs("osc") # Stage the "osc" checkout from the ground up, but path the RPM spec to say # it is nuitks-unstable package. assert os.system("""\ cd osc && \ osc init home:kayhayen Nuitka-experimental && \ osc repairwc && \ cp ../dist/Nuitka-*.tar.gz . && \ sed -e s/VERSION/%s/ ../rpm/nuitka.spec >./nuitka-experimental.spec && \ sed -i nuitka-experimental.spec -e 's/Name: *nuitka/Name: nuitka-experimental/' && \ cp ../rpm/nuitka-rpmlintrc . && \ osc addremove && \ echo 'New release' >ci_message && osc ci --file ci_message """ % nuitka_version) == 0 # Cleanup the osc directory. shutil.rmtree("osc", ignore_errors=True) else: sys.exit("Skipping OSC for branch '%s'" % branch_name)
def __init__(self): """ Read the JSON file and enable any standard plugins. """ if not getNuitkaVersion() >= "0.6.6": sys.exit("Need Nuitka v0.6.6+ for hinted compilation.") # start a timer self.timer = StopWatch() self.timer.start() self.implicit_imports = OrderedSet() # speed up repeated lookups self.ignored_modules = OrderedSet() # speed up repeated lookups options = Options.options fin_name = self.getPluginOptions()[0] # the JSON file name import_info = json.loads( getFileContents(fin_name)) # read it and extract the two lists self.import_calls = import_info["calls"] self.import_files = import_info["files"] self.msg_count = dict() # to limit keep messages self.msg_limit = 21 # suppress pytest / _pytest / unittest? self.accept_test = self.getPluginOptionBool("test", False) """ Check if we should enable any (optional) standard plugins. This code must be modified whenever more standard plugin become available. """ show_msg = False # only show info if one ore more detected # indicators for found packages tk = np = qt = sc = mp = pmw = torch = sklearn = False eventlet = tflow = gevent = mpl = trio = False msg = "'%s' is adding the following options:" % self.plugin_name # detect required standard plugins and request enabling them for m in self.import_calls: # scan thru called items if m in ("numpy", "numpy.*"): np = True show_msg = True if m in ("matplotlib", "matplotlib.*"): mpl = True show_msg = True elif m in ("tkinter", "Tkinter", "tkinter.*", "Tkinter.*"): tk = True show_msg = True elif m.startswith(("PyQt", "PySide")): qt = True show_msg = True elif m in ("scipy", "scipy.*"): sc = True show_msg = True elif m in ("multiprocessing", "multiprocessing.*") and getOS() == "Windows": mp = True show_msg = True elif m in ("Pmw", "Pmw.*"): pmw = True show_msg = True elif m == "torch": torch = True show_msg = True elif m in ("sklearn", "sklearn.*"): sklearn = True show_msg = True elif m in ("tensorflow", "tensorflow.*"): tflow = True show_msg = True elif m in ("gevent", "gevent.*"): gevent = True show_msg = True elif m in ("eventlet", "eventlet.*"): eventlet = True show_msg = True # elif m in ("trio", "trio.*"): # trio = True # show_msg = True if show_msg is True: info(msg) if np: o = ["numpy="] if mpl: o.append("matplotlib") if sc: o.append("scipy") if sklearn: o.append("sklearn") o = ",".join(o).replace("=,", "=") if o.endswith("="): o = o[:-1] options.plugins_enabled.append(o) # enable numpy info("--enable-plugin=" + o) if tk: options.plugins_enabled.append("tk-inter") # enable tk-inter info("--enable-plugin=tk-inter") if qt: # TODO more scrutiny for the qt options! options.plugins_enabled.append("qt-plugins=sensible") info("--enable-plugin=qt-plugins=sensible") if mp: options.plugins_enabled.append("multiprocessing") info("--enable-plugin=multiprocessing") if pmw: options.plugins_enabled.append("pmw-freezer") info("--enable-plugin=pmw-freezer") if torch: options.plugins_enabled.append("torch") info("--enable-plugin=torch") if tflow: options.plugins_enabled.append("tensorflow") info("--enable-plugin=tensorflow") if gevent: options.plugins_enabled.append("gevent") info("--enable-plugin=gevent") if eventlet: options.plugins_enabled.append("eventlet") info("--enable-plugin=eventlet") # if trio: # options.plugins_enabled.append("trio") # info("--enable-plugin=trio") recurse_count = 0 for f in self.import_files: # request recursion to called modules if self.accept_test is False and f.startswith( ("pytest", "_pytest", "unittest")): continue options.recurse_modules.append(f) recurse_count += 1 # no plugin detected, but recursing to modules? if show_msg is False and recurse_count > 0: info(msg) msg = "--recurse-to for %i imported modules." % recurse_count if len(self.import_files) > 0: info(msg) info("") self.ImplicitImports = None # the 'implicit-imports' plugin object return None
from nuitka.utils import Utils from nuitka.Version import getNuitkaVersion # Indicator if we were called as "nuitka-run" in which case we assume some # other defaults and work a bit different with parameters. is_nuitka_run = os.path.basename(sys.argv[0]).lower().endswith("-run") if not is_nuitka_run: usage = "usage: %prog [--module] [--run] [options] main_module.py" else: usage = "usage: %prog [options] main_module.py" parser = OptionParser( usage=usage, version='\n'.join( (getNuitkaVersion(), "Python: " + sys.version.split('\n')[0], "Executable: " + sys.executable, "OS: " + Utils.getOS(), "Arch: " + Utils.getArchitecture()))) parser.add_option("--module", action="store_false", dest="executable", default=True, help="""\ Create an extension module executable instead of a program. Defaults to off.""" ) parser.add_option( "--standalone", action="store_true", dest="is_standalone",
from nuitka.PythonVersions import getSupportedPythonVersions from nuitka.utils import Utils from nuitka.Version import getNuitkaVersion # Indicator if we were called as "nuitka-run" in which case we assume some # other defaults and work a bit different with parameters. is_nuitka_run = os.path.basename(sys.argv[0]).lower().endswith("-run") if not is_nuitka_run: usage = "usage: %prog [--module] [--run] [options] main_module.py" else: usage = "usage: %prog [options] main_module.py" parser = OptionParser(usage=usage, version='\n'.join( (getNuitkaVersion(), sys.version, sys.executable))) # This option is obsolete, and module should be used. parser.add_option("--exe", action="store_true", dest="obsolete_executable", default=False, help=SUPPRESS_HELP) parser.add_option("--module", action="store_false", dest="executable", default=True, help="""\ Create an extension module executable instead of a program. Defaults to off.""" )
This special version performs standalone compilations and serves as an invoker for the user plugin "hinted-mods.py". This plugin controls the inclusion of modules in the distribution folder. """ import sys import os import json import platform from nuitka.__main__ import main from nuitka.Version import getNuitkaVersion # Make it a tuple of ints, for element based comparison, ignoring rc # status, hoping that doesn't matter much, although it often will # have become incompatible already. nuitka_version = getNuitkaVersion().split(".") nuitka_version = tuple(int(v.split("rc")[0]) for v in nuitka_version) # TODO: Provide a comparison/check method in the nuitka.Version module, maybe for 0.6.10 if not nuitka_version >= (0, 6, 11): sys.exit("This needs Nuitka version 0.6.11 or higher, this is %s" % getNuitkaVersion()) python_version = sys.version.split()[0] this_dir = os.path.dirname(os.path.abspath(__file__)) hinted_mods_fn = os.path.join(this_dir, "hinted-mods.py") if not os.path.exists(hinted_mods_fn): sys.exit("no such file: " + hinted_mods_fn) my_opts = [
from nuitka.Version import getNuitkaVersion # Indicator if we were called as "nuitka-run" in which case we assume some # other defaults and work a bit different with parameters. is_nuitka_run = os.path.basename(sys.argv[0]).lower().endswith("-run") if not is_nuitka_run: usage = "usage: %prog [--module] [--run] [options] main_module.py" else: usage = "usage: %prog [options] main_module.py" parser = OptionParser( usage=usage, version="\n".join( ( getNuitkaVersion(), "Python: " + sys.version.split("\n")[0], "Executable: " + sys.executable, "OS: " + Utils.getOS(), "Arch: " + Utils.getArchitecture(), ) ), ) parser.add_option( "--module", action="store_false", dest="executable", default=True, help="""\ Create an extension module executable instead of a program. Defaults to off.""",
action = "store", dest = "ds_source", default = None, help = """\ When given, use this as the source for the Debian package instead. Default \ %default.""" ) options, positional_args = parser.parse_args() assert not positional_args, positional_args checkAtHome() from nuitka.Version import getNuitkaVersion nuitka_version = getNuitkaVersion() branch_name = checkBranchName() from nuitka.tools.release.Release import checkNuitkaChangelog if branch_name.startswith("release") or \ branch_name == "master" or \ branch_name.startswith("hotfix/"): if nuitka_version.count('.') == 2: assert checkChangeLog("New upstream release.") else: assert checkChangeLog("New upstream hotfix release.") assert checkNuitkaChangelog() == "final", checkNuitkaChangelog() else:
def main(): # Complex stuff, pylint: disable=too-many-branches,too-many-statements # Make sure error messages are in English. os.environ["LANG"] = "C" parser = OptionParser() parser.add_option( "--no-pbuilder-update", action="store_false", dest="update_pbuilder", default=True, help="""\ Update the pbuilder chroot before building. Default %default.""", ) options, positional_args = parser.parse_args() assert len(positional_args) == 1, positional_args codename = positional_args[0] nuitka_version = getNuitkaVersion() branch_name = checkBranchName() category = getBranchCategory(branch_name) if category == "stable": if nuitka_version.count(".") == 2: assert checkChangeLog("New upstream release.") else: assert checkChangeLog("New upstream hotfix release.") else: assert checkChangeLog("New upstream pre-release.") shutil.rmtree("dist", ignore_errors=True) shutil.rmtree("build", ignore_errors=True) createReleaseDocumentation() assert os.system("python setup.py sdist --formats=gztar") == 0 os.chdir("dist") # Clean the stage for the debian package. The name "deb_dist" is what "py2dsc" # uses for its output later on. shutil.rmtree("deb_dist", ignore_errors=True) # Provide a re-packed tar.gz for the Debian package as input. # Create it as a "+ds" file, removing: # - the benchmarks (too many sources, not useful to end users, potential license # issues) # - the inline copy of scons (not wanted for Debian) # Then run "py2dsc" on it. for filename in os.listdir("."): if filename.endswith(".tar.gz"): new_name = filename[:-7] + "+ds.tar.gz" cleanupTarfileForDebian(filename, new_name) assert os.system("py2dsc " + new_name) == 0 # Fixup for py2dsc not taking our custom suffix into account, so we need # to rename it ourselves. before_deb_name = filename[:-7].lower().replace("-", "_") after_deb_name = before_deb_name.replace("rc", "~rc") assert (os.system( "mv 'deb_dist/%s.orig.tar.gz' 'deb_dist/%s+ds.orig.tar.gz'" % (before_deb_name, after_deb_name)) == 0) assert os.system("rm -f deb_dist/*_source*") == 0 # Remove the now useless input, py2dsc has copied it, and we don't # publish it. os.unlink(new_name) break else: assert False os.chdir("deb_dist") # Assert that the unpacked directory is there. Otherwise fail badly. for entry in os.listdir("."): if (os.path.isdir(entry) and entry.startswith("nuitka") and not entry.endswith(".orig")): break else: assert False # We know the dir is not empty, pylint: disable=undefined-loop-variable # Import the "debian" directory from above. It's not in the original tar and # overrides or extends what py2dsc does. assert (os.system( "rsync -a --exclude pbuilder-hookdir ../../debian/ %s/debian/" % entry) == 0) # Remove now unnecessary files. assert os.system("rm *.dsc *.debian.tar.[gx]z") == 0 os.chdir(entry) # Build the debian package, but disable the running of tests, will be done later # in the pbuilder test steps. assert os.system("debuild --set-envvar=DEB_BUILD_OPTIONS=nocheck") == 0 os.chdir("../../..") assert os.path.exists("dist/deb_dist") # Check with pylint in pedantic mode and don't proceed if there were any # warnings given. Nuitka is lintian clean and shall remain that way. For # hotfix releases, i.e. "stable" builds, we skip this test though. if category == "stable": print("Skipped lintian checks for stable releases.") else: assert (os.system( "lintian --pedantic --fail-on-warnings --allow-root dist/deb_dist/*.changes" ) == 0) # Move the created debian package files out. os.system("cp dist/deb_dist/*.deb dist/") # Build inside the pbuilder chroot, and output to dedicated directory. shutil.rmtree("package", ignore_errors=True) os.makedirs("package") # Now update the pbuilder. if options.update_pbuilder: command = """\ sudo /usr/sbin/pbuilder --update --basetgz /var/cache/pbuilder/%s.tgz""" % ( codename) assert os.system(command) == 0, codename # Execute the package build in the pbuilder with tests. command = ("""\ sudo /usr/sbin/pbuilder --build --basetgz /var/cache/pbuilder/%s.tgz \ --hookdir debian/pbuilder-hookdir --debemail "Kay Hayen <*****@*****.**>" \ --buildresult package dist/deb_dist/*.dsc""" % codename) assert os.system(command) == 0, codename # Cleanup the build directory, not needed anymore. shutil.rmtree("build", ignore_errors=True) # Now build the repository. os.chdir("package") os.makedirs("repo") os.chdir("repo") os.makedirs("conf") with open("conf/distributions", "w") as output: output.write("""\ Origin: Nuitka Label: Nuitka Codename: %(codename)s Architectures: i386 amd64 armel armhf powerpc Components: main Description: Apt repository for project Nuitka %(codename)s SignWith: 2912B99C """ % {"codename": codename}) assert os.system("reprepro includedeb %s ../*.deb" % codename) == 0 print("Uploading...") # Create repo folder unless already done. This is needed for the first # build only. assert (os.system("ssh [email protected] mkdir -p /var/www/deb/%s/%s/" % (category, codename)) == 0) # Update the repository on the web site. assert (os.system( "rsync -avz --delete dists pool --chown www-data [email protected]:/var/www/deb/%s/%s/" % (category, codename)) == 0) print("Finished.")
'my_opts'. This can be used to create "canned" standard compilation profiles and to limit the command line length. This special version performs standalone compilations and serves as an invoker for the user plugin "hinted-mods.py". This plugin controls the inclusion of modules in the distribution folder. """ import json import os import platform import sys from nuitka.__main__ import main from nuitka.Version import getNuitkaVersion nuitka_vsn = getNuitkaVersion() if not nuitka_vsn >= "0.6.6": sys.exit("This needs Nuitka version 0.6.6 or higher.") python_vsn = sys.version.split()[0] this_dir = os.path.dirname(os.path.abspath(__file__)) hinted_mods_fn = os.path.join(this_dir, "hinted-mods.py") if not os.path.exists(hinted_mods_fn): sys.exit("no such file: " + hinted_mods_fn) my_opts = [ "--standalone", # the purpose of this script "--recurse-none", # exclude everything ] script = sys.argv[-1] # name of script to be compiled if not os.path.exists(script):
parser.add_option("--use-as-ds-source", action="store", dest="ds_source", default=None, help="""\ When given, use this as the source for the Debian package instead. Default \ %default.""") options, positional_args = parser.parse_args() assert not positional_args, positional_args checkAtHome() from nuitka.Version import getNuitkaVersion nuitka_version = getNuitkaVersion() branch_name = checkBranchName() from nuitka.tools.release.Release import checkNuitkaChangelog if branch_name.startswith("release") or \ branch_name == "master" or \ branch_name.startswith("hotfix/"): if nuitka_version.count('.') == 2: assert checkChangeLog("New upstream release.") else: assert checkChangeLog("New upstream hotfix release.") assert checkNuitkaChangelog() == "final", checkNuitkaChangelog() else:
def main(): # Complex stuff, pylint: disable=too-many-branches,too-many-statements # Make sure error messages are in English. os.environ["LANG"] = "C" parser = OptionParser() parser.add_option( "--no-pbuilder-update", action="store_false", dest="update_pbuilder", default=True, help="""\ Update the pbuilder chroot before building. Default %default.""", ) options, positional_args = parser.parse_args() assert len(positional_args) == 1, positional_args codename = positional_args[0] nuitka_version = getNuitkaVersion() branch_name = checkBranchName() category = getBranchCategory(branch_name) if category == "stable": if nuitka_version.count(".") == 2: assert checkChangeLog("New upstream release.") else: assert checkChangeLog("New upstream hotfix release.") else: assert checkChangeLog("New upstream pre-release.") shutil.rmtree("dist", ignore_errors=True) shutil.rmtree("build", ignore_errors=True) createReleaseDocumentation() assert os.system("python setup.py sdist --formats=gztar") == 0 os.chdir("dist") # Clean the stage for the debian package. The name "deb_dist" is what "py2dsc" # uses for its output later on. shutil.rmtree("deb_dist", ignore_errors=True) # Provide a re-packed tar.gz for the Debian package as input. # Create it as a "+ds" file, removing: # - the benchmarks (too many sources, not useful to end users, potential license # issues) # - the inline copy of scons (not wanted for Debian) # Then run "py2dsc" on it. for filename in os.listdir("."): if filename.endswith(".tar.gz"): new_name = filename[:-7] + "+ds.tar.gz" cleanupTarfileForDebian(filename, new_name) assert os.system("py2dsc " + new_name) == 0 # Fixup for py2dsc not taking our custom suffix into account, so we need # to rename it ourselves. before_deb_name = filename[:-7].lower().replace("-", "_") after_deb_name = before_deb_name.replace("rc", "~rc") assert ( os.system( "mv 'deb_dist/%s.orig.tar.gz' 'deb_dist/%s+ds.orig.tar.gz'" % (before_deb_name, after_deb_name) ) == 0 ) assert os.system("rm -f deb_dist/*_source*") == 0 # Remove the now useless input, py2dsc has copied it, and we don't # publish it. os.unlink(new_name) break else: assert False os.chdir("deb_dist") # Assert that the unpacked directory is there. Otherwise fail badly. for entry in os.listdir("."): if ( os.path.isdir(entry) and entry.startswith("nuitka") and not entry.endswith(".orig") ): break else: assert False # We know the dir is not empty, pylint: disable=undefined-loop-variable # Import the "debian" directory from above. It's not in the original tar and # overrides or extends what py2dsc does. assert ( os.system( "rsync -a --exclude pbuilder-hookdir ../../debian/ %s/debian/" % entry ) == 0 ) # Remove now unnecessary files. assert os.system("rm *.dsc *.debian.tar.[gx]z") == 0 os.chdir(entry) # Build the debian package, but disable the running of tests, will be done later # in the pbuilder test steps. assert os.system("debuild --set-envvar=DEB_BUILD_OPTIONS=nocheck") == 0 os.chdir("../../..") assert os.path.exists("dist/deb_dist") # Check with pylint in pedantic mode and don't proceed if there were any # warnings given. Nuitka is lintian clean and shall remain that way. For # hotfix releases, i.e. "stable" builds, we skip this test though. if category == "stable": print("Skipped lintian checks for stable releases.") else: assert ( os.system( "lintian --pedantic --fail-on-warnings --allow-root dist/deb_dist/*.changes" ) == 0 ) # Move the created debian package files out. os.system("cp dist/deb_dist/*.deb dist/") # Build inside the pbuilder chroot, and output to dedicated directory. shutil.rmtree("package", ignore_errors=True) os.makedirs("package") # Now update the pbuilder. if options.update_pbuilder: command = """\ sudo /usr/sbin/pbuilder --update --basetgz /var/cache/pbuilder/%s.tgz""" % ( codename ) assert os.system(command) == 0, codename # Execute the package build in the pbuilder with tests. command = ( """\ sudo /usr/sbin/pbuilder --build --basetgz /var/cache/pbuilder/%s.tgz \ --hookdir debian/pbuilder-hookdir --debemail "Kay Hayen <*****@*****.**>" \ --buildresult package dist/deb_dist/*.dsc""" % codename ) assert os.system(command) == 0, codename # Cleanup the build directory, not needed anymore. shutil.rmtree("build", ignore_errors=True) # Now build the repository. os.chdir("package") os.makedirs("repo") os.chdir("repo") os.makedirs("conf") with open("conf/distributions", "w") as output: output.write( """\ Origin: Nuitka Label: Nuitka Codename: %(codename)s Architectures: i386 amd64 armel armhf powerpc Components: main Description: Apt repository for project Nuitka %(codename)s SignWith: 2912B99C """ % {"codename": codename} ) assert os.system("reprepro includedeb %s ../*.deb" % codename) == 0 print("Uploading...") # Create repo folder unless already done. This is needed for the first # build only. assert ( os.system( "ssh [email protected] mkdir -p /var/www/deb/%s/%s/" % (category, codename) ) == 0 ) # Update the repository on the web site. assert ( os.system( "rsync -avz --delete dists pool --chown www-data [email protected]:/var/www/deb/%s/%s/" % (category, codename) ) == 0 ) print("Finished.")
def main(): # Complex stuff, pylint: disable=too-many-statements # Make sure error messages are in English. os.environ["LANG"] = "C" parser = OptionParser() parser.add_option( "--no-pbuilder-update", action="store_false", dest="update_pbuilder", default=True, help="""\ Update the pbuilder chroot before building. Default %default.""", ) options, positional_args = parser.parse_args() assert len(positional_args) == 1, positional_args codename = positional_args[0] nuitka_version = getNuitkaVersion() branch_name = checkBranchName() category = getBranchCategory(branch_name) if category == "stable": if nuitka_version.count(".") == 1: assert checkChangeLog("New upstream release.") else: assert checkChangeLog("New upstream hotfix release.") else: assert checkChangeLog("New upstream pre-release.") shutil.rmtree("dist", ignore_errors=True) shutil.rmtree("build", ignore_errors=True) createReleaseDocumentation() assert os.system("python setup.py sdist --formats=gztar") == 0 os.chdir("dist") # Clean the stage for the debian package. The name "deb_dist" is what "py2dsc" # uses for its output later on. shutil.rmtree("deb_dist", ignore_errors=True) # Provide a re-packed tar.gz for the Debian package as input. # Create it as a "+ds" file, removing: # - the benchmarks (too many sources, not useful to end users, potential license # issues) # - the inline copy of scons (not wanted for Debian) for filename in os.listdir("."): if filename.endswith(".tar.gz"): new_name = filename[:-7] + "+ds.tar.gz" cleanupTarfileForDebian(filename, new_name) entry = runPy2dsc(filename, new_name) break else: assert False os.chdir("deb_dist") os.chdir(entry) # Build the debian package, but disable the running of tests, will be done later # in the pbuilder test steps. assert os.system("debuild --set-envvar=DEB_BUILD_OPTIONS=nocheck") == 0 os.chdir("../../..") assert os.path.exists("dist/deb_dist") # Check with pylint in pedantic mode and don't proceed if there were any # warnings given. Nuitka is lintian clean and shall remain that way. For # hotfix releases, i.e. "stable" builds, we skip this test though. if category == "stable": my_print("Skipped lintian checks for stable releases.", style="blue") else: assert os.system( "lintian --pedantic --allow-root dist/deb_dist/*.changes") == 0 # Move the created debian package files out. os.system("cp dist/deb_dist/*.deb dist/") # Build inside the pbuilder chroot, and output to dedicated directory. shutil.rmtree("package", ignore_errors=True) os.makedirs("package") # Now update the pbuilder. if options.update_pbuilder: command = """\ sudo /usr/sbin/pbuilder --update --basetgz /var/cache/pbuilder/%s.tgz""" % ( codename) assert os.system(command) == 0, codename (dsc_filename, ) = resolveShellPatternToFilenames("dist/deb_dist/*.dsc") # Execute the package build in the pbuilder with tests. command = ( "sudo", "/usr/sbin/pbuilder", "--build", "--basetgz", "/var/cache/pbuilder/%s.tgz" % codename, "--hookdir", "debian/pbuilder-hookdir", "--debemail", "Kay Hayen <*****@*****.**>", "--buildresult", "package", dsc_filename, ) check_call(command, shell=False) # Cleanup the build directory, not needed anymore. shutil.rmtree("build", ignore_errors=True) # Now build the repository. my_print("Building repository ...", style="blue") os.chdir("package") os.makedirs("repo") os.chdir("repo") os.makedirs("conf") putTextFileContents( "conf/distributions", contents="""\ Origin: Nuitka Label: Nuitka Codename: %(codename)s Architectures: i386 amd64 armel armhf powerpc Components: main Description: Apt repository for project Nuitka %(codename)s SignWith: D96ADCA1377F1CEB6B5103F11BFC33752912B99C """ % {"codename": codename}, ) command = ["reprepro", "includedeb", codename] command.extend(resolveShellPatternToFilenames("../*.deb")) check_call(command, shell=False) my_print("Uploading ...", style="blue") # Create repo folder unless already done. This is needed for the first # build only. assert (os.system("ssh [email protected] mkdir -p /var/www/deb/%s/%s/" % (category, codename)) == 0) # Update the repository on the web site. assert (os.system( "rsync -avz --delete dists pool --chown www-data [email protected]:/var/www/deb/%s/%s/" % (category, codename)) == 0) my_print("Finished.", style="blue")
def __init__(self, hinted_json_file): """ Read the JSON file and enable any standard plugins. Notes: Read the JSON file produced during the get-hints step. It will contain a list of imported items ("calls") and a list of modules / packages ("files") to be loaded and recursed into. Depending on the items in 'files', we will trigger loading standard plugins. """ if not getNuitkaVersion() >= "0.6.6": sys.exit("Need Nuitka v0.6.6+ for hinted compilation.") # start a timer self.timer = StopWatch() self.timer.start() self.implicit_imports = OrderedSet() # speed up repeated lookups self.ignored_modules = OrderedSet() # speed up repeated lookups options = Options.options # Load json file contents from --hinted-json-file= argument filename = hinted_json_file try: # read it and extract the two lists import_info = json.loads(getFileContents(filename)) except (ValueError, FileNotFoundError): raise FileNotFoundError('Cannot load json file %s' % filename) self.import_calls = import_info["calls"] self.import_files = import_info["files"] self.msg_count = dict() # to limit keep messages self.msg_limit = 21 # suppress pytest / _pytest / unittest? # TODO: disabled because self.getPluginOptionBool does not exist anymore #self.accept_test = self.getPluginOptionBool("test", False) self.accept_test = False """ Check if we should enable any (optional) standard plugins. This code must be modified whenever more standard plugin become available. """ show_msg = False # only show info if one ore more detected # indicators for found packages tk = np = qt = sc = mp = pmw = torch = sklearn = False eventlet = tflow = gevent = mpl = trio = dill = False msg = "'%s' is adding the following options:" % os.path.basename( self.plugin_name) # we need matplotlib-specific cleanup to happen first: # if no mpl backend is used, reference to matplotlib is removed alltogether if "matplotlib.backends" not in self.import_files: temp = [ f for f in self.import_calls if not f.startswith(("matplotlib", "mpl_toolkits")) ] self.import_calls = temp temp = [ f for f in self.import_files if not f.startswith(("matplotlib", "mpl_toolkits")) ] self.import_files = temp # detect required standard plugins and request enabling them for m in self.import_calls: # scan thru called items if m in ("numpy", "numpy.*"): np = True show_msg = True if m in ("matplotlib", "matplotlib.*"): mpl = True show_msg = True elif m in ("tkinter", "Tkinter", "tkinter.*", "Tkinter.*"): tk = True show_msg = True elif m.startswith(("PyQt", "PySide")): qt = True show_msg = True elif m in ("scipy", "scipy.*"): sc = True show_msg = True elif m in ("multiprocessing", "multiprocessing.*") and getOS() == "Windows": mp = True show_msg = True elif m in ("Pmw", "Pmw.*"): pmw = True show_msg = True elif m == "torch": torch = True show_msg = True elif m in ("sklearn", "sklearn.*"): sklearn = True show_msg = True elif m in ("tensorflow", "tensorflow.*"): tflow = True show_msg = True elif m in ("gevent", "gevent.*"): gevent = True show_msg = True elif m in ("eventlet", "eventlet.*"): eventlet = True show_msg = True elif m in ("dill", "dill.*"): dill = True show_msg = True # elif m in ("trio", "trio.*"): # trio = True # show_msg = True if show_msg is True: info(msg) if np: o = ["numpy="] if mpl: o.append("matplotlib") if sc: o.append("scipy") if sklearn: o.append("sklearn") o = ",".join(o).replace("=,", "=") if o.endswith("="): o = o[:-1] options.plugins_enabled.append(o) # enable numpy info("--enable-plugin=" + o) if tk: options.plugins_enabled.append("tk-inter") # enable tk-inter info("--enable-plugin=tk-inter") if qt: # TODO more scrutiny for the qt options! options.plugins_enabled.append("qt-plugins=sensible") info("--enable-plugin=qt-plugins=sensible") if mp: options.plugins_enabled.append("multiprocessing") info("--enable-plugin=multiprocessing") if pmw: options.plugins_enabled.append("pmw-freezer") info("--enable-plugin=pmw-freezer") if torch: options.plugins_enabled.append("torch") info("--enable-plugin=torch") if tflow: options.plugins_enabled.append("tensorflow") info("--enable-plugin=tensorflow") if gevent: options.plugins_enabled.append("gevent") info("--enable-plugin=gevent") if eventlet: options.plugins_enabled.append("eventlet") info("--enable-plugin=eventlet") if dill: options.plugins_enabled.append("dill-compat") info("--enable-plugin=dill-compat") # if trio: # options.plugins_enabled.append("trio") # info("--enable-plugin=trio") recurse_count = 0 for f in self.import_files: # request recursion to called modules if self.accept_test is False and f.startswith( ("pytest", "_pytest", "unittest")): continue options.recurse_modules.append(f) recurse_count += 1 # no plugin detected, but recursing to modules? if show_msg is False and recurse_count > 0: info(msg) if len(self.import_files) > 0: msg = "--recurse-to=%s and %i more modules" % ( self.import_files[-1], recurse_count - 1, ) info(msg) info("") self.ImplicitImports = None # the 'implicit-imports' plugin object
from nuitka.utils import Utils from nuitka.Version import getNuitkaVersion # Indicator if we were called as "nuitka-run" in which case we assume some # other defaults and work a bit different with parameters. is_nuitka_run = os.path.basename(sys.argv[0]).lower().endswith("-run") if not is_nuitka_run: usage = "usage: %prog [--module] [--run] [options] main_module.py" else: usage = "usage: %prog [options] main_module.py" parser = OptionParser( usage=usage, version="\n".join(( getNuitkaVersion(), "Python: " + sys.version.split("\n")[0], "Executable: " + sys.executable, "OS: " + Utils.getOS(), "Arch: " + Utils.getArchitecture(), )), ) parser.add_option( "--module", action="store_false", dest="executable", default=True, help="""\ Create an extension module executable instead of a program. Defaults to off.""", )
This special version performs standalone compilations and serves as an invoker for the user plugin "hinted-mods.py". This plugin controls the inclusion of modules in the distribution folder. """ import sys import os import json import platform from nuitka.__main__ import main from nuitka.Version import getNuitkaVersion # Make it a tuple of ints, for element based comparison, ignoring rc # status, hoping that doesn't matter much, although it often will # have become incompatible already. nuitka_version = getNuitkaVersion().split(".") nuitka_version = tuple(int(v.split("rc")[0]) for v in nuitka_version) # TODO: Provide a comparison/check method in the nuitka.Version module, maybe for 0.6.10 if not nuitka_version >= (0,6,9): sys.exit("This needs Nuitka version 0.6.9 or higher, this is %s" % getNuitkaVersion()) python_version = sys.version.split()[0] this_dir = os.path.dirname(os.path.abspath(__file__)) hinted_mods_fn = os.path.join(this_dir, "hinted-mods.py") if not os.path.exists(hinted_mods_fn): sys.exit("no such file: " + hinted_mods_fn) my_opts = [ "--standalone", # the purpose of this script