Progress¶
- class lsst.daf.butler.progress.Progress(name: str, level: int = 20)¶
Bases:
objectPublic interface for reporting incremental progress in the butler and related tools.
This class automatically creates progress bars (or not) depending on whether a handle (see
ProgressHandler) has been installed and the given name and level are enabled. When progress reporting is not enabled, it returns dummy objects that can be used just like progress bars by calling code.- Parameters:
- name
str Name of the process whose progress is being reported. This is in general the name of a group of progress bars, not necessarily a single one, and it should have the same form as a logger name.
- level
int, optional A
logginglevel value (defaults tologging.INFO). Progress reporting is enabled if a logger withnameis enabled for this level, and aProgressHandlerhas been installed.
- name
Notes
The progress system inspects the level for a name using the Python built-in
loggingmodule, and may not respect level-setting done via thelsst.loginterface. But whileloggingmay be necessary to control progress bar visibility, the progress system can still be used together with either system for actual logging.Methods Summary
at(level)Return a copy of this progress interface with a different level.
bar([iterable, desc, total, skip_scalar])Return a new progress bar context manager.
Check whether this process should report progress.
iter_chunks(chunks[, desc, total, skip_scalar])Wrap iteration over chunks of elements in a progress bar.
iter_item_chunks(items[, desc, total, ...])Wrap iteration over chunks of items in a progress bar.
set_handler(handler)Set the (global) progress handler to the given instance.
wrap(iterable[, desc, total, skip_scalar])Iterate over an object while reporting progress.
Methods Documentation
- at(level: int) Progress¶
Return a copy of this progress interface with a different level.
- Parameters:
- level
int A
logginglevel value. Progress reporting is enabled if a logger withnameis enabled for this level, and aProgressHandlerhas been installed.
- level
- Returns:
- bar(iterable: Iterable[_T] | None = None, desc: str | None = None, total: int | None = None, skip_scalar: bool = True) AbstractContextManager[ProgressBar[_T]]¶
Return a new progress bar context manager.
- Parameters:
- iterable
Iterable, optional An arbitrary Python iterable that will be iterated over when the returned
ProgressBaris. If not provided, whether the progress bar is iterable is handler-defined, but it may be updated manually.- desc
str, optional A user-friendly description for this progress bar; usually appears next to it. If not provided,
self.nameis used (which is not usually a user-friendly string, but may be appropriate for debug-level progress).- total
int, optional The total number of steps in this progress bar. If not provided,
len(iterable)is used. If that does not work, whether the progress bar works at all is handler-defined, and hence this mode should not be relied upon.- skip_scalar
bool, optional If
Trueandtotalis zero or one, do not report progress.
- iterable
- Returns:
- bar
contextlib.AbstractContextManager[ProgressBar] A context manager that returns an object satisfying the
ProgressBarinterface when it is entered.
- bar
- is_enabled() bool¶
Check whether this process should report progress.
- Returns:
- enabled
bool Trueif there is aProgressHandlerset and a logger with the same name and level asselfis enabled.
- enabled
- iter_chunks(chunks: Iterable[_V], desc: str | None = None, total: int | None = None, skip_scalar: bool = True) Generator[_V, None, None]¶
Wrap iteration over chunks of elements in a progress bar.
- Parameters:
- chunks
Iterable An iterable whose elements are themselves iterable.
- desc
str, optional A user-friendly description for this progress bar; usually appears next to it. If not provided,
self.nameis used (which is not usually a user-friendly string, but may be appropriate for debug-level progress).- total
int, optional The total number of steps in this progress bar; defaults to the sum of the lengths of the chunks if this can be computed. If this is provided or
True, each element inchunksmust be sized butchunksitself need not be (and may be a single-pass iterable).- skip_scalar
bool, optional If
Trueand there are zero or one chunks, do not report progress.
- chunks
- Yields:
- chunk
The same objects that iteration over
chunkswould yield.
Notes
This attempts to display as much progress as possible given the limitations of the iterables, assuming that sized iterables are also multi-pass (as is true of all built-in collections and lazy iterators). In detail, if
totalisNone:if
chunksand its elements are both sized,totalis computed from them and full progress is reported, andchunksmust be a multi-pass iterable.if
chunksis sized but its elements are not, a progress bar over the number of chunks is shown, andchunksmust be a multi-pass iterable.if
chunksis not sized, the progress bar just shows when updates occur.
If
totalisTrueor an integer,chunksneed not be sized, but its elements must be,chunksmust be a multi-pass iterable, and full progress is shown.If
totalisFalse,chunksand its elements need not be sized, and the progress bar just shows when updates occur.
- iter_item_chunks(items: Iterable[tuple[_K, _V]], desc: str | None = None, total: int | None = None, skip_scalar: bool = True) Generator[tuple[_K, _V], None, None]¶
Wrap iteration over chunks of items in a progress bar.
- Parameters:
- items
Iterable An iterable whose elements are (key, value) tuples, where the values are themselves iterable.
- desc
str, optional A user-friendly description for this progress bar; usually appears next to it. If not provided,
self.nameis used (which is not usually a user-friendly string, but may be appropriate for debug-level progress).- total
int, optional The total number of steps in this progress bar; defaults to the sum of the lengths of the chunks if this can be computed. If this is provided or
True, each element inchunksmust be sized butchunksitself need not be (and may be a single-pass iterable).- skip_scalar
bool, optional If
Trueand there are zero or one items, do not report progress.
- items
- Yields:
- chunk
The same 2-tuples that iteration over
itemswould yield.
Notes
This attempts to display as much progress as possible given the limitations of the iterables, assuming that sized iterables are also multi-pass (as is true of all built-in collections and lazy iterators). In detail, if
totalisNone:if
chunksand its values elements are both sized,totalis computed from them and full progress is reported, andchunksmust be a multi-pass iterable.if
chunksis sized but its value elements are not, a progress bar over the number of chunks is shown, andchunksmust be a multi-pass iterable.if
chunksis not sized, the progress bar just shows when updates occur.
If
totalisTrueor an integer,chunksneed not be sized, but its value elements must be,chunksmust be a multi-pass iterable, and full progress is shown.If
totalisFalse,chunksand its values elements need not be sized, and the progress bar just shows when updates occur.
- classmethod set_handler(handler: ProgressHandler | None) None¶
Set the (global) progress handler to the given instance.
This should only be called in very high-level code that can be reasonably confident that it will dominate its current process, e.g. at the initialization of a command-line script or Jupyter notebook.
- Parameters:
- handler
ProgressHandlerorNone Object that will handle all progress reporting. May be set to
Noneto disable progress reporting.
- handler
- wrap(iterable: Iterable[_T], desc: str | None = None, total: int | None = None, skip_scalar: bool = True) Generator[_T, None, None]¶
Iterate over an object while reporting progress.
- Parameters:
- iterable
Iterable An arbitrary Python iterable to iterate over.
- desc
str, optional A user-friendly description for this progress bar; usually appears next to it. If not provided,
self.nameis used (which is not usually a user-friendly string, but may be appropriate for debug-level progress).- total
int, optional The total number of steps in this progress bar. If not provided,
len(iterable)is used. If that does not work, whether the progress bar works at all is handler-defined, and hence this mode should not be relied upon.- skip_scalar
bool, optional If
Trueandtotalis zero or one, do not report progress.
- iterable
- Yields:
- element
The same objects that iteration over
iterablewould yield.