faust.cli.base

Command-line programs using click.

faust.cli.base.argument(*param_decls, **attrs)[source]

Attaches an argument to the command. All positional arguments are passed as parameter declarations to Argument; all keyword arguments are forwarded unchanged (except cls). This is equivalent to creating an Argument instance manually and attaching it to the Command.params list.

Parameters:cls – the argument class to instantiate. This defaults to Argument.
faust.cli.base.option(*param_decls, **attrs)[source]

Attaches an option to the command. All positional arguments are passed as parameter declarations to Option; all keyword arguments are forwarded unchanged (except cls). This is equivalent to creating an Option instance manually and attaching it to the Command.params list.

Parameters:cls – the option class to instantiate. This defaults to Option.
class faust.cli.base.TCPPort[source]

CLI option: TCP Port (integer in range 1 - 65535).

name = 'range[1-65535]'
faust.cli.base.find_app(app: str, *, symbol_by_name: Callable = <function symbol_by_name>, imp: Callable = <function import_from_cwd>) → faust.types.app.AppT[source]

Find app by string like examples.simple.

Notes

This function uses import_from_cwd to temporarily add the current working directory to PYTHONPATH, such that when importing the app it will search the current working directory last.

You can think of it as temporarily running with the PYTHONPATH set like this:

You can disable this with the imp keyword argument, for example passing imp=importlib.import_module.

Examples

>>> # If providing the name of a module, it will attempt
>>> # to find an attribute name (.app) in that module.
>>> # Example below is the same as importing::
>>> #    from examples.simple import app
>>> find_app('examples.simple')
>>> # If you want an attribute other than .app you can
>>> # use : to separate module and attribute.
>>> # Examples below is the same as importing::
>>> #     from examples.simple import my_app
>>> find_app('examples.simple:my_app')
>>> # You can also use period for the module/attribute separator
>>> find_app('examples.simple.my_app')
Return type:AppT[]
class faust.cli.base.Command(ctx: click.core.Context, *args, **kwargs) → None[source]

Base class for subcommands.

exception UsageError(message, ctx=None)

An internal exception that signals a usage error. This typically aborts any further handling.

Parameters:
  • message – the error message to display.
  • ctx – optionally the context that caused this error. Click will fill in the context automatically in some situations.
exit_code = 2
show(file=None)
abstract = True
builtin_options = [<function version_option.<locals>.decorator>, <function option.<locals>.decorator>, <function option.<locals>.decorator>, <function option.<locals>.decorator>, <function option.<locals>.decorator>, <function option.<locals>.decorator>, <function option.<locals>.decorator>, <function option.<locals>.decorator>, <function option.<locals>.decorator>]
options = None
classmethod as_click_command() → Callable[source]
Return type:Callable
classmethod parse(argv: Sequence[str]) → Mapping[source]

Parse command-line arguments in argv’ and return mapping.

Return type:Mapping[~KT, +VT_co]
prog_name = ''
tabulate(data: Sequence[Sequence[str]], headers: Sequence[str] = None, wrap_last_row: bool = True, title: str = '', title_color: str = 'blue', **kwargs) → str[source]

Create an ANSI representation of a table of two-row tuples.

See also

Keyword arguments are forwarded to terminaltables.SingleTable

Note

If the --json option is enabled this returns json instead.

Return type:str
table(data: Sequence[Sequence[str]], title: str = '', **kwargs) → terminaltables.base_table.BaseTable[source]

Format table data as ANSI/ASCII table.

Return type:BaseTable
color(name: str, text: str) → str[source]

Return text having a certain color by name.

Examples::
>>> self.color('blue', 'text_to_color')
>>> self.color('hiblue', text_to_color')

See also

colorclass: for a list of available colors.

Return type:str
dark(text: str) → str[source]

Return cursor text.

Return type:str
bold(text: str) → str[source]

Return text in bold.

Return type:str
bold_tail(text: str, *, sep: str = '.') → str[source]

Put bold emphasis on the last part of a foo.bar.baz string.

Return type:str
say(*args, **kwargs) → None[source]

Print something to stdout (or use file=stderr kwarg).

Note

Does not do anything if the --quiet option is enabled.

Return type:None
carp(s: Any, **kwargs) → None[source]

Print something to stdout (or use file=stderr kwargs).

Note

Does not do anything if the --debug option is enabled.

Return type:None
dumps(obj: Any) → str[source]
Return type:str
coroutine run(self, *args, **kwargs) → Any[source]
class faust.cli.base.AppCommand(ctx: click.core.Context, *args, key_serializer: Union[faust.types.codecs.CodecT, str, NoneType] = None, value_serializer: Union[faust.types.codecs.CodecT, str, NoneType] = None, **kwargs) → None[source]

Command that takes -A app as argument.

abstract = False
require_app = True
value_serialier = None

The codec used to serialize values. Taken from instance parameters or value_serializer.

classmethod from_handler(*options, **kwargs) → Callable[Callable, Type[_ForwardRef('AppCommand')]][source]
Return type:Callable[[Callable], Type[AppCommand]]
key_serializer = None

The codec used to serialize keys. Taken from instance parameters or key_serializer.

to_key(typ: Union[str, NoneType], key: str) → Any[source]

Convert command-line argument string to model (key).

Parameters:
  • typ (Optional[str]) – The name of the model to create.
  • key (str) – The string json of the data to populate it with.

Notes

Uses key_serializer to set the codec for the key (e.g. "json"), as set by the --key-serializer option.

Return type:Any
to_value(typ: Union[str, NoneType], value: str) → Any[source]

Convert command-line argument string to model (value).

Parameters:
  • typ (Optional[str]) – The name of the model to create.
  • key – The string json of the data to populate it with.

Notes

Uses value_serializer to set the codec for the value (e.g. "json"), as set by the --value-serializer option.

Return type:Any
to_model(typ: Union[str, NoneType], value: str, serializer: Union[faust.types.codecs.CodecT, str, NoneType]) → Any[source]

Convert command-line argument to model.

Generic version of to_key()/to_value().

Parameters:
  • typ (Optional[str]) – The name of the model to create.
  • key – The string json of the data to populate it with.
  • serializer (Union[CodecT, str, None]) – The argument setting it apart from to_key/to_value enables you to specify a custom serializer not mandated by key_serializer, and value_serializer.

Notes

Uses value_serializer to set the codec for the value (e.g. "json"), as set by the --value-serializer option.

Return type:Any
import_relative_to_app(attr: str) → Any[source]

Import string like “module.Model”, or “Model” to model class.

Return type:Any
to_topic(entity: str) → Any[source]

Convert topic name given on command-line to app.topic().

Return type:Any
abbreviate_fqdn(name: str, *, prefix: str = '') → str[source]

Abbreviate fully-qualified Python name, by removing origin.

app.conf.origin is the package where the app is defined, so if this is examples.simple it returns the truncated:

>>> app.conf.origin
'examples.simple'
>>> abbr_fqdn(app.conf.origin,
...           'examples.simple.Withdrawal',
...           prefix='[...]')
'[...]Withdrawal'

but if the package is not part of origin it provides the full path:

>>> abbr_fqdn(app.conf.origin,
...           'examples.other.Foo', prefix='[...]')
'examples.other.foo'
Return type:str