本文整理汇总了Python中pkgutil.walk_packages方法的典型用法代码示例。如果您正苦于以下问题:Python pkgutil.walk_packages方法的具体用法?Python pkgutil.walk_packages怎么用?Python pkgutil.walk_packages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkgutil
的用法示例。
在下文中一共展示了pkgutil.walk_packages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def setUp(self):
self.dev_null = open(os.devnull, 'w')
# self.spec = {"modules": {"PlanetPhysicalModel": "PlanetPhysicalModel"}}
self.script = resource_path('test-scripts/template_minimal.json')
with open(self.script) as f:
self.spec = json.loads(f.read())
modtype = getattr(EXOSIMS.Prototypes.Observatory.Observatory, '_modtype')
pkg = EXOSIMS.Observatory
self.allmods = [get_module(modtype)]
for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__ + '.'):
if not is_pkg:
mod = get_module(module_name.split('.')[-1], modtype)
self.assertTrue(mod._modtype is modtype, '_modtype mismatch for %s' % mod.__name__)
self.allmods.append(mod)
示例2: setUp
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def setUp(self):
self.dev_null = open(os.devnull, 'w')
self.script = resource_path('test-scripts/template_minimal.json')
with open(self.script) as f:
self.spec = json.loads(f.read())
with RedirectStreams(stdout=self.dev_null):
self.TL = TargetList(ntargs=10,**copy.deepcopy(self.spec))
self.TL.dist = np.random.uniform(low=0,high=100,size=self.TL.nStars)*u.pc
modtype = getattr(Completeness,'_modtype')
pkg = EXOSIMS.Completeness
self.allmods = [get_module(modtype)]
for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
if (not 'starkAYO' in module_name) and not is_pkg:
mod = get_module(module_name.split('.')[-1],modtype)
self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
self.allmods.append(mod)
示例3: setUp
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def setUp(self):
self.dev_null = open(os.devnull, 'w')
self.script = resource_path('test-scripts/template_prototype_testing.json')
with open(self.script) as f:
self.spec = json.loads(f.read())
with RedirectStreams(stdout=self.dev_null):
self.sim = MissionSim.MissionSim(self.script)
self.TL = self.sim.TargetList
self.nStars = self.TL.nStars
self.star_index = np.array(range(0, self.nStars))
self.Obs = self.sim.Observatory
self.mode = self.sim.OpticalSystem.observingModes[0]
self.TK = self.sim.TimeKeeping
assert self.nStars > 10, "Need at least 10 stars in the target list for the unit test."
self.unit = 1./u.arcsec**2
modtype = getattr(EXOSIMS.Prototypes.ZodiacalLight.ZodiacalLight, '_modtype')
pkg = EXOSIMS.ZodiacalLight
self.allmods = [get_module(modtype)]
for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__ + '.'):
if not is_pkg:
mod = get_module(module_name.split('.')[-1], modtype)
self.assertTrue(mod._modtype is modtype, '_modtype mismatch for %s' % mod.__name__)
self.allmods.append(mod)
示例4: setUp
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def setUp(self):
self.dev_null = open(os.devnull, 'w')
self.script = resource_path('test-scripts/template_minimal.json')
with open(self.script) as f:
self.spec = json.loads(f.read())
with RedirectStreams(stdout=self.dev_null):
self.TL = TargetList(ntargs=10,**copy.deepcopy(self.spec))
self.TL.dist = np.random.uniform(low=0,high=100,size=self.TL.nStars)*u.pc
modtype = getattr(SimulatedUniverse,'_modtype')
pkg = EXOSIMS.SimulatedUniverse
self.allmods = [get_module(modtype)]
for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
if not is_pkg:
mod = get_module(module_name.split('.')[-1],modtype)
self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
self.allmods.append(mod)
示例5: setUp
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def setUp(self):
self.dev_null = open(os.devnull, 'w')
self.script = resource_path('test-scripts/template_minimal.json')
with open(self.script) as f:
self.spec = json.loads(f.read())
with RedirectStreams(stdout=self.dev_null):
self.TL = TargetList(ntargs=10,**copy.deepcopy(self.spec))
modtype = getattr(OpticalSystem,'_modtype')
pkg = EXOSIMS.OpticalSystem
self.allmods = [get_module(modtype)]
for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
if not is_pkg:
mod = get_module(module_name.split('.')[-1],modtype)
self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
self.allmods.append(mod)
示例6: setUp
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def setUp(self):
self.dev_null = open(os.devnull, 'w')
modtype = getattr(EXOSIMS.Prototypes.BackgroundSources.BackgroundSources,'_modtype')
pkg = EXOSIMS.BackgroundSources
self.allmods = [get_module(modtype)]
for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
if not is_pkg:
mod = get_module(module_name.split('.')[-1],modtype)
self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
self.allmods.append(mod)
# need a TargetList object for testing
script = resource_path('test-scripts/template_prototype_testing.json')
with open(script) as f:
spec = json.loads(f.read())
with RedirectStreams(stdout=self.dev_null):
self.TL = TargetList(**spec)
示例7: main
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def main():
results = {'codes': {0: 0, 1: 0}, 'errors': 0}
for _, test, _ in pkgutil.walk_packages(glazier.__path__,
glazier.__name__ + '.'):
if '_test' in test:
print('**** %s ****\n' % test)
proc = subprocess.Popen(['python', '-m', test], stderr=subprocess.PIPE)
_, err = proc.communicate()
err = err.decode()
print(err)
failed = FAILED_RE.search(err)
if failed:
results['errors'] += int(failed.group(1))
results['codes'][proc.returncode] = results['codes'].setdefault(
proc.returncode, 0) + 1
print('Success: %s' % results['codes'][0])
print('Failure: %s' % results['codes'][1])
sys.exit(results['codes'][1])
示例8: load
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def load(path):
# Path needs to be a list in order for the following calls to work.
if type(path) != list: path = [path]
# Walk the directory.
for loader, name, ispkg in pkgutil.walk_packages(path):
module = loader.find_module(name).load_module(name)
# Try to find the module's defined class, and add it to the
# list.
qname = name + "Question"
try:
if qname in dir(module):
categories[qname.lower()] = module.__dict__[qname]
else:
raise NoQuestionInModuleException("No class %s" % qname)
except Exception as e:
print("Skipping module {}: {}".format(name, e))
# Load all of the questions in this path.
示例9: test_tabs
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def test_tabs():
"""Test that there are no tabs in our source files."""
ignore = _tab_ignores[:]
for importer, modname, ispkg in walk_packages(celer.__path__,
prefix='celer.'):
if not ispkg and modname not in ignore:
# mod = importlib.import_module(modname) # not py26 compatible!
try:
with warnings.catch_warnings(record=True): # traits
__import__(modname)
except Exception: # can't import properly
continue
mod = sys.modules[modname]
try:
source = getsource(mod)
except IOError: # user probably should have run "make clean"
continue
assert '\t' not in source, ('"%s" has tabs, please remove them '
'or add it to the ignore list'
% modname)
示例10: import_submodules
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def import_submodules(package):
"""Import all submodules of a module, recursively, including subpackages.
:param package: package (name or actual module)
:type package: str | module
:rtype: dict[str, types.ModuleType]
"""
if isinstance(package, str):
package = importlib.import_module(package)
results = {}
for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
full_name = package.__name__ + '.' + name
try:
results[full_name] = importlib.import_module(full_name)
if is_pkg:
results.update(import_submodules(full_name))
except ModuleNotFoundError as mnfe:
print("module not found: {}".format(full_name))
capture_exception(mnfe)
except Exception as general_exception:
print(general_exception)
capture_exception(general_exception)
return results
示例11: import_submodules
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def import_submodules(package, recursive=True):
""" Import all submodules of a module, recursively, including subpackages
:param package: package (name or actual module)
:type package: str | module
:rtype: dict[str, types.ModuleType]
"""
if isinstance(package, str):
package = importlib.import_module(package)
results = {}
for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
full_name = package.__name__ + '.' + name
try:
results[full_name] = importlib.import_module(full_name)
except:
pass
if recursive and is_pkg:
results.update(import_submodules(full_name))
return results
示例12: get_package_libraries
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def get_package_libraries(pkg):
"""
Recursively yield template tag libraries defined in submodules of a
package.
"""
for entry in walk_packages(pkg.__path__, pkg.__name__ + '.'):
try:
module = import_module(entry[1])
except ImportError as e:
raise InvalidTemplateLibrary(
"Invalid template library specified. ImportError raised when "
"trying to load '%s': %s" % (entry[1], e)
)
if hasattr(module, 'register'):
yield entry[1]
示例13: test_tabs
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def test_tabs():
# Test that there are no tabs in our source files
for importer, modname, ispkg in walk_packages(sklearn.__path__,
prefix='sklearn.'):
if IS_PYPY and ('_svmlight_format' in modname or
'feature_extraction._hashing' in modname):
continue
# because we don't import
mod = importlib.import_module(modname)
try:
source = getsource(mod)
except IOError: # user probably should have run "make clean"
continue
assert '\t' not in source, ('"%s" has tabs, please remove them ',
'or add it to theignore list'
% modname)
示例14: test_import_all_consistency
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def test_import_all_consistency():
# Smoke test to check that any name in a __all__ list is actually defined
# in the namespace of the module or package.
pkgs = pkgutil.walk_packages(path=sklearn.__path__, prefix='sklearn.',
onerror=lambda _: None)
submods = [modname for _, modname, _ in pkgs]
for modname in submods + ['sklearn']:
if ".tests." in modname:
continue
if IS_PYPY and ('_svmlight_format' in modname or
'feature_extraction._hashing' in modname):
continue
package = __import__(modname, fromlist="dummy")
for name in getattr(package, '__all__', ()):
if getattr(package, name, None) is None:
raise AttributeError(
"Module '{0}' has no attribute '{1}'".format(
modname, name))
示例15: test_all_tests_are_importable
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import walk_packages [as 别名]
def test_all_tests_are_importable():
# Ensure that for each contentful subpackage, there is a test directory
# within it that is also a subpackage (i.e. a directory with __init__.py)
HAS_TESTS_EXCEPTIONS = re.compile(r'''(?x)
\.externals(\.|$)|
\.tests(\.|$)|
\._
''')
lookup = {name: ispkg
for _, name, ispkg
in pkgutil.walk_packages(sklearn.__path__, prefix='sklearn.')}
missing_tests = [name for name, ispkg in lookup.items()
if ispkg
and not HAS_TESTS_EXCEPTIONS.search(name)
and name + '.tests' not in lookup]
assert_equal(missing_tests, [],
'{0} do not have `tests` subpackages. Perhaps they require '
'__init__.py or an add_subpackage directive in the parent '
'setup.py'.format(missing_tests))