repype.cli
- class repype.cli.StatusReaderConsoleAdapter(*args, indent: int = 2, batch: Batch | None = None, **kwargs)
Bases:
StatusReaderWrites formatted status updates to stdout.
The status updates are indented according to the level of the nesting hierarchy. In addition, an empty line is printed when the level of indentation changes. Intermediate status updates can be muted by setting the environment variable
REPYPE_CLI_INTERMEDIATEto0.Sub-classes can be used to customize the formatting of status updates, or to add entirely new types of status updates:
>>> import repype.cli >>> >>> class ExtendedStatusReader(repype.cli.StatusReaderConsoleAdapter): ... def format(self, positions, status, intermediate): ... if isinstance(status, dict) and status.get('info') == 'custom': ... return f'*** {status["text"]} ({status["number"]})' ... return super().format(positions, status, intermediate) ... >>> async def main(): ... with repype.status.create() as status: ... async with ExtendedStatusReader(status.filepath): ... repype.status.update(status, info = 'custom', text = 'Text', number = 42) ... >>> import asyncio >>> asyncio.run(main()) *** Text (42)
- Parameters:
*args – Passed through to the base class.
indent – Indentation level for each line of the status (for each level of the nesting hierarchy).
batch – Batch instance used for running tasks.
**kwargs – Passed through to the base class.
- clear_line(line: str) str
Clear any previously printed intermediate line by appending the proper number of spaces.
- format(positions: List[int], status: str | dict, intermediate: bool) str
Format a status update as a string.
- format_progress_details(details: dict) str
Format the details of a progress status update as a string.
- full_format(positions: List[int], status: str | dict, intermediate: bool) str
Format the status update as a string, including indentation and empty lines between blocks of different indentation.
- handle_new_status(positions: List[int], status: str | dict | None, intermediate: bool) None
Process a new status update.
- Parameters:
positions – The sequence of elements along the path, represented by the positions of the elements within the parent lists.
status – The new status update. Can only be None if intermediate is True, indicating that the intermediate status is cleared.
intermediate – True if the status update is intermediate, and False otherwise.
- indent: int
Indentation level for each line of the status (for each level of the nesting hierarchy).
- margin: str | None
Last margin used for the status (corresponds to the total indentation).
None if no status has been printed yet.
- progress_bar_length = 20
Length of the progress bar displayed for
repype.status.progress()status updates.
- repype.cli.format_hms(seconds)
Format a duration in seconds as hours, minutes, and seconds.
- repype.cli.main(path: ~repype.typing.PathLike, run: bool = False, reset: bool = False, tasks: ~typing.List[~repype.typing.PathLike] = [], task_dirs: ~typing.List[~repype.typing.PathLike] = [], task_cls: ~typing.Type[~repype.task.Task] = <class 'repype.task.Task'>, status_reader_cls: ~typing.Type[~repype.status.StatusReader] = <class 'repype.cli.StatusReaderConsoleAdapter'>) Coroutine[Any, Any, bool]
Create a co-routine for running the command-line interface for batch processing.
- Parameters:
path – The root directory for batch processing. Tasks will be loaded recursively from this directory.
run – Whether to run the batch processing. If False, the tasks will be loaded, but not executed. Can only be True if reset is False.
reset – Whether to reset the selected tasks. Can only be True if run is False.
tasks – List of tasks to run. Tasks are identified by their paths. If given, only these tasks will be run.
task_dirs – List of task directories to run. If given, only tasks from these directories and their sub-directories will be run.
task_cls – The task class to use for loading tasks.
status_reader_cls – The status reader implementation to use for displaying status updates.
- Raises:
AssertionError – If run and reset are both True.
- Returns:
Co-routine for batch processing. The co-routine returns True upon success, False if an error occurred.
- repype.cli.run_cli(task_cls: ~typing.Type[~repype.task.Task] = <class 'repype.task.Task'>, status_reader_cls: ~typing.Type[~repype.status.StatusReader] = <class 'repype.cli.StatusReaderConsoleAdapter'>) bool
Run the command-line interface for batch processing, parsing options from the command line.
- Parameters:
task_cls – The task class to use for loading tasks.
status_reader_cls – The status reader implementation to use for displaying status updates.
- Returns:
True if the batch processing was successful, False if an error occurred.