abjad.contextmanagers
Context manager. |
|
Filesystem state context manager. |
|
|
Forbid update context manager. |
Null context manager. |
|
Progress indicator context manager. |
|
Redirected streams context manager. |
|
Temporary directory context manager. |
|
Temporary directory change context manager. |
|
|
Timer context manager. |
- class abjad.contextmanagers.FilesystemState(keep=None, remove=None)[source]
Filesystem state context manager.
Gets asset paths to restore on exit.
Gets paths to remove on exit.
- keep
Gets asset paths to restore on exit.
Returns tuple.
- remove
Gets paths to remove on exit.
Returns tuple.
- class abjad.contextmanagers.ForbidUpdate(component: Component, *, update_on_exit: bool = False)[source]
Forbid update context manager.
>>> staff = abjad.Staff("c'8 d'8 ~ d'2 e'4") >>> with abjad.ForbidUpdate(component=staff): ... for note in staff[:]: ... pitch_1 = note.written_pitch ... pitch_2 = pitch_1 + abjad.NamedInterval("M3") ... pitches = [pitch_1, pitch_2] ... chord = abjad.Chord(pitches, note.written_duration) ... abjad.mutate.replace(note, chord) ...
>>> abjad.wf.is_wellformed(staff) True
>>> abjad.show(staff)
Gets component.
Is true when context manager should update offsets on exit.
- component
Gets component.
Set to component or none.
Returns component or none.
- update_on_exit
Is true when context manager should update offsets on exit.
- class abjad.contextmanagers.ProgressIndicator(message: str = '', *, do_not_print: bool = False, is_warning: bool = False, total: int = 0)[source]
Progress indicator context manager.
advance
()Advances the progress indicator's progress count.
Is true if progress indicator does not prints status.
Is true if progress indicator prints in red when its progress goes above zero.
Gets message of progress indicator.
Gets progress.
Gets total count.
- advance()[source]
Advances the progress indicator’s progress count. Overwrites the current terminal line with the progress indicators message and new count.
- do_not_print
Is true if progress indicator does not prints status.
- is_warning
Is true if progress indicator prints in red when its progress goes above zero.
- message
Gets message of progress indicator.
- progress
Gets progress.
- total
Gets total count.
- class abjad.contextmanagers.RedirectedStreams(stdout=None, stderr=None)[source]
Redirected streams context manager.
Captures stdout and stderr output.
>>> abjad.RedirectedStreams() <RedirectedStreams()>
>>> from io import StringIO >>> string_io = StringIO() >>> with abjad.RedirectedStreams(stdout=string_io): ... print("hello, world!") ... >>> result = string_io.getvalue() >>> string_io.close() >>> print(result) hello, world!
Gets stderr of context manager.
Gets stdout of context manager.
- stderr
Gets stderr of context manager.
- stdout
Gets stdout of context manager.
- class abjad.contextmanagers.TemporaryDirectory(parent_directory=None)[source]
Temporary directory context manager.
Gets parent directory.
Gets temporary directory.
- parent_directory
Gets parent directory.
- temporary_directory
Gets temporary directory.
- class abjad.contextmanagers.TemporaryDirectoryChange(directory=None, verbose=None)[source]
Temporary directory change context manager.
Gets temporary directory of context manager.
Gets original directory of context manager.
Is true if context manager prints verbose messages on entrance and exit.
- directory
Gets temporary directory of context manager.
- original_directory
Gets original directory of context manager.
- verbose
Is true if context manager prints verbose messages on entrance and exit.
- class abjad.contextmanagers.Timer(exit_message=None, enter_message=None, print_continuously_from_background=False, verbose=True)[source]
Timer context manager.
>>> timer = abjad.Timer() >>> with timer: ... for _ in range(1000000): ... x = 1 + 1 ... >>> timer.elapsed_time 0.025415897369384766
The timer can also be accessed from within the
with
block:>>> with abjad.Timer() as timer: ... for _ in range(5): ... for _ in range(1000000): ... x = 1 + 1 ... print(timer.elapsed_time) ... 0.025332927703857422 0.05059981346130371 0.07599377632141113 0.10130476951599121 0.1265699863433838
Timers can be reused between
with
blocks. They will reset their clock on entering anywith
block.Elapsed time.
Timer enter message.
Timer exit message.
Is true when timer should print continuously from background.
Start time of timer.
Stop time of timer.
Gets total time message.
Is true if timer should print messages.
- elapsed_time
Elapsed time.
- enter_message
Timer enter message.
- exit_message
Timer exit message.
- print_continuously_from_background
Is true when timer should print continuously from background.
- start_time
Start time of timer.
Returns time.
- stop_time
Stop time of timer.
Returns time.
- total_time_message
Gets total time message.
Truncated to the nearest second.
- verbose
Is true if timer should print messages.