當前位置: 首頁>>代碼示例>>Python>>正文


Python module_loading.module_has_submodule方法代碼示例

本文整理匯總了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 
開發者ID:ulule,項目名稱:django-badgify,代碼行數:23,代碼來源:registry.py

示例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 
開發者ID:znick,項目名稱:anytask,代碼行數:24,代碼來源:simple.py

示例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 
開發者ID:gregoil,項目名稱:rotest,代碼行數:20,代碼來源:resources_discoverer.py

示例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) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:17,代碼來源:base.py

示例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) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:12,代碼來源:config.py

示例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') 
開發者ID:arteria,項目名稱:django-compat,代碼行數:36,代碼來源:test_module_loading.py

示例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) 
開發者ID:zulip,項目名稱:zulip,代碼行數:30,代碼來源:test_fixtures.py

示例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 
開發者ID:mercadona,項目名稱:rele,代碼行數:12,代碼來源:discover.py

示例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)) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:10,代碼來源:apps.py

示例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 
開發者ID:django-leonardo,項目名稱:django-leonardo,代碼行數:36,代碼來源:base.py

示例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 
開發者ID:respondcreate,項目名稱:django-versatileimagefield,代碼行數:39,代碼來源:registry.py

示例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) 
開發者ID:zentralopensource,項目名稱:zentral,代碼行數:11,代碼來源:apps.py

示例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) 
開發者ID:zentralopensource,項目名稱:zentral,代碼行數:7,代碼來源:apps.py

示例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)) 
開發者ID:labd,項目名稱:wagtailstreamforms,代碼行數:11,代碼來源:apps.py

示例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)) 
開發者ID:DivineITLimited,項目名稱:django-hyper-editor,代碼行數:7,代碼來源:utils.py


注:本文中的django.utils.module_loading.module_has_submodule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。