abjad.contextmanagers

abjad.contextmanagers.ContextManager()

Context manager.

abjad.contextmanagers.FilesystemState([...])

Filesystem state context manager.

abjad.contextmanagers.ForbidUpdate(component, *)

Forbid update context manager.

abjad.contextmanagers.NullContextManager()

Null context manager.

abjad.contextmanagers.ProgressIndicator([...])

Progress indicator context manager.

abjad.contextmanagers.RedirectedStreams([...])

Redirected streams context manager.

abjad.contextmanagers.TemporaryDirectory([...])

Temporary directory context manager.

abjad.contextmanagers.TemporaryDirectoryChange([...])

Temporary directory change context manager.

abjad.contextmanagers.Timer([exit_message, ...])

Timer context manager.

class abjad.contextmanagers.ContextManager[source]

Context manager.

class abjad.contextmanagers.FilesystemState(keep=None, remove=None)[source]

Filesystem state context manager.

keep

Gets asset paths to restore on exit.

remove

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)  

component

Gets component.

update_on_exit

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.NullContextManager[source]

Null context manager.

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.

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.

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!

stderr

Gets stderr of context manager.

stdout

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.

parent_directory

Gets parent directory.

temporary_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.

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.

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 any with block.

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.

stop_time

Stop time of timer.

total_time_message

Gets total time message.

verbose

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.