def _analyze_base_modules(self): """ Analyze dependencies of the the modules in base_library.zip. """ logger.info('Analyzing base_library.zip ...') required_mods = [] # Collect submodules from required modules in base_library.zip. for m in PY3_BASE_MODULES: if is_package(m): required_mods += collect_submodules(m) else: required_mods.append(m) # Initialize ModuleGraph. self._base_modules = [ mod for req in required_mods for mod in self.import_hook(req) ]
def collect_submodules_traitsui(package, filter=lambda name: True): # Accept only strings as packages. if not isinstance(package, string_types): raise ValueError logger.debug('Collecting submodules for %s' % package) # Skip a module which is not a package. if not is_package(package): logger.debug('collect_submodules - Module %s is not a package.' % package) return [] # Determine the filesystem path to the specified package. pkg_base, pkg_dir = get_package_paths(package) # Walk the package. Since this performs imports, do it in a separate # process. names = exec_statement(""" import sys import pkgutil def ignore_err(name, err): # Can't print anything because printing is captured as module names # print ("error importing %s: %s" % (name, err)) pass # ``pkgutil.walk_packages`` doesn't walk subpackages of zipped files # per https://bugs.python.org/issue14209. This is a workaround. def walk_packages(path=None, prefix='', onerror=ignore_err): def seen(p, m={{}}): if p in m: return True m[p] = True for importer, name, ispkg in pkgutil.iter_modules(path, prefix): if not name.startswith(prefix): ## Added name = prefix + name ## Added yield importer, name, ispkg if ispkg: try: __import__(name) except ImportError, e: if onerror is not None: onerror(name, e) except Exception, e: if onerror is not None: onerror(name, e) else: raise else: path = getattr(sys.modules[name], '__path__', None) or [] # don't traverse path items we've seen before path = [p for p in path if not seen(p)] ## Use Py2 code here. It still works in Py3. for item in walk_packages(path, name+'.', onerror): yield item ## This is the original Py3 code. #yield from walk_packages(path, name+'.', onerror) for module_loader, name, ispkg in walk_packages([{}], '{}.'): print(name) """.format( # Use repr to escape Windows backslashes. repr(pkg_dir), package)) # Include the package itself in the results. mods = {package} # Filter through the returend submodules. for name in names.split(): if filter(name): mods.add(name) logger.debug("collect_submodules - Found submodules: %s", mods) return list(mods)
def collect_submodules_traitsui(package, filter=lambda name: True): # Accept only strings as packages. if not isinstance(package, string_types): raise ValueError logger.debug('Collecting submodules for %s' % package) # Skip a module which is not a package. if not is_package(package): logger.debug('collect_submodules - Module %s is not a package.' % package) return [] # Determine the filesystem path to the specified package. pkg_base, pkg_dir = get_package_paths(package) # Walk the package. Since this performs imports, do it in a separate # process. names = exec_statement(""" import sys import pkgutil def ignore_err(name, err): # Can't print anything because printing is captured as module names # print ("error importing %s: %s" % (name, err)) pass # ``pkgutil.walk_packages`` doesn't walk subpackages of zipped files # per https://bugs.python.org/issue14209. This is a workaround. def walk_packages(path=None, prefix='', onerror=ignore_err): def seen(p, m={{}}): if p in m: return True m[p] = True for importer, name, ispkg in pkgutil.iter_modules(path, prefix): if not name.startswith(prefix): ## Added name = prefix + name ## Added yield importer, name, ispkg if ispkg: try: __import__(name) except ImportError as e: if onerror is not None: onerror(name, e) except Exception as e: if onerror is not None: onerror(name, e) else: raise else: path = getattr(sys.modules[name], '__path__', None) or [] # don't traverse path items we've seen before path = [p for p in path if not seen(p)] ## Use Py2 code here. It still works in Py3. for item in walk_packages(path, name+'.', onerror): yield item ## This is the original Py3 code. #yield from walk_packages(path, name+'.', onerror) for module_loader, name, ispkg in walk_packages([{}], '{}.'): print(name) """.format( # Use repr to escape Windows backslashes. repr(pkg_dir), package)) # Include the package itself in the results. mods = {package} # Filter through the returend submodules. for name in names.split(): if filter(name): mods.add(name) logger.debug("collect_submodules - Found submodules: %s", mods) return list(mods)