本文整理匯總了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)
示例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)
示例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)
)
示例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)
示例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
示例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)
示例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()
示例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()
示例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')
示例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)