deploy-ng: Fix loading submodules for hidden imports

Fixes #242
This commit is contained in:
Mitchell Stokes 2018-02-12 22:19:41 -08:00
parent 8f919b7e40
commit 0c3c6c36bf
2 changed files with 67 additions and 58 deletions

View File

@ -71,11 +71,6 @@ hiddenImports = {
'pytest': pytest_imports(),
'pkg_resources': [
'pkg_resources.*.*',
# TODO why does the above not get these modules too?
'pkg_resources._vendor.packaging.*',
'pkg_resources._vendor.packaging.version',
'pkg_resources._vendor.packaging.specifiers',
'pkg_resources._vendor.packaging.requirements',
],
'xml.etree.cElementTree': ['xml.etree.ElementTree'],
'datetime': ['_strptime'],
@ -907,33 +902,17 @@ class Freezer:
return modules
def addModule(self, moduleName, implicit = False, newName = None,
def _gatherSubmodules(self, moduleName, implicit = False, newName = 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.
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.
"""
assert self.mf == None
if not newName:
newName = moduleName
if moduleName.endswith('.*'):
assert(moduleName.endswith('.*'))
assert(newName.endswith('.*'))
mdefs = {}
# Find the parent module, so we can get its directory.
parentName = moduleName[:-2]
newParentName = newName[:-2]
@ -963,7 +942,7 @@ class Freezer:
if modules == None:
# It's actually a regular module.
self.modules[newParentName] = self.ModuleDef(
mdef[newParentName] = self.ModuleDef(
parentName, implicit = implicit, guess = guess,
fromSource = fromSource, text = text)
@ -972,10 +951,40 @@ class Freezer:
for basename in modules:
moduleName = '%s.%s' % (parentName, basename)
newName = '%s.%s' % (newParentName, basename)
mdef = self.ModuleDef(
mdefs[newName] = self.ModuleDef(
moduleName, implicit = implicit, guess = True,
fromSource = fromSource)
self.modules[newName] = mdef
return mdefs
def addModule(self, moduleName, implicit = False, newName = 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.
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.
"""
assert self.mf == None
if not newName:
newName = moduleName
if moduleName.endswith('.*'):
self.modules.update(self._gatherSubmodules(
moduleName, implicit, newName, filename,
guess, fromSource, text))
else:
# A normal, explicit module name.
self.modules[newName] = self.ModuleDef(
@ -1069,6 +1078,15 @@ class Freezer:
for origName in list(self.mf.modules.keys()):
hidden = hiddenImports.get(origName, [])
for modname in hidden:
print(origName, modname)
if modname.endswith('.*'):
mdefs = self._gatherSubmodules(modname, implicit = True)
for mdef in mdefs.values():
try:
self.__loadModule(mdef)
except ImportError:
pass
else:
self.__loadModule(self.ModuleDef(modname, implicit = True))
# Now, any new modules we found get added to the export list.

View File

@ -12,15 +12,6 @@ setup(
'pandagl',
'p3openal_audio',
],
'include_modules': {
'*': [
'pkg_resources.*.*',
# TODO why does the above not get these modules too?
'pkg_resources._vendor.packaging.*',
'pkg_resources._vendor.packaging.version',
'pkg_resources._vendor.packaging.specifiers',
'pkg_resources._vendor.packaging.requirements',
] + pytest.freeze_includes(),
},
'platforms': [
'manylinux1_x86_64',