예제 #1
0
파일: app.py 프로젝트: shuyunqi/alchemist
def configure(self, app):

    # Detect if we are being invoked by a test runner.
    # Checks the first and second arguments to determine if we are being
    # run by a test runner.
    # Able to match `py.test`, `nosetests`, `alchemist test`,
    # and `python setup.py test`.

    app.config['TESTING'] = False
    count = 3 if os.path.basename(sys.argv[0]).startswith('python') else 2
    for argument in sys.argv[0:count]:
        if 'test' in argument:
            # We are, in fact, being run by a test runner.
            app.config['TESTING'] = True
            break

    # Gather configuration from the following places:
    #  1. alchemist.conf.default_settings
    app.config.from_object('alchemist.conf.default_settings')

    #  2. <package>.settings

    try:
        app.config.from_object('%s.settings' % app.name)

    except ImportError:
        pass

    #  3. Gather configuration from each registered component.

    name = app.name
    for component in components.find('settings', app, raw=True):
        if component.__package__ != name or component.__name__ != name:
            app.config.from_object(component)

    #  4. $ALCHEMIST_SETTINGS_MODULE

    app.config.from_envvar('ALCHEMIST_SETTINGS_MODULE', silent=True)

    #  5. $<package>_SETTINGS_MODULE

    var = '%s_SETTINGS_MODULE' % app.name.replace('.', '_').upper()
    app.config.from_envvar(var, silent=True)

    # Resolve deferred configuration.

    from alchemist.conf import defer

    with app.app_context():
        for name, value in app.config.items():
            if isinstance(value, defer):
                app.config[name] = value.resolve()

    # Gather and import all models modules or packages of the
    # registered components.

    components.find('models', app, raw=True)

    # Register the coercion listener.
    sa.event.listen(sa.orm.mapper, 'mapper_configured', coercion_listener)
예제 #2
0
파일: app.py 프로젝트: shuyunqi/alchemist
def configure(self, app):

    # Detect if we are being invoked by a test runner.
    # Checks the first and second arguments to determine if we are being
    # run by a test runner.
    # Able to match `py.test`, `nosetests`, `alchemist test`,
    # and `python setup.py test`.

    app.config["TESTING"] = False
    count = 3 if os.path.basename(sys.argv[0]).startswith("python") else 2
    for argument in sys.argv[0:count]:
        if "test" in argument:
            # We are, in fact, being run by a test runner.
            app.config["TESTING"] = True
            break

    # Gather configuration from the following places:
    #  1. alchemist.conf.default_settings
    app.config.from_object("alchemist.conf.default_settings")

    #  2. <package>.settings

    try:
        app.config.from_object("%s.settings" % app.name)

    except ImportError:
        pass

    #  3. Gather configuration from each registered component.

    name = app.name
    for component in components.find("settings", app, raw=True):
        if component.__package__ != name or component.__name__ != name:
            app.config.from_object(component)

    #  4. $ALCHEMIST_SETTINGS_MODULE

    app.config.from_envvar("ALCHEMIST_SETTINGS_MODULE", silent=True)

    #  5. $<package>_SETTINGS_MODULE

    var = "%s_SETTINGS_MODULE" % app.name.replace(".", "_").upper()
    app.config.from_envvar(var, silent=True)

    # Resolve deferred configuration.

    from alchemist.conf import defer

    with app.app_context():
        for name, value in app.config.items():
            if isinstance(value, defer):
                app.config[name] = value.resolve()

    # Gather and import all models modules or packages of the
    # registered components.

    components.find("models", app, raw=True)

    # Register the coercion listener.
    sa.event.listen(sa.orm.mapper, "mapper_configured", coercion_listener)
예제 #3
0
    def test_find_raw(self):
        items = components.find('utils',
                                components=['jinja2', 'flask.ext.components'],
                                raw=True)

        assert len(items) == 2
        assert hasattr(items[1], 'find')
예제 #4
0
    def test_find_normalize_limit(self):
        items = components.find('utils',
                                components=['jinja2', 'flask.ext.components'])

        assert len(items) == 2
        assert 'find' in items[1]
        assert 'import_module' not in items[1]
예제 #5
0
    def test_context_config(self):
        app = Flask('components')
        app.config['COMPONENTS'] = ['flask', 'jinja2']
        with app.app_context():
            items = components.find('ext')

        assert len(items) == 2
예제 #6
0
    def __init__(self, app, **kwargs):

        # Initialize color output.
        if sys.stdout.isatty():  # pragma: nocoverage
            colorama.init()

        # Disable loading of default flask-script commands.
        kwargs.setdefault('with_default_commands', False)

        super(Manager, self).__init__(app, **kwargs)

        # Discover commands using the flask-components utility.
        for component in components.find('commands', app):
            for command in component.values():
                if (command and isinstance(command, type) and
                        issubclass(command, (script.Command, script.Manager))):
                    self.add_command(command)
예제 #7
0
    def __init__(self, app, **kwargs):

        # Initialize color output.
        if sys.stdout.isatty():  # pragma: nocoverage
            colorama.init()

        # Disable loading of default flask-script commands.
        kwargs.setdefault('with_default_commands', False)

        super(Manager, self).__init__(app, **kwargs)

        # Discover commands using the flask-components utility.
        for component in components.find('commands', app):
            for command in component.values():
                if (command and isinstance(command, type)
                        and issubclass(command,
                                       (script.Command, script.Manager))):
                    self.add_command(command)
예제 #8
0
    def test_find_nothing(self):
        items = components.find('foo', components=['flask_components'])

        assert len(items) == 0
예제 #9
0
    def test_find_normalize(self):
        items = components.find('ext', components=['flask', 'jinja2'])

        assert len(items) == 2
        assert 'Extension' in items[1]
예제 #10
0
    def test_find_in_module_and_package(self):
        items = components.find('ext', components=['flask', 'jinja2'])

        assert len(items) == 2