Module Expr Str ImportFrom alias ImportFrom alias ImportFrom alias alias ImportFrom alias alias ImportFrom alias alias ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr For NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str ListLoad body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad Assign NameStore Call NameLoad NameLoad Str NameLoad Expr Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Raise Call NameLoad decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr keyword Call AttributeLoad AttributeLoad NameLoad attr attr Str ListLoad keyword Call AttributeLoad AttributeLoad NameLoad attr attr Str ListLoad decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr Str keyword NameLoad keyword NameLoad Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults vararg kwarg body Expr Str Raise Call NameLoad decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad NameLoad NameLoad body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr BoolOpOr NameLoad Str keyword NameLoad keyword NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore BinOpAdd BinOpAdd NameLoad Str AttributeLoad NameLoad attr TryExcept body Assign NameStore Call NameLoad NameLoad keyword AttributeLoad NameLoad attr handlers ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Return ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Return Assign NameStore ListLoad If CompareIn Str Call NameLoad NameLoad body AugAssignAdd NameStore Call NameLoad NameLoad Str If CompareIn Str Call NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad Str For NameStore NameLoad body If Call NameLoad NameLoad NameLoad body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad keyword Call AttributeLoad Call AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr Str Dict attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad decorator_list decorator_list
N/A N/A 
Application discovery registries.

They provide discovery functionality useful for dynamically constructing Flask
applications based on configuration variables. This allows a developer to
package config, blueprints and extensions into isolated and reusable packages
which a framework can dynamically install into a Flask application.

Such a package (named ``tests``) could look like:

 * ``tests.views`` -- contains blueprints which should be registered on the
   application object.
 * ``tests.mockext`` -- contains a ``setup_app()`` method which be used to
   install any Flask extensions on the application object.
 * ``tests.config`` -- contains configuration variables specific for this
   module.

Following is a simplified example of a Flask application factory, that will
load config, extensions and blueprints:

.. doctest::

    >>> from flask import Flask, Blueprint
    >>> from flask_registry import Registry, PackageRegistry
    >>> from flask_registry import ExtensionRegistry
    >>> from flask_registry import ConfigurationRegistry
    >>> from flask_registry import BlueprintAutoDiscoveryRegistry
    >>> class Config(object):
    ...     PACKAGES = ['tests']
    ...     EXTENSIONS = ['tests.mockext']
    ...     USER_CFG = True
    >>> def create_app(config):
    ...     app = Flask('myapp')
    ...     app.config.from_object(config)
    ...     r = Registry(app=app)
    ...     r['packages'] = PackageRegistry(app)
    ...     r['extensions'] = ExtensionRegistry(app)
    ...     r['config'] = ConfigurationRegistry(app)
    ...     r['blueprints'] = BlueprintAutoDiscoveryRegistry(app=app)
    ...     return app
    >>> config = Config()
    >>> app = create_app(config)

Packages
^^^^^^^^
The config variable ``PACKAGES`` specifies the list of Python packages, which
``ConfigurationRegistry`` and ``BlueprintAutoDiscoveryRegistry``
will search for ``config.py`` and ``views.py`` modules inside.

.. doctest::

    >>> for pkg in app.extensions['registry']['packages']:
    ...     print(pkg)
    tests

Extensions
^^^^^^^^^^
The config variable ``EXTENSIONS`` specifies the list of Python packages,
which the ``ExtensionRegistry`` will load and call ``setup_app(app)`` on,
to dynamically initialize Flask extensions.

.. doctest::

    >>> for pkg in app.extensions['registry']['extensions']:
    ...     print(pkg)
    tests.mockext

Configuration
^^^^^^^^^^^^^
The ``ConfigurationRegistry`` will merge any package defined config, with the
application config without overwriting already set variables in the application
config:

.. doctest::

    >>> config.USER_CFG
    True
    >>> import tests.config
    >>> tests.config.USER_CFG
    False
    >>> app.config['USER_CFG']
    True

Blueprints
^^^^^^^^^^
The ``BlueprintAutoDiscoveryRegistry`` will search for blueprints defined
inside a ``views`` module in each package defined in ``PACKAGES``. It will
also register the discovered blueprints on the Flask application.
Each ``views`` module should define either a single blueprint in the variable
``blueprint`` and/or multiple blueprints in the variable ``blueprints``:

.. doctest::

    >>> from tests import views
    >>> isinstance(views.blueprint, Blueprint)
    True
    >>> len(views.blueprints)
    2
    >>> for k in sorted(app.blueprints.keys()):
    ...     print(k)
    test
    test1
    test2

 __future__ absolute_import werkzeug.utils import_string flask Blueprint Config core ListRegistry ImportPathRegistry modulediscovery ModuleDiscoveryRegistry ModuleAutoDiscoveryRegistry ExtensionRegistry N/A ListRegistry N/A N/A 
    Flask extensions registry.

    Loads all extensions specified by ``EXTENSIONS`` configuration variable.
    The registry will look for a ``setup_app`` function in the extension and
    call it if it exists.

    Example configuration::

        EXTENSIONS = [
            'invenio.ext.debug_toolbar',
            'invenio.ext.menu:MenuAlchemy',
        ]

    :param app: Flask application to get configuration from.
     __init__ N/A N/A self app N/A N/A N/A N/A N/A N/A super ExtensionRegistry self __init__ N/A ext_name N/A N/A N/A app config get EXTENSIONS N/A N/A N/A N/A N/A self register app ext_name N/A register N/A N/A self app ext_name N/A N/A N/A 
        Register a Flask extensions and call ``setup_app()`` on it.

        :param app: Flask application object
        :param ext_name: An import path (e.g. a package, module, object) which
            when loaded has an method ``setup_app()``.
         N/A ext N/A import_string ext_name N/A N/A N/A N/A super ExtensionRegistry self register ext_name N/A ext N/A getattr ext setup_app ext N/A N/A ext app N/A unregister N/A N/A self N/A N/A N/A 
        It is not possible to unregister configuration.
         N/A N/A NotImplementedError N/A N/A PackageRegistry N/A ImportPathRegistry N/A N/A 
    Specialized ``ImportPathRegistry`` that takes the initial list of import
    paths from the ``PACKAGES`` configuration variable in the application.

    :param app: The Flask application object from which includes a ``PACKAGES``
        variable in it's configuration.
     __init__ N/A N/A self app N/A N/A N/A N/A N/A N/A super PackageRegistry self __init__ initial N/A N/A N/A app config get PACKAGES N/A exclude N/A N/A N/A app config get PACKAGES_EXCLUDE N/A N/A N/A ConfigurationRegistry N/A ModuleDiscoveryRegistry N/A N/A 
    Specialized ``ModuleDiscoveryRegistry`` that search for ``config`` modules
    in a list of Python packages and merge them into the Flask application
    config without overwriting already set variables.

    :param app: A Flask application
    :param registry_namespace: The registry namespace of an
        ``ImportPathRegistry`` with a list Python packages to search for
        ``config`` modules in. Defaults to ``packages``.
     __init__ N/A N/A self app registry_namespace N/A None N/A N/A N/A N/A N/A super ConfigurationRegistry self __init__ config registry_namespace registry_namespace with_setup False N/A N/A self new_config N/A Config N/A N/A app config root_path N/A N/A N/A self discover app N/A N/A N/A N/A self new_config update N/A app config N/A N/A N/A N/A app config update N/A self new_config N/A register N/A N/A self new_object N/A N/A N/A 
        Register a new ``config`` module.

        :param new_object: The configuration module.
            ``app.config.from_object()`` will be called on it.
         N/A N/A N/A N/A self new_config from_object new_object N/A N/A N/A N/A super ConfigurationRegistry self register new_object N/A unregister N/A N/A self N/A args kwargs N/A N/A 
        It is not possible to unregister configuration.
         N/A N/A NotImplementedError N/A N/A BlueprintAutoDiscoveryRegistry N/A ModuleAutoDiscoveryRegistry N/A N/A 
    Specialized ``ModuleAutoDiscoveryRegistry`` that search for ``views``
    modules in a list of Python packages and register blueprints found inside
    them.

    Blueprints are loaded by searching for a variable ``blueprints``
    (list of Blueprint instances) or  ``blueprint`` (a
    Blueprint instance). If found, the blueprint will be registered on the
    Flask application.

    A blueprint URL prefix can be overwritten using the
    ``BLUEPRINTS_URL_PREFIXES`` variable in the application configuration::

        BLUEPRINTS_URL_PREFIXES = {
            '<blueprint name>': '<new url prefix>',
            # ...
        }
     __init__ N/A N/A self module_name app with_setup silent N/A None None False False N/A N/A N/A N/A N/A super BlueprintAutoDiscoveryRegistry self __init__ N/A module_name views app app with_setup with_setup silent silent N/A _discover_module N/A N/A self pkg N/A N/A N/A import_str N/A N/A pkg . N/A self module_name N/A N/A N/A module N/A import_string import_str silent N/A self silent N/A N/A N/A ImportError N/A e N/A N/A N/A N/A self _handle_importerror e pkg import_str N/A N/A N/A SyntaxError N/A e N/A N/A N/A N/A self _handle_syntaxerror e pkg import_str N/A N/A candidates N/A N/A N/A blueprints N/A dir module N/A N/A candidates N/A getattr module blueprints N/A N/A blueprint N/A dir module N/A N/A N/A N/A candidates append N/A getattr module blueprint N/A candidate candidates N/A N/A N/A isinstance candidate Blueprint N/A N/A N/A N/A N/A self app register_blueprint candidate url_prefix N/A N/A N/A N/A N/A N/A self app config get BLUEPRINTS_URL_PREFIXES N/A get N/A candidate name N/A N/A N/A self register candidate N/A N/A