pecan.commands – Pecan Commands¶
The pecan.commands module implements the pecan console script
used to provide (for example) pecan serve and pecan shell command line
utilities.
- class pecan.commands.base.BaseCommand¶
Bases:
BaseCommandParentA base interface for Pecan commands.
Can be extended to support
pecancommand extensions in individual Pecan projects, e.g.,$
pecan my-custom-command config.py# myapp/myapp/custom_command.py class CustomCommand(pecan.commands.base.BaseCommand): ''' (First) line of the docstring is used to summarize the command. ''' arguments = ({ 'name': '--extra_arg', 'help': 'an extra command line argument', 'optional': True }) def run(self, args): super(SomeCommand, self).run(args) if args.extra_arg: pass
- class pecan.commands.base.BaseCommandParent¶
Bases:
objectA base interface for Pecan commands.
Can be extended to support
pecancommand extensions in individual Pecan projects, e.g.,$
pecan my-custom-command config.py# myapp/myapp/custom_command.py class CustomCommand(pecan.commands.base.BaseCommand): ''' (First) line of the docstring is used to summarize the command. ''' arguments = ({ 'name': '--extra_arg', 'help': 'an extra command line argument', 'optional': True }) def run(self, args): super(SomeCommand, self).run(args) if args.extra_arg: pass
- run(args)¶
To be implemented by subclasses.
- class pecan.commands.base.CommandManager¶
Bases:
objectUsed to discover pecan.command entry points.
- class pecan.commands.base.CommandRunner¶
Bases:
objectDispatches pecan command execution requests.
- class pecan.commands.base.HelpfulArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)¶
Bases:
ArgumentParser- error(message: string)¶
Prints a usage message incorporating the message to stderr and exits.
If you override this in a subclass, it should not return – it should either exit or raise an exception.
pecan.commands.server – Pecan Development Server¶
Serve command for Pecan.
- class pecan.commands.serve.PecanWSGIRequestHandler(*args, **kwargs)¶
Bases:
WSGIRequestHandler,objectA wsgiref request handler class that allows actual log output depending on the application configuration.
- log_message(format, *args)¶
overrides the
log_messagemethod from the wsgiref server so that normal logging works with whatever configuration the application has been set to.Levels are inferred from the HTTP status code, 4XX codes are treated as warnings, 5XX as errors and everything else as INFO level.
- class pecan.commands.serve.ServeCommand¶
Bases:
BaseCommandServes a Pecan web application.
This command serves a Pecan web application using the provided configuration file for the server and application.
- run(args)¶
To be implemented by subclasses.
- serve(app, conf)¶
A very simple approach for a WSGI server.
- pecan.commands.serve.gunicorn_run()¶
The
gunicorn_pecancommand for launchingpecanapplications
pecan.commands.shell – Pecan Interactive Shell¶
Shell command for Pecan.
- class pecan.commands.shell.BPythonShell¶
Bases:
objectOpen an interactive bpython shell with the Pecan app loaded.
- classmethod invoke(ns, banner)¶
- Parameters:
ns – local namespace
banner – interactive shell startup banner
Embed an interactive bpython shell.
- class pecan.commands.shell.IPythonShell¶
Bases:
objectOpen an interactive ipython shell with the Pecan app loaded.
- classmethod invoke(ns, banner)¶
- Parameters:
ns – local namespace
banner – interactive shell startup banner
Embed an interactive ipython shell. Try the InteractiveShellEmbed API first, fall back on IPShellEmbed for older IPython versions.
- class pecan.commands.shell.NativePythonShell¶
Bases:
objectOpen an interactive python shell with the Pecan app loaded.
- classmethod invoke(ns, banner)¶
- Parameters:
ns – local namespace
banner – interactive shell startup banner
Embed an interactive native python shell.
- class pecan.commands.shell.ShellCommand¶
Bases:
BaseCommandOpen an interactive shell with the Pecan app loaded. Attempt to invoke the specified python shell flavor (ipython, bpython, etc.). Fall back on the native python shell if the requested flavor variance is not installed.
- invoke_shell(locs, banner)¶
Invokes the appropriate flavor of the python shell. Falls back on the native python shell if the requested flavor (ipython, bpython,etc) is not installed.
- load_model(config)¶
Load the model extension module
- run(args)¶
Load the pecan app, prepare the locals, sets the banner, and invokes the python shell.