mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
freezer: add mechanism for overriding modules with custom code
This commit is contained in:
parent
f34d4c4851
commit
ef69e8935f
@ -84,6 +84,10 @@ else:
|
|||||||
hiddenImports['matplotlib.backends._backend_tk'] = ['Tkinter']
|
hiddenImports['matplotlib.backends._backend_tk'] = ['Tkinter']
|
||||||
|
|
||||||
|
|
||||||
|
# These are overrides for specific modules.
|
||||||
|
overrideModules = {
|
||||||
|
}
|
||||||
|
|
||||||
# These are missing modules that we've reported already this session.
|
# These are missing modules that we've reported already this session.
|
||||||
reportedMissing = {}
|
reportedMissing = {}
|
||||||
|
|
||||||
@ -2245,9 +2249,16 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
|
|||||||
m = self.load_package(fqname, pathname)
|
m = self.load_package(fqname, pathname)
|
||||||
self.msgout(2, "load_module ->", m)
|
self.msgout(2, "load_module ->", m)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
if type == imp.PY_SOURCE:
|
if type == imp.PY_SOURCE:
|
||||||
newline = b'\n' if 'b' in mode else '\n'
|
if fqname in overrideModules:
|
||||||
co = compile(fp.read()+newline, pathname, 'exec')
|
# This module has a custom override.
|
||||||
|
code = overrideModules[fqname]
|
||||||
|
else:
|
||||||
|
code = fp.read()
|
||||||
|
|
||||||
|
code += b'\n' if isinstance(code, bytes) else '\n'
|
||||||
|
co = compile(code, pathname, 'exec')
|
||||||
elif type == imp.PY_COMPILED:
|
elif type == imp.PY_COMPILED:
|
||||||
try:
|
try:
|
||||||
marshal_data = importlib._bootstrap_external._validate_bytecode_header(fp.read())
|
marshal_data = importlib._bootstrap_external._validate_bytecode_header(fp.read())
|
||||||
@ -2257,6 +2268,7 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
|
|||||||
co = marshal.loads(marshal_data)
|
co = marshal.loads(marshal_data)
|
||||||
else:
|
else:
|
||||||
co = None
|
co = None
|
||||||
|
|
||||||
m = self.add_module(fqname)
|
m = self.add_module(fqname)
|
||||||
m.__file__ = pathname
|
m.__file__ = pathname
|
||||||
if co:
|
if co:
|
||||||
@ -2283,6 +2295,10 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
|
|||||||
if fullname in self.excludes:
|
if fullname in self.excludes:
|
||||||
raise ImportError(name)
|
raise ImportError(name)
|
||||||
|
|
||||||
|
# If we have a custom override for this module, we know we have it.
|
||||||
|
if fullname in overrideModules:
|
||||||
|
return (None, '', ('.py', 'r', imp.PY_SOURCE))
|
||||||
|
|
||||||
# If no search path is given, look for a built-in module.
|
# If no search path is given, look for a built-in module.
|
||||||
if path is None:
|
if path is None:
|
||||||
if name in sys.builtin_module_names:
|
if name in sys.builtin_module_names:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user