direct.dist.FreezeTool

from direct.dist.FreezeTool import CompilationEnvironment, Freezer, PandaModuleFinder, pytest_imports

This module contains code to freeze a number of Python modules into a single (mostly) standalone DLL or EXE.

Inheritance diagram

Inheritance diagram of direct.dist.FreezeTool

class CompilationEnvironment(platform)[source]

Bases: object

Create an instance of this class to record the commands to invoke the compiler on a given platform. If needed, the caller can create a custom instance of this class (or simply set the compile strings directly) to customize the build environment.

__init__(self, platform)[source]
compileDll(self, filename, basename, extraLink=[])[source]
compileExe(self, filename, basename, extraLink=[])[source]
determineStandardSetup(self)[source]
class Freezer(previous=None, debugLevel=0, platform=None, path=None, optimize=None)[source]

Bases: object

class ModuleDef(moduleName, filename=None, implicit=False, guess=False, exclude=False, forbid=False, allowChildren=False, fromSource=None, text=None)[source]

Bases: object

__init__(self, moduleName, filename=None, implicit=False, guess=False, exclude=False, forbid=False, allowChildren=False, fromSource=None, text=None)[source]
__init__(self, previous=None, debugLevel=0, platform=None, path=None, optimize=None)[source]
addModule(self, moduleName, implicit=False, newName=None, filename=None, guess=False, fromSource=None, text=None)[source]

Adds a module to the list of modules to be exported by this tool. If implicit is true, it is OK if the module does not actually exist.

newName is the name to call the module when it appears in the output. The default is the same name it had in the original. Use caution when renaming a module; if another module imports this module by its original name, you will also need to explicitly add the module under its original name, duplicating the module twice in the output.

The module name may end in “.*”, which means to add all of the .py files (other than __init__.py) in a particular directory. It may also end in “.*.*”, which means to cycle through all directories within a particular directory.

addToMultifile(self, multifile, compressionLevel=0)[source]

After a call to done(), this stores all of the accumulated python code into the indicated Multifile. Additional extension modules are listed in self.extras.

done(self, addStartupModules=False)[source]

Call this method after you have added all modules with addModule(). You may then call generateCode() or writeMultifile() to dump the resulting output. After a call to done(), you may not add any more modules until you call reset().

excludeFrom(self, freezer)[source]

Excludes all modules that have already been processed by the indicated FreezeTool. This is equivalent to passing the indicated FreezeTool object as previous to this object’s constructor, but it may be called at any point during processing.

excludeModule(self, moduleName, forbid=False, allowChildren=False, fromSource=None)[source]

Adds a module to the list of modules not to be exported by this tool. If forbid is true, the module is furthermore forbidden to be imported, even if it exists on disk. If allowChildren is true, the children of the indicated module may still be included.

generateCode(self, basename, compileToExe=False)[source]

After a call to done(), this freezes all of the accumulated python code into either an executable program (if compileToExe is true) or a dynamic library (if compileToExe is false). The basename is the name of the file to write, without the extension.

The return value is the newly-generated filename, including the filename extension. Additional extension modules are listed in self.extras.

generateRuntimeFromStub(self, target, stub_file, use_console, fields={}, log_append=False, log_filename_strftime=False)[source]
getAllModuleNames(self)[source]

Return a list of all module names that have been included or forbidden, either in this current pass or in a previous pass. Module names that have been excluded are not included in this list.

getModuleDefs(self)[source]

Return a list of all of the modules we will be explicitly or implicitly including. The return value is actually a list of tuples: (moduleName, moduleDef).

getModulePath(self, moduleName)[source]

Looks for the indicated directory module and returns the __path__ member: the list of directories in which its python files can be found. If the module is a .py file and not a directory, returns None.

getModuleStar(self, moduleName)[source]

Looks for the indicated directory module and returns the __all__ member: the list of symbols within the module.

handleCustomPath(self, moduleName)[source]

Indicates a module that may perform runtime manipulation of its __path__ variable, and which must therefore be actually imported at runtime in order to determine the true value of __path__.

makeForbiddenModuleListEntry(self, moduleName)[source]
makeModuleDef(self, mangledName, code)[source]
makeModuleListEntry(self, mangledName, code, moduleName, module)[source]
mangleName(self, moduleName)[source]
reset(self)[source]

After a previous call to done(), this resets the FreezeTool object for a new pass. More modules may be added and dumped to a new target. Previously-added modules are remembered and will not be dumped again.

writeCode(self, filename, initCode='')[source]

After a call to done(), this freezes all of the accumulated Python code into a C source file.

writeMultifile(self, mfname)[source]

After a call to done(), this stores all of the accumulated python code into a Multifile with the indicated filename, including the extension. Additional extension modules are listed in self.extras.

class PandaModuleFinder(*args, **kw)[source]

Bases: ModuleFinder

__init__(self, *args, **kw)[source]
Parameters
  • path – search path to look on, defaults to sys.path

  • suffixes – defaults to imp.get_suffixes()

  • excludes – a list of modules to exclude

  • debug – an integer indicating the level of verbosity

find_all_submodules(self, m)[source]
find_module(self, name, path=None, parent=None)[source]

Finds a module with the indicated name on the given search path (or self.path if None). Returns a tuple like (fp, path, stuff), where stuff is a tuple like (suffix, mode, type).

load_module(self, fqname, fp, pathname, file_info)[source]

Copied from ModuleFinder.load_module with fixes to handle sending bytes to compile() for PY_SOURCE types. Sending bytes to compile allows it to handle file encodings.

scan_code(self, co, m)[source]
pytest_imports()[source]