本文整理汇总了Python中django.utils.module_loading.module_has_submodule方法的典型用法代码示例。如果您正苦于以下问题:Python module_loading.module_has_submodule方法的具体用法?Python module_loading.module_has_submodule怎么用?Python module_loading.module_has_submodule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.module_loading
的用法示例。
在下文中一共展示了module_loading.module_has_submodule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _autodiscover
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def _autodiscover(recipes):
import copy
from django.conf import settings
try:
# py27 / py3 only
from importlib import import_module
except ImportError:
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
for app in settings.INSTALLED_APPS:
mod = import_module(app)
try:
before_import_recipes = copy.copy(recipes)
import_module('%s.badgify_recipes' % app)
except Exception:
recipes = before_import_recipes
if module_has_submodule(mod, 'badgify_recipes'):
raise
示例2: get_tests
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def get_tests(app_module):
parts = app_module.__name__.split('.')
prefix, last = parts[:-1], parts[-1]
try:
test_module = import_module('.'.join(prefix + [TEST_MODULE]))
except ImportError:
# Couldn't import tests.py. Was it due to a missing file, or
# due to an import error in a tests.py that actually exists?
# app_module either points to a models.py file, or models/__init__.py
# Tests are therefore either in same directory, or one level up
if last == 'models':
app_root = import_module('.'.join(prefix))
else:
app_root = app_module
if not module_has_submodule(app_root, TEST_MODULE):
test_module = None
else:
# The module exists, so there must be an import error in the test
# module itself.
raise
return test_module
示例3: get_resources
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def get_resources():
"""Get all the resource classes from apps declared in settings.py.
Returns:
dict. all resource classes found in the application {name: class}.
"""
declared_apps = settings.INSTALLED_APPS
resources = {}
for app_name in declared_apps:
app_module = import_module(app_name)
if module_has_submodule(app_module, RESOURCES_MODULE_NAME):
resources_module = '%s.%s' % (app_name, RESOURCES_MODULE_NAME)
app_resources = _import_resources_from_module(resources_module)
resources.update(app_resources)
return resources
示例4: is_library_missing
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def is_library_missing(name):
"""Check if library that failed to load cannot be found under any
templatetags directory or does exist but fails to import.
Non-existing condition is checked recursively for each subpackage in cases
like <appdir>/templatetags/subpackage/package/module.py.
"""
# Don't bother to check if '.' is in name since any name will be prefixed
# with some template root.
path, module = name.rsplit('.', 1)
try:
package = import_module(path)
return not module_has_submodule(package, module)
except ImportError:
return is_library_missing(path)
示例5: import_models
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def import_models(self, all_models):
# Dictionary of models for this app, primarily maintained in the
# 'all_models' attribute of the Apps this AppConfig is attached to.
# Injected as a parameter because it gets populated when models are
# imported, which might happen before populate() imports models.
self.models = all_models
if module_has_submodule(self.module, MODELS_MODULE_NAME):
models_module_name = '%s.%s' % (self.name, MODELS_MODULE_NAME)
self.models_module = import_module(models_module_name)
示例6: test_loader
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def test_loader(self):
"Normal module existence can be tested"
test_module = import_module('compat.tests.utils_tests.test_module')
test_no_submodule = import_module(
'compat.tests.utils_tests.test_no_submodule')
# An importable child
self.assertTrue(module_has_submodule(test_module, 'good_module'))
mod = import_module('compat.tests.utils_tests.test_module.good_module')
self.assertEqual(mod.content, 'Good Module')
# A child that exists, but will generate an import error if loaded
self.assertTrue(module_has_submodule(test_module, 'bad_module'))
with self.assertRaises(ImportError):
import_module('compat.tests.utils_tests.test_module.bad_module')
# A child that doesn't exist
self.assertFalse(module_has_submodule(test_module, 'no_such_module'))
with self.assertRaises(ImportError):
import_module('compat.tests.utils_tests.test_module.no_such_module')
# A child that doesn't exist, but is the name of a package on the path
self.assertFalse(module_has_submodule(test_module, 'django'))
with self.assertRaises(ImportError):
import_module('compat.tests.utils_tests.test_module.django')
# Don't be confused by caching of import misses
import types # NOQA: causes attempted import of utils_tests.types
self.assertFalse(module_has_submodule(sys.modules['compat.tests.utils_tests'], 'types'))
# A module which doesn't have a __path__ (so no submodules)
self.assertFalse(module_has_submodule(test_no_submodule, 'anything'))
with self.assertRaises(ImportError):
import_module('compat.tests.utils_tests.test_no_submodule.anything')
示例7: get_migration_status
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def get_migration_status(**options: Any) -> str:
verbosity = options.get('verbosity', 1)
for app_config in apps.get_app_configs():
if module_has_submodule(app_config.module, "management"):
import_module('.management', app_config.name)
app_label = options['app_label'] if options.get('app_label') else None
db = options.get('database', DEFAULT_DB_ALIAS)
out = StringIO()
command_args = ['--list']
if app_label:
command_args.append(app_label)
call_command(
'showmigrations',
*command_args,
database=db,
no_color=options.get('no_color', False),
settings=options.get('settings', os.environ['DJANGO_SETTINGS_MODULE']),
stdout=out,
traceback=options.get('traceback', True),
verbosity=verbosity,
)
connections.close_all()
out.seek(0)
output = out.read()
return re.sub(r'\x1b\[(1|0)m', '', output)
示例8: discover_subs_modules
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def discover_subs_modules():
logger.debug("Autodiscovering subs...")
app_configs = apps.get_app_configs()
subs_modules = []
for conf in app_configs:
if module_has_submodule(conf.module, "subs"):
module = conf.name + ".subs"
subs_modules.append(module)
logger.debug(" * Discovered subs module: %r" % module)
return subs_modules
示例9: get_app_submodules
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def get_app_submodules(submodule_name):
"""
Searches each app module for the specified submodule
yields tuples of (app_name, module)
"""
for name, module in get_app_modules():
if module_has_submodule(module, submodule_name):
yield name, import_module('%s.%s' % (name, submodule_name))
示例10: get_app_modules
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def get_app_modules(self, apps):
"""return array of imported leonardo modules for apps
"""
modules = getattr(self, "_modules", [])
if not modules:
from django.utils.module_loading import module_has_submodule
# Try importing a modules from the module package
package_string = '.'.join(['leonardo', 'module'])
for app in apps:
exc = '...'
try:
# check if is not full app
_app = import_module(app)
except Exception as e:
_app = False
exc = e
if module_has_submodule(
import_module(package_string), app) or _app:
if _app:
mod = _app
else:
mod = import_module('.{0}'.format(app), package_string)
if mod:
modules.append(mod)
continue
warnings.warn('%s was skipped because %s ' % (app, exc))
self._modules = modules
return self._modules
示例11: autodiscover
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def autodiscover():
"""
Discover versatileimagefield.py modules.
Iterate over django.apps.get_app_configs() and discover
versatileimagefield.py modules.
"""
from importlib import import_module
from django.apps import apps
from django.utils.module_loading import module_has_submodule
for app_config in apps.get_app_configs():
# Attempt to import the app's module.
try:
before_import_sizedimage_registry = copy.copy(
versatileimagefield_registry._sizedimage_registry
)
before_import_filter_registry = copy.copy(
versatileimagefield_registry._filter_registry
)
import_module('%s.versatileimagefield' % app_config.name)
except Exception:
# Reset the versatileimagefield_registry to the state before the
# last import as this import will have to reoccur on the next
# request and this could raise NotRegistered and AlreadyRegistered
# exceptions (see django ticket #8245).
versatileimagefield_registry._sizedimage_registry = \
before_import_sizedimage_registry
versatileimagefield_registry._filter_registry = \
before_import_filter_registry
# Decide whether to bubble up this error. If the app just
# doesn't have the module in question, we can ignore the error
# attempting to import it, otherwise we want it to bubble up.
if module_has_submodule(app_config.module, 'versatileimagefield'):
raise
示例12: import_events
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def import_events(self):
if module_has_submodule(self.module, EVENTS_MODULE_NAME):
events_module_name = "%s.%s" % (self.name, EVENTS_MODULE_NAME)
self.events_module = import_module(events_module_name)
logger.debug('Events module "%s" loaded', events_module_name)
events_templates_dir = os.path.join(self.path, 'events/templates')
if os.path.exists(events_templates_dir):
self.events_templates_dir = events_templates_dir
logger.debug('Found events templates dir "%s"', events_templates_dir)
示例13: import_probes
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def import_probes(self):
if module_has_submodule(self.module, PROBES_MODULE_NAME):
probes_module_name = "%s.%s" % (self.name, PROBES_MODULE_NAME)
self.probes_module = import_module(probes_module_name)
logger.debug('Probes module "%s" imported', probes_module_name)
示例14: get_app_submodules
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def get_app_submodules(submodule_name):
"""
Searches each app module for the specified submodule
yields tuples of (app_name, module)
"""
for name, module in get_app_modules():
if module_has_submodule(module, submodule_name):
yield name, import_module("%s.%s" % (name, submodule_name))
示例15: load_hyper_blocks
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import module_has_submodule [as 别名]
def load_hyper_blocks():
submodule_name = 'hyper_blocks'
for name, module in get_app_modules():
if module_has_submodule(module, submodule_name):
yield name, import_module('%s.%s' % (name, submodule_name))