当前位置: 首页>>代码示例>>Python>>正文


Python cli.ScriptInfo方法代码示例

本文整理汇总了Python中flask.cli.ScriptInfo方法的典型用法代码示例。如果您正苦于以下问题:Python cli.ScriptInfo方法的具体用法?Python cli.ScriptInfo怎么用?Python cli.ScriptInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.cli的用法示例。


在下文中一共展示了cli.ScriptInfo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: invoke

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def invoke(self, cli=None, args=None, **kwargs):
        """Invokes a CLI command in an isolated environment. See
        :meth:`CliRunner.invoke <click.testing.CliRunner.invoke>` for
        full method documentation. See :ref:`testing-cli` for examples.

        If the ``obj`` argument is not given, passes an instance of
        :class:`~flask.cli.ScriptInfo` that knows how to load the Flask
        app being tested.

        :param cli: Command object to invoke. Default is the app's
            :attr:`~flask.app.Flask.cli` group.
        :param args: List of strings to invoke the command with.

        :return: a :class:`~click.testing.Result` object.
        """
        if cli is None:
            cli = self.app.cli

        if 'obj' not in kwargs:
            kwargs['obj'] = ScriptInfo(create_app=lambda: self.app)

        return super(FlaskCliRunner, self).invoke(cli, args, **kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:testing.py

示例2: invoke

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def invoke(self, cli=None, args=None, **kwargs):
        """
        Invokes a command in an isolated environment.  The arguments are
        forwarded directly to the command line script, the `extra` keyword
        arguments are passed to the :meth:`~click.Command.main` function of
        the command.

        This returns a :class:`~click.testing.Result` object.

        :param cli: the command to invoke
        :param args: the arguments to invoke
        :param input: the input data for `sys.stdin`.
        :param env: the environment overrides.
        :param catch_exceptions: Whether to catch any other exceptions than
                                 ``SystemExit``.
        :param extra: the keyword arguments to pass to :meth:`main`.
        :param color: whether the output should contain color codes. The
                      application can still override this explicitly.
        """
        if cli is None:
            cli = self.app.cli
        if 'obj' not in kwargs:
            kwargs['obj'] = ScriptInfo(create_app=lambda _: self.app)
        return super().invoke(cli, args, **kwargs) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:26,代码来源:pytest.py

示例3: test_cli_commands_raise

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def test_cli_commands_raise(app):
    if not hasattr(app, "cli"):
        pytest.skip("Too old flask version")

    from flask.cli import ScriptInfo

    @app.cli.command()
    def foo():
        1 / 0

    with pytest.raises(ZeroDivisionError):
        app.cli.main(
            args=["foo"], prog_name="myapp", obj=ScriptInfo(create_app=lambda _: app)
        ) 
开发者ID:getsentry,项目名称:sentry-python,代码行数:16,代码来源:test_flask.py

示例4: script_info

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def script_info(app, sqlalchemy_datastore):
    from flask.cli import ScriptInfo

    def create_app(info):
        uia = [
            {"email": {"mapper": uia_email_mapper}},
            {"username": {"mapper": lambda x: x}},
        ]

        app.config.update(**{"SECURITY_USER_IDENTITY_ATTRIBUTES": uia})
        app.security = Security(app, datastore=sqlalchemy_datastore)
        return app

    return ScriptInfo(create_app=create_app) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:16,代码来源:conftest.py

示例5: load_udata_commands

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def load_udata_commands(self, ctx):
        '''
        Load udata commands from:
        - `udata.commands.*` module
        - known internal modules with commands
        - plugins exporting a `udata.commands` entrypoint
        '''
        if self._udata_commands_loaded:
            return

        # Load all commands submodules
        pattern = os.path.join(os.path.dirname(__file__), '[!_]*.py')
        for filename in iglob(pattern):
            module = os.path.splitext(os.path.basename(filename))[0]
            try:
                __import__('udata.commands.{0}'.format(module))
            except Exception as e:
                error('Unable to import {0}'.format(module), e)

        # Load all core modules commands
        for module in MODULES_WITH_COMMANDS:
            try:
                __import__('udata.{0}.commands'.format(module))
            except Exception as e:
                error('Unable to import {0}'.format(module), e)

        # Load commands from entry points for enabled plugins
        app = ctx.ensure_object(ScriptInfo).load_app()
        entrypoints.get_enabled('udata.commands', app)

        # Ensure loading happens once
        self._udata_commands_loaded = False 
开发者ID:opendatateam,项目名称:udata,代码行数:34,代码来源:__init__.py

示例6: main

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def main(self, *args, **kwargs):
        '''
        Instanciate ScriptInfo before parent does
        to ensure the `settings` parameters is available to `create_app
        '''
        obj = kwargs.get('obj')
        if obj is None:
            obj = ScriptInfo(create_app=self.create_app)
        # This is the import line: allows create_app to access the settings
        obj.settings = kwargs.pop('settings', 'udata.settings.Defaults')
        kwargs['obj'] = obj
        return super(UdataGroup, self).main(*args, **kwargs) 
开发者ID:opendatateam,项目名称:udata,代码行数:14,代码来源:__init__.py

示例7: main

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def main():
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('--env')
    args, _ = parser.parse_known_args()

    env = args.env or os.getenv('FLASK_ENV', DEV)
    os.environ['FLASK_ENV'] = ENV_ALIASES.get(env, env)

    debug = get_boolean_env('FLASK_DEBUG', env not in PROD_ENVS)
    os.environ['FLASK_DEBUG'] = 'true' if debug else 'false'

    maybe_set_app_factory_from_env()
    _load_unchained_config = True
    if _should_create_basic_app(env):
        cli = _get_basic_cli()
        _load_unchained_config = False
    else:
        cli = _get_main_cli()

    # make sure to always load the app. this is necessary because some 3rd party
    # extensions register commands using setup.py, which for some reason
    # bypasses this step
    obj = flask_cli.ScriptInfo(create_app=functools.partial(
        cli_create_app, _load_unchained_config=_load_unchained_config))
    obj.load_app()

    cli.main(args=[arg for arg in sys.argv[1:] if '--env' not in arg], obj=obj)
    clear_env_vars() 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:30,代码来源:cli.py

示例8: __init__

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def __init__(self, *args, **kwargs):
        super(FlaskJob, self).__init__(*args, **kwargs)
        self.script_info = ScriptInfo() 
开发者ID:rq,项目名称:Flask-RQ2,代码行数:5,代码来源:job.py

示例9: add_commands

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def add_commands(cli, rq):
    @click.group(cls=AppGroup, help='Runs RQ commands with app context.')
    @click.pass_context
    def rq_group(ctx):
        ctx.ensure_object(ScriptInfo).data['rq'] = rq

    sorted_commands = sorted(_commands.items(), key=operator.itemgetter(0))
    for name, func in sorted_commands:
        rq_group.command(name=name)(func)

    cli.add_command(rq_group, name='rq') 
开发者ID:rq,项目名称:Flask-RQ2,代码行数:13,代码来源:cli.py

示例10: runner

# 需要导入模块: from flask import cli [as 别名]
# 或者: from flask.cli import ScriptInfo [as 别名]
def runner(command, args=""):
        obj = ScriptInfo(app_import_path="tests/integration/app.py")
        return CliRunner().invoke(command, args=args, obj=obj) 
开发者ID:cuducos,项目名称:alchemydumps,代码行数:5,代码来源:test_commands.py


注:本文中的flask.cli.ScriptInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。