MCPcopy Create free account
hub / github.com/pallets/quart / shell_command

Function shell_command

src/quart/cli.py:668–709  ·  view source on GitHub ↗

Run an interactive Python shell in the context of a given Quart application. The application will populate the default namespace of this shell according to its configuration. This is useful for executing small snippets of management code without having to manually configure the appl

()

Source from the content-addressed store, hash-verified

666@click.command("shell", short_help="Run a shell in the app context.")
667@with_appcontext
668def shell_command() -> None:
669 """Run an interactive Python shell in the context of a given
670 Quart application. The application will populate the default
671 namespace of this shell according to its configuration.
672 This is useful for executing small snippets of management code
673 without having to manually configure the application.
674 """
675 banner = (
676 f"Python {sys.version} on {sys.platform}\n"
677 f"App: {current_app.import_name}\n"
678 f"Instance: {current_app.instance_path}"
679 )
680 ctx: dict = {}
681
682 # Support the regular Python interpreter startup script if someone
683 # is using it.
684 startup = os.environ.get("PYTHONSTARTUP")
685 if startup and os.path.isfile(startup):
686 with open(startup) as f:
687 eval(compile(f.read(), startup, "exec"), ctx)
688
689 ctx.update(current_app.make_shell_context())
690
691 # Site, customize, or startup script can set a hook to call when
692 # entering interactive mode. The default one sets up readline with
693 # tab and history completion.
694 interactive_hook = getattr(sys, "__interactivehook__", None)
695
696 if interactive_hook is not None:
697 try:
698 import readline
699 from rlcompleter import Completer
700 except ImportError:
701 pass
702 else:
703 # rlcompleter uses __main__.__dict__ by default, which is
704 # quart.__main__. Use the shell context instead.
705 readline.set_completer(Completer(ctx).complete)
706
707 interactive_hook()
708
709 code.interact(banner=banner, local=ctx)
710
711
712@click.command("routes", short_help="Show the routes for the app.")

Callers

nothing calls this directly

Calls 2

make_shell_contextMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…