abjad.io

abjad.io.compare_files(path_1, path_2)

Compares file path_1 to file path_2.

abjad.io.count_function_calls(argument, *[, ...])

Counts function calls required to execute argument.

abjad.io.execute_file([path, attribute_names])

Executes file path.

abjad.io.execute_string(string, *[, ...])

Executes string.

abjad.io.find_executable(name, *[, flags])

Finds executable name.

abjad.io.graph(graphable[, format_, layout, ...])

Graphs argument.

abjad.io.make_subprocess(command)

Makes Popen instance.

abjad.io.open_file(file_path, *[, ...])

Opens file_path.

abjad.io.open_last_log()

Opens LilyPond log file in operating system-specific text editor.

abjad.io.profile(string, *[, ...])

Profiles string.

abjad.io.run_command(command)

Runs command in subprocess.

abjad.io.run_lilypond(ly_path, *[, flags, ...])

Runs LilyPond on ly_path.

abjad.io.show(illustrable, *[, flags, ...])

Shows illustrable.

abjad.io.spawn_subprocess(command)

Spawns subprocess and runs command.

abjad.io.AbjadGrapher(graphable[, format_, ...])

Abjad grapher.

abjad.io.Illustrator(illustrable, *[, ...])

Illustrator.

abjad.io.LilyPondIO(illustrable, *[, flags, ...])

LilyPond IO.

abjad.io.Player(illustrable, *[, flags, ...])

Player.

abjad.io.compare_files(path_1, path_2)[source]

Compares file path_1 to file path_2.

For all file types:

* Performs line-by-line comparison
* Discards blank lines

For LilyPond files, additionally:

* Discards any LilyPond version statements
* Discards any lines beginning with ``%``

Returns true when files compare the same and false when files compare differently.

abjad.io.count_function_calls(argument: str, *, global_context: dict | None = None, local_context: dict | None = None, only_one_time: bool = False) int[source]

Counts function calls required to execute argument.

abjad.io.execute_file(path: str | None = None, *, attribute_names: tuple[str] | None = None) tuple[str] | None[source]

Executes file path.

Returns attribute_names from file.

abjad.io.execute_string(string: str, *, attribute_names: tuple[str] | None = None, local_namespace: dict | None = None) tuple | None[source]

Executes string.

Returns attribute_names from executed string.

>>> string = "foo = 23"
>>> attribute_names = ("foo", "bar")
>>> abjad.io.execute_string(
...     string,
...     attribute_names=attribute_names,
... )
(23, None)
abjad.io.find_executable(name: str, *, flags: int = 1) list[Path][source]

Finds executable name.

Similar to Unix which command.

Returns list of zero or more full paths to name.

abjad.io.graph(graphable, format_='pdf', layout='dot', return_timing=False, **keywords) tuple[float, float] | None[source]

Graphs argument.

Opens image in default image viewer.

Graphs staff:

>>> staff = abjad.Staff("c'4 d' e' f'")
>>> abjad.graph(staff)  

Graphs rhythm tree:

>>> rtm_syntax = "(3 ((2 (2 1)) 2))"
>>> parser = abjad.rhythmtrees.RhythmTreeParser()
>>> rhythm_tree = parser(rtm_syntax)[0]
>>> abjad.graph(rhythm_tree)  
abjad.io.make_subprocess(command: str) Popen[source]

Makes Popen instance.

Redirects stderr to stdout.

Defined equal to:

process = subprocess.Popen(
    command,
    shell=True,
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT,
)
abjad.io.open_file(file_path: str, *, application: str | None = None, line_number: int | None = None, test: bool = False)[source]

Opens file_path.

Uses application when application is not none.

Uses Abjad configuration file text_editor when application is none.

Takes best guess at operating system-specific file opener when both application and Abjad configuration file text_editor are none.

Respects line_number when file_path can be opened with text editor.

abjad.io.open_last_log() None[source]

Opens LilyPond log file in operating system-specific text editor.

abjad.io.profile(string: str, *, do_not_strip_dirs: bool = False, global_context: dict | None = None, line_count: int = 12, local_context: dict | None = None, print_callers: bool = False, print_callees: bool = False, sort_by: str = 'cumulative') str[source]

Profiles string.

Wraps Python’s built-in cProfile module. Set sort_by to "cumulative", "time", "calls". See the Python documentation for more information.

>>> string = 'abjad.Staff("c8 c8 c8 c8 c8 c8 c8 c8")'
>>> result = abjad.io.profile(string, global_context=globals())
abjad.io.run_command(command: str) list[str][source]

Runs command in subprocess.

Returns list of strings read from subprocess stdout.

abjad.io.run_lilypond(ly_path: str, *, flags: str = '', lilypond_log_file_path: Path | None = None) int[source]

Runs LilyPond on ly_path.

Writes redirected output of Unix date to top line of LilyPond log file.

Then appends redirected output of LilyPond output to the LilyPond log file.

abjad.io.show(illustrable, *, flags: str = '', return_timing: bool = False, **keywords)[source]

Shows illustrable.

Makes LilyPond input files and output PDF.

Writes LilyPond input file and output PDF to Abjad output directory.

Opens output PDF.

Returns none when return_timing is false.

Returns pair of abjad_formatting_time and lilypond_rendering_time when return_timing is true.

Shows note:

>>> note = abjad.Note("c'4")
>>> abjad.show(note)  
abjad.io.spawn_subprocess(command: str) int[source]

Spawns subprocess and runs command.

The function is basically a reimplementation of the deprecated os.system() using Python’s subprocess module.

Redirects stderr to stdout.

class abjad.io.AbjadGrapher(graphable, format_='pdf', layout='dot')[source]

Abjad grapher.

get_output_directory()

Gets output directory.

open_output_path(output_path)

Open output_path.

overridden get_output_directory() Path[source]

Gets output directory.

overridden open_output_path(output_path)[source]

Open output_path.

class abjad.io.Illustrator(illustrable, *, flags=None, output_directory=None, render_prefix=None, should_copy_stylesheets=False, should_open=True, should_persist_log=True, string=None, **keywords)[source]

Illustrator.

get_openable_paths(output_paths)

Gets openable paths.

overridden get_openable_paths(output_paths) Iterator[Path][source]

Gets openable paths.

class abjad.io.LilyPondIO(illustrable, *, flags=None, output_directory=None, render_prefix=None, should_copy_stylesheets=False, should_open=True, should_persist_log=True, string=None, **keywords)[source]

LilyPond IO.

copy_stylesheets(render_directory)

Copies stylesheets.

get_lilypond_path()

Gets LilyPond path.

get_openable_paths(output_paths)

Gets openable paths.

get_output_directory()

Gets output directory.

get_render_command(input_path, lilypond_path)

Gets render command.

get_render_directory()

Gets render directory.

get_render_prefix(string)

Gets render prefix.

get_string()

Gets string.

get_stylesheets_directories()

Gets stylesheets directories.

migrate_assets(render_prefix, ...)

Migrates assets.

open_output_path(output_path)

Opens output_path.

persist_log(string, input_path)

Persists log string to input_path.

persist_string(string, input_path)

Persists string to input_path.

run_command(command)

Runs command.

copy_stylesheets(render_directory)[source]

Copies stylesheets.

get_lilypond_path()[source]

Gets LilyPond path.

get_openable_paths(output_paths: Iterable[Path]) Iterator[Path][source]

Gets openable paths.

get_output_directory() Path[source]

Gets output directory.

get_render_command(input_path, lilypond_path) str[source]

Gets render command.

get_render_directory()[source]

Gets render directory.

get_render_prefix(string) str[source]

Gets render prefix.

get_string() str[source]

Gets string.

get_stylesheets_directories() list[Path][source]

Gets stylesheets directories.

migrate_assets(render_prefix, render_directory, output_directory) Sequence[Path][source]

Migrates assets.

open_output_path(output_path)[source]

Opens output_path.

persist_log(string, input_path)[source]

Persists log string to input_path.

persist_string(string, input_path)[source]

Persists string to input_path.

run_command(command)[source]

Runs command.

class abjad.io.Player(illustrable, *, flags=None, output_directory=None, render_prefix=None, should_copy_stylesheets=False, should_open=True, should_persist_log=True, string=None, **keywords)[source]

Player.

get_openable_paths(output_paths)

Gets openable paths.

get_string()

Gets string.

overridden get_openable_paths(output_paths) Iterator[Path][source]

Gets openable paths.

overridden get_string() str[source]

Gets string.