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:
pecan.commands.base.BaseCommandParent
A base interface for Pecan commands.
Can be extended to support
pecan
command 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:
object
A base interface for Pecan commands.
Can be extended to support
pecan
command 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:
object
Used to discover pecan.command entry points.
- class pecan.commands.base.CommandRunner¶
Bases:
object
Dispatches 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:
argparse.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:
wsgiref.simple_server.WSGIRequestHandler
,object
A wsgiref request handler class that allows actual log output depending on the application configuration.
- log_message(format, *args)¶
overrides the
log_message
method 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:
pecan.commands.base.BaseCommand
Serves 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_pecan
command for launchingpecan
applications
pecan.commands.shell
– Pecan Interactive Shell¶
Shell command for Pecan.
- class pecan.commands.shell.BPythonShell¶
Bases:
object
Open 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:
object
Open 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:
object
Open 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:
pecan.commands.base.BaseCommand
Open 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.