mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 00:06:44 -04:00
dist: Add ignoreImports mechanism, prevents every app including numpy
Apparently a host of thirdparty packages currently get included by default, such as importlib.metadata -> toml -> numpy, and this is getting rather out of hand. The ignoreImports mechanism provides a way for us to flag certain imports as being optional dependencies. Also added is various "builtins" imports in Python 2.7 (which are all under version checks and would otherwise lead to the PyPI "builtins" package being included, which would pull in "future", etc.)
This commit is contained in:
parent
ef6aa9d6ca
commit
a270a55ccd
40
direct/src/dist/FreezeTool.py
vendored
40
direct/src/dist/FreezeTool.py
vendored
@ -92,6 +92,41 @@ else:
|
||||
hiddenImports['matplotlib.backends._backend_tk'] = ['Tkinter']
|
||||
|
||||
|
||||
# These are modules that import other modules but shouldn't pick them up as
|
||||
# dependencies (usually because they are optional). This prevents picking up
|
||||
# unwanted dependencies.
|
||||
ignoreImports = {
|
||||
'direct.showbase.PythonUtil': ['pstats', 'profile'],
|
||||
|
||||
'toml.encoder': ['numpy'],
|
||||
}
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
# importlib.metadata is a "provisional" module introduced in Python 3.8 that
|
||||
# conditionally pulls in dependency-rich packages like "email" and "pep517"
|
||||
# (the latter of which is a thirdparty package!) But it's only imported in
|
||||
# one obscure corner, so we don't want to pull it in by default.
|
||||
ignoreImports['importlib._bootstrap_external'] = ['importlib.metadata']
|
||||
ignoreImports['importlib.metadata'] = ['pep517']
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
# Include everything that we know conditionally imports the "builtins"
|
||||
# module in Python 3 only, because otherwise it would cause the Python 2.7
|
||||
# package "builtins" to be included as a dependency.
|
||||
ignoreImports.update({
|
||||
'direct.p3d.AppRunner': ['builtins'],
|
||||
'direct.showbase.ContainerLeakDetector': ['builtins'],
|
||||
'direct.showbase.LeakDetectors': ['builtins'],
|
||||
'direct.showbase.MessengerLeakDetector': ['builtins'],
|
||||
'direct.showbase.ObjectReport': ['builtins'],
|
||||
'direct.showbase.ProfileSession': ['builtins'],
|
||||
'direct.showbase.PythonUtil': ['builtins'] + ignoreImports['direct.showbase.PythonUtil'],
|
||||
'direct.showbase.ShowBase': ['builtins'],
|
||||
'direct.showbase.ShowBaseGlobal': ['builtins'],
|
||||
'py._builtin': ['builtins'],
|
||||
})
|
||||
|
||||
|
||||
# These are overrides for specific modules.
|
||||
overrideModules = {
|
||||
# Used by the warnings module, among others, to get line numbers. Since
|
||||
@ -2409,6 +2444,11 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
|
||||
if name in self.badmodules:
|
||||
self._add_badmodule(name, caller)
|
||||
return
|
||||
|
||||
if level <= 0 and caller and caller.__name__ in ignoreImports:
|
||||
if name in ignoreImports[caller.__name__]:
|
||||
return
|
||||
|
||||
try:
|
||||
self.import_hook(name, caller, level=level)
|
||||
except ImportError as msg:
|
||||
|
Loading…
x
Reference in New Issue
Block a user