echofilter.ui package
Contents
echofilter.ui package#
User interface.
Submodules#
echofilter.ui.checkpoints module#
Interacting with the list of available checkpoints.
- class echofilter.ui.checkpoints.ListCheckpoints(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]#
Bases:
argparse.Action
- echofilter.ui.checkpoints.cannonise_checkpoint_name(name)[source]#
Cannonises checkpoint name by removing extension.
- echofilter.ui.checkpoints.download_checkpoint(checkpoint_name, cache_dir=None, verbose=1)[source]#
Download a checkpoint if it isn’t already cached.
- Parameters
checkpoint_name (str) – Name of checkpoint to download.
cache_dir (str or None, optional) – Path to local cache directory. If None (default), an OS-appropriate application-specific default cache directory is used.
verbose (int, optional) – Verbosity level. Default is 1. Set to 0 to disable print statements.
- Returns
Path to downloaded checkpoint file.
- Return type
- echofilter.ui.checkpoints.get_checkpoint_list()[source]#
List the currently available checkpoints, as stored in a local file.
- Returns
checkpoints – Dictionary with a key for each checkpoint. Each key maps to a dictionary whose elements describe the checkpoint.
- Return type
OrderedDict
- echofilter.ui.checkpoints.get_default_checkpoint()[source]#
Get the name of the current default checkpoint.
- Returns
checkpoint_name – Name of current checkpoint.
- Return type
- echofilter.ui.checkpoints.load_checkpoint(ckpt_name=None, cache_dir=None, device='cpu', return_name=False, verbose=1)[source]#
Load a checkpoint, either from absolute path or the cache.
- Parameters
checkpoint_name (str or None, optional) – Path to checkpoint file, or name of checkpoint to download. Default is None.
cache_dir (str or None, optional) – Path to local cache directory. If None (default), an OS-appropriate application-specific default cache directory is used.
device (str or torch.device or None, optional) – Device onto which weight tensors will be mapped. If None, no mapping is performed and tensors will be loaded onto the same device as they were on when saved (which will result in an error if the device is not present). Default is “cpu”.
return_name (bool, optional) – If True, a tuple is returned indicting the name of the checkpoint which was loaded. This is useful if the default checkpoint was loaded. Default is False.
verbose (int, optional) – Verbosity level. Default is 1. Set to 0 to disable print statements.
- Returns
checkpoint (dict) – Loaded checkpoint.
checkpoint_name (str, optional) – If return_name is True, the name of the checkpoint is also returned.
echofilter.ui.formatters module#
Provides extensions to argparse.
- class echofilter.ui.formatters.DedentTextHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]#
Bases:
argparse.HelpFormatter
Help message formatter which retains formatting of all help text, except from indentation. Leading new lines are also stripped.
- class echofilter.ui.formatters.FlexibleHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]#
Bases:
argparse.HelpFormatter
Help message formatter which can handle different formatting specifications.
The following formatters are supported:
- “R|”
Raw. will be left as is, processed using argparse.RawTextHelpFormatter.
- “d|”
Raw except for indentation. Will be dedented and leading newlines stripped only, processed using argparse.RawTextHelpFormatter.
The format specifier will be stripped from the text.
Notes
Based on https://stackoverflow.com/a/22157266/1960959 and https://sourceforge.net/projects/ruamel-std-argparse/.
- echofilter.ui.formatters.format_parser_for_sphinx(parser)[source]#
Pre-format parser help for sphinx-argparse processing.
- Parameters
parser (argparse.ArgumentParser) – Initial argument parser.
- Returns
parser – The same argument parser, but with raw help text touched up so it renders correctly when passed through sphinx-argparse.
- Return type
echofilter.ui.inference_cli module#
Provides a command line interface for the inference routine.
This is separated out from inference.py so the responsiveness for simple
commands like --help
and --version
is faster, not needing to import
the full dependency stack.
- class echofilter.ui.inference_cli.ListColors(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]#
Bases:
argparse.Action
- echofilter.ui.inference_cli.cli()[source]#
Run run_inference with arguments taken from the command line using argparse.
echofilter.ui.style module#
User interface styling, using ANSI codes and colorama.
- class echofilter.ui.style.AsideStyle[source]#
Bases:
echofilter.ui.style._AbstractStyle
Defines the style for aside text; dim style.
- reset = '\x1b[22m'#
- start = '\x1b[2m'#
- class echofilter.ui.style.DryrunStyle[source]#
Bases:
echofilter.ui.style._AbstractStyle
Defines the style for dry-run text; magenta foreground.
- reset = '\x1b[39m'#
- start = '\x1b[35m'#
- class echofilter.ui.style.ErrorStyle[source]#
Bases:
echofilter.ui.style._AbstractStyle
Defines the style for an error string; red foreground.
- reset = '\x1b[39m'#
- start = '\x1b[31m'#
- class echofilter.ui.style.HighlightStyle[source]#
Bases:
echofilter.ui.style._AbstractStyle
Defines the style for highlighted text; bright style.
- reset = '\x1b[22m'#
- start = '\x1b[1m'#
- class echofilter.ui.style.OverwriteStyle[source]#
Bases:
echofilter.ui.style._AbstractStyle
Defines the style for overwrite text; bright blue.
- reset = '\x1b[39m\x1b[22m'#
- start = '\x1b[34m\x1b[1m'#
- class echofilter.ui.style.ProgressStyle[source]#
Bases:
echofilter.ui.style._AbstractStyle
Defines the style for a progress string; green foreground.
- reset = '\x1b[39m'#
- start = '\x1b[32m'#
- class echofilter.ui.style.SkipStyle[source]#
Bases:
echofilter.ui.style._AbstractStyle
Defines the style for skip text; yellow foreground.
- reset = '\x1b[39m'#
- start = '\x1b[33m'#
- class echofilter.ui.style.WarningStyle[source]#
Bases:
echofilter.ui.style._AbstractStyle
Defines the style for a warning string; cyan foreground.
- reset = '\x1b[39m'#
- start = '\x1b[36m'#
- echofilter.ui.style.aside_fmt(string)[source]#
Wrap a string in ANSI codes to render it in an aside (de-emphasised) style when printed at the terminal.
- echofilter.ui.style.dryrun_fmt(string)[source]#
Wrap a string in ANSI codes to render it in the style of dry-run text when printed at the terminal.
- echofilter.ui.style.error_fmt(string)[source]#
Wrap a string in ANSI codes to render it in the style of an error when printed at the terminal.
- class echofilter.ui.style.error_message(message='')[source]#
Bases:
contextlib.AbstractContextManager
Wrap an error message in ANSI codes to stylise its appearance in the terminal as red and bold (bright). If the context is exited with an error, that error message will be red.
- echofilter.ui.style.highlight_fmt(string)[source]#
Wrap a string in ANSI codes to render it in a highlighted style when printed at the terminal.
- echofilter.ui.style.overwrite_fmt(string)[source]#
Wrap a string in ANSI codes to render it in the style of an overwrite message when printed at the terminal.
- echofilter.ui.style.progress_fmt(string)[source]#
Wrap a string in ANSI codes to render it in the style of progress text when printed at the terminal.
- echofilter.ui.style.skip_fmt(string)[source]#
Wrap a string in ANSI codes to render it in the style of a skip message when printed at the terminal.
- echofilter.ui.style.warning_fmt(string)[source]#
Wrap a string in ANSI codes to render it in the style of a warning when printed at the terminal.
- class echofilter.ui.style.warning_message(message='')[source]#
Bases:
contextlib.AbstractContextManager
Wrap a warning message in ANSI codes to stylise its appearance in the terminal as cyan and bold (bright). All statements printed during the context will be in cyan.
echofilter.ui.train_cli module#
Provides a command line interface for the training routine.
This is separated out from train.py so the documentation can be accessed without having all the training dependencies installed.