Automatically imports symbols of a submodule of a package for given
    (or detected) environment into globals of an entry-point submodule.

    Example::

        - project
        --- __init__.py
        --- settings.py
        --- settings_development.py

    * Here ``project`` is a package available for import (note ``__init__.py``).

    * ``settings.py`` is an entry point module for settings using ``import_by_environment()``.

    * ``settings_development.py`` is one of module files for certain environment (development).

    * ``import_by_environment()`` call in ``settings.py`` makes symbols from ``settings_development.py``
      available from ``settings.py``.

    :param Environment environment:

    :param str|unicode module_name_pattern: Environment submodule name pattern.
        ``%s`` will be replaced with environment name.

    :param bool silent: If ``True`` no import error (if any) will be raised.

    :rtype: Environment|None

    :returns: ``Environment`` object if module is imported or ``None``.

def import_by_environment(environment=None, module_name_pattern='settings_%s', silent=False):
    """Automatically imports symbols of a submodule of a package for given
    (or detected) environment into globals of an entry-point submodule.

    Example::

        - project
        --- __init__.py
        --- settings.py
        --- settings_development.py

    * Here ``project`` is a package available for import (note ``__init__.py``).

    * ``settings.py`` is an entry point module for settings using ``import_by_environment()``.

    * ``settings_development.py`` is one of module files for certain environment (development).

    * ``import_by_environment()`` call in ``settings.py`` makes symbols from ``settings_development.py``
      available from ``settings.py``.

    :param Environment environment:

    :param str|unicode module_name_pattern: Environment submodule name pattern.
        ``%s`` will be replaced with environment name.

    :param bool silent: If ``True`` no import error (if any) will be raised.

    :rtype: Environment|None

    :returns: ``Environment`` object if module is imported or ``None``.

    """
    environment = environment or get_environment()

    module_name_pattern = '.' + module_name_pattern

    settings_module = currentframe().f_back
    package_name = basename(dirname(settings_module.f_code.co_filename))

    result = None

    try:
        env_module = import_module(module_name_pattern % environment, package_name)
        settings_module.f_globals.update(env_module.__dict__)

        result = environment

    except (ImportError, SystemError):
        if not silent:
            raise

    return result