Python flask.cli.ScriptInfo() Examples
The following are 14
code examples of flask.cli.ScriptInfo().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.cli
, or try the search function
.
Example #1
Source File: testing.py From recruit with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: testing.py From Building-Recommendation-Systems-with-Python with MIT License | 6 votes |
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)
Example #3
Source File: testing.py From Building-Recommendation-Systems-with-Python with MIT License | 6 votes |
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)
Example #4
Source File: testing.py From scylla with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: pytest.py From flask-unchained with MIT License | 6 votes |
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)
Example #6
Source File: testing.py From android_universal with MIT License | 6 votes |
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)
Example #7
Source File: test_flask.py From sentry-python with BSD 2-Clause "Simplified" License | 5 votes |
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) )
Example #8
Source File: conftest.py From flask-security with MIT License | 5 votes |
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)
Example #9
Source File: __init__.py From udata with GNU Affero General Public License v3.0 | 5 votes |
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
Example #10
Source File: __init__.py From udata with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #11
Source File: cli.py From flask-unchained with MIT License | 5 votes |
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()
Example #12
Source File: job.py From Flask-RQ2 with MIT License | 5 votes |
def __init__(self, *args, **kwargs): super(FlaskJob, self).__init__(*args, **kwargs) self.script_info = ScriptInfo()
Example #13
Source File: cli.py From Flask-RQ2 with MIT License | 5 votes |
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')
Example #14
Source File: test_commands.py From alchemydumps with MIT License | 5 votes |
def runner(command, args=""): obj = ScriptInfo(app_import_path="tests/integration/app.py") return CliRunner().invoke(command, args=args, obj=obj)