diff --git a/direct/src/p3d/Packager.py b/direct/src/p3d/Packager.py index d0c009a206..40c30d8485 100644 --- a/direct/src/p3d/Packager.py +++ b/direct/src/p3d/Packager.py @@ -1841,7 +1841,10 @@ class Packager: self.notify.warning(message) return - self.freezer.addModule(moduleName, filename = file.filename) + if file.text: + self.freezer.addModule(moduleName, filename = file.filename, text = file.text) + else: + self.freezer.addModule(moduleName, filename = file.filename) def addEggFile(self, file): # Precompile egg files to bam's. diff --git a/direct/src/showutil/FreezeTool.py b/direct/src/showutil/FreezeTool.py index 28c622a9be..68a6eff60a 100644 --- a/direct/src/showutil/FreezeTool.py +++ b/direct/src/showutil/FreezeTool.py @@ -8,6 +8,7 @@ import marshal import imp import platform import types +from StringIO import StringIO from distutils.sysconfig import PREFIX, get_python_inc, get_python_version # Temporary (?) try..except to protect against unbuilt p3extend_frozen. @@ -499,7 +500,8 @@ class Freezer: def __init__(self, moduleName, filename = None, implicit = False, guess = False, exclude = False, forbid = False, - allowChildren = False, fromSource = None): + allowChildren = False, fromSource = None, + text = None): # The Python module name. self.moduleName = moduleName @@ -534,6 +536,9 @@ class Freezer: # record came from, supplied by the caller. self.fromSource = fromSource + # If this is set, it contains Python code of the module. + self.text = text + # Some sanity checks. if not self.exclude: self.allowChildren = True @@ -750,7 +755,8 @@ class Freezer: return modules def addModule(self, moduleName, implicit = False, newName = None, - filename = None, guess = False, fromSource = None): + filename = None, guess = False, fromSource = None, + text = None): """ 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. @@ -806,7 +812,7 @@ class Freezer: # It's actually a regular module. self.modules[newParentName] = self.ModuleDef( parentName, implicit = implicit, guess = guess, - fromSource = fromSource) + fromSource = fromSource, text = text) else: # Now get all the py files in the parent directory. @@ -821,7 +827,7 @@ class Freezer: # A normal, explicit module name. self.modules[newName] = self.ModuleDef( moduleName, filename = filename, implicit = implicit, - guess = guess, fromSource = fromSource) + guess = guess, fromSource = fromSource, text = text) def done(self, compileToExe = False): """ Call this method after you have added all modules with @@ -972,7 +978,11 @@ class Freezer: stuff = ("", "rb", imp.PY_COMPILED) self.mf.load_module(mdef.moduleName, fp, pathname, stuff) else: - fp = open(pathname, modulefinder.READ_MODE) + fp = open(pathname, 'U') + if mdef.text: + fp = StringIO(mdef.text) + else: + fp = open(pathname, modulefinder.READ_MODE) stuff = ("", "r", imp.PY_SOURCE) self.mf.load_module(mdef.moduleName, fp, pathname, stuff)