zensols.latidx package

Submodules

zensols.latidx.app module

Parse and index Latex files.

class zensols.latidx.app.Application(indexer, log_config)[source]

Bases: object

Parse and index Latex files.

__init__(indexer, log_config)
dump_commands(tex_path, output_format=_Format.txt, name=None)[source]

List commands.

Parameters:
  • tex_path (str) – a path separated (‘:’ on Linux) list of files or directories

  • output_format (_Format) – the output format

  • name (str) – the command to output; defaults to all

dump_dependencies(tex_path, source=None, output_format=_Format.txt)[source]

List dependencies.

Parameters:
  • tex_path (str) – a path separated (‘:’ on Linux) list of files or directories

  • source (str) – the source latex file dependency to print

  • output_format (_Format) – the output format

dump_files(tex_path, output_format=_Format.txt)[source]

List files and their contents.

Parameters:
  • tex_path (str) – a path separated (‘:’ on Linux) list of files or directories

  • output_format (_Format) – the output format

indexer: LatexIndexer

The file indexer.

log_config: LogConfigurator

Used to update logging levels based on the ran action.

class zensols.latidx.app.PrototypeApplication(app)[source]

Bases: object

CLI_META = {'is_usage_visible': False}
__init__(app)
app: Application
proto(run=4)[source]

Prototype test.

zensols.latidx.cli module

Command line entry point to the application.

class zensols.latidx.cli.ApplicationFactory(*args, **kwargs)[source]

Bases: ApplicationFactory

__init__(*args, **kwargs)[source]
classmethod get_indexer()[source]

Get the indexer.

Return type:

LatexIndexer

zensols.latidx.cli.main(args=['/Users/landes/opt/lib/python/util/bin/sphinx-build', '-M', 'html', '/Users/landes/view/util/latidx/target/doc/src', '/Users/landes/view/util/latidx/target/doc/build'], **kwargs)[source]
Return type:

ActionResult

zensols.latidx.domain module

Application domain classes.

class zensols.latidx.domain.LatexObject[source]

Bases: PersistableContainer, Dictable

Any Latex data structure that is parsed, or composed of, parsed Latex.

__init__()
class zensols.latidx.domain.LatexSpannedObject[source]

Bases: LatexObject

Any Latex data structure that is parsed text from a Latex file.

__init__()
property name: str

The name of the object or text that makes it unique.

property span: int

The absolute 0-index character offset of the Latex statement.

exception zensols.latidx.domain.LatidxError[source]

Bases: APIError

Thrown for any application level error.

__module__ = 'zensols.latidx.domain'
class zensols.latidx.domain.NewCommand(newcommand_node, macro_node, arg_spec_nodes, body_node, comment_nodes, definition)[source]

Bases: LatexSpannedObject

A parsed macro definition using \{provide,new,renew}command.

__init__(newcommand_node, macro_node, arg_spec_nodes, body_node, comment_nodes, definition)
property arg_spec: str

The argument specification, which includes the argument count.

arg_spec_nodes: Tuple[LatexNode, ...]

The node containing the package import options (if present).

property body: str

The body of the macro definition.

body_node: LatexGroupNode

The node with the name of the package to be imported.

property comment: str

The concatenated text from the parsed comment_nodes.

comment_nodes: Tuple[LatexCommentNode, ...]

Any comment nodes that preceeded the newcommand statement.

definition: str

The string definition of the command.

macro_node: LatexMacroNode

The node containing the macro.

property macro_offset: int
newcommand_node: LatexMacroNode

The \newcommand node.

write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Write this instance as either a Writable or as a Dictable. If class attribute _DICTABLE_WRITABLE_DESCENDANTS is set as True, then use the write() method on children instead of writing the generated dictionary. Otherwise, write this instance by first creating a dict recursively using asdict(), then formatting the output.

If the attribute _DICTABLE_WRITE_EXCLUDES is set, those attributes are removed from what is written in the write() method.

Note that this attribute will need to be set in all descendants in the instance hierarchy since writing the object instance graph is done recursively.

Parameters:
  • depth (int) – the starting indentation depth

  • writer (TextIOBase) – the writer to dump the content of this writable

exception zensols.latidx.domain.ParseError(path, msg)[source]

Bases: LatidxError

Raised for Latex file parsing errors.

__annotations__ = {}
__init__(path, msg)[source]
__module__ = 'zensols.latidx.domain'
class zensols.latidx.domain.UsePackage(macro_node, options_node, name_node)[source]

Bases: LatexSpannedObject

A parsed use of a Latex \usepackage{<name>}.

__init__(macro_node, options_node, name_node)
macro_node: LatexMacroNode

The node containing the macro.

name_node: LatexCharsNode

The node with the name of the package to be imported.

options_node: LatexCharsNode

The node containing the package import options (if present).

zensols.latidx.file module

Classes that represent text with parsable Latex content.

class zensols.latidx.file.LatexFile(path)[source]

Bases: LatexSpannedObject

A Latex file (.tex, .sty, etc) with parsed artifacts.

__init__(path)
property content: str

The content of the Latex file path.

property db: LatexContextDb
property failures: Tuple[Failure, ...]

Write parse failures.

property newcommands: Dict[str, NewCommand]

Get the usepackage declarations in the file.

path: Path

The parsed latex .tex or .sty file.

property usepackages: Dict[str, UsePackage]

Get the usepackage declarations in the file.

property walker: LatexWalker

Iterates over parsed Latex artifacts (such as macros).

write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, include_path=True)[source]

Write this instance as either a Writable or as a Dictable. If class attribute _DICTABLE_WRITABLE_DESCENDANTS is set as True, then use the write() method on children instead of writing the generated dictionary. Otherwise, write this instance by first creating a dict recursively using asdict(), then formatting the output.

If the attribute _DICTABLE_WRITE_EXCLUDES is set, those attributes are removed from what is written in the write() method.

Note that this attribute will need to be set in all descendants in the instance hierarchy since writing the object instance graph is done recursively.

Parameters:
  • depth (int) – the starting indentation depth

  • writer (TextIOBase) – the writer to dump the content of this writable

class zensols.latidx.file.NewCommandLocation(command, file)[source]

Bases: LatexSpannedObject

A pairing of commands and the files they live in.

__init__(command, file)
command: NewCommand

The command foiund in file.

file: LatexFile

The file that contains command.

write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Write this instance as either a Writable or as a Dictable. If class attribute _DICTABLE_WRITABLE_DESCENDANTS is set as True, then use the write() method on children instead of writing the generated dictionary. Otherwise, write this instance by first creating a dict recursively using asdict(), then formatting the output.

If the attribute _DICTABLE_WRITE_EXCLUDES is set, those attributes are removed from what is written in the write() method.

Note that this attribute will need to be set in all descendants in the instance hierarchy since writing the object instance graph is done recursively.

Parameters:
  • depth (int) – the starting indentation depth

  • writer (TextIOBase) – the writer to dump the content of this writable

zensols.latidx.index module

Classes used to parse and index LaTeX files.

class zensols.latidx.index.LatexDependency(source, targets)[source]

Bases: LatexObject

An import relationship given by Latex usepackage.

__init__(source, targets)
property base_dir: Path
get_files()[source]

Return all target files recursively.

Return type:

Iterable[LatexFile]

property orphans: Tuple[str, ...]

The target Latex packages that were imported by not found. This will typically include installed base packages (i.e. hyperref).

source: Union[LatexFile, str]

“The source file that contains the import statement or the string root if the root of the aggregation of dependnecies.

targets: Optional[Dict[str, LatexDependency]]

The imported files from source.

tree(include_relative_path=False)[source]
Return type:

Dict[str, Any]

write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, include_relative_path=False, base_dir=None)[source]

Write this instance as either a Writable or as a Dictable. If class attribute _DICTABLE_WRITABLE_DESCENDANTS is set as True, then use the write() method on children instead of writing the generated dictionary. Otherwise, write this instance by first creating a dict recursively using asdict(), then formatting the output.

If the attribute _DICTABLE_WRITE_EXCLUDES is set, those attributes are removed from what is written in the write() method.

Note that this attribute will need to be set in all descendants in the instance hierarchy since writing the object instance graph is done recursively.

Parameters:
  • depth (int) – the starting indentation depth

  • writer (TextIOBase) – the writer to dump the content of this writable

class zensols.latidx.index.LatexIndexer(candidate_extensions, recurse_dirs)[source]

Bases: Dictable

Indexes and parses Latex files. Candidate files refer to files we actually consider for parsing.

__init__(candidate_extensions, recurse_dirs)
candidate_extensions: Set[str]

The files extensions of files to parse (i.e. .tex, .sty).

create_project(paths)[source]

Create a latex project from the file paths of .tex and .sty files.

Return type:

LatexProject

recurse_dirs: bool

Whether to recursively descend directories in search for candidates.

class zensols.latidx.index.LatexProject(files)[source]

Bases: LatexObject, Primeable

A collection of dependencies of a set of files used in a LaTeX compliation process.

__init__(files)
property command_locations: Tuple[NewCommandLocation, ...]

All commands across all Latex files.

property command_locations_by_name: Dict[str, NewCommandLocation]

All commands across all Latex files by command name.

property dependencies: Dict[str, Dict[str, Any]]

A nested directory of string file names and their recursive usepackage includes as children.

property dependency_files: Tuple[LatexFile, ...]

The parsed latex files in the project.

files: Tuple[Union[LatexFile, Path], ...]

The files to parse or those that have already been parsed. These are all LatexFile instances after this object is instantiated.

property files_by_name: Dict[str, LatexFile]

The files as key names and LatexFile instances as values.

prime()[source]
write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Write this instance as either a Writable or as a Dictable. If class attribute _DICTABLE_WRITABLE_DESCENDANTS is set as True, then use the write() method on children instead of writing the generated dictionary. Otherwise, write this instance by first creating a dict recursively using asdict(), then formatting the output.

If the attribute _DICTABLE_WRITE_EXCLUDES is set, those attributes are removed from what is written in the write() method.

Note that this attribute will need to be set in all descendants in the instance hierarchy since writing the object instance graph is done recursively.

Parameters:
  • depth (int) – the starting indentation depth

  • writer (TextIOBase) – the writer to dump the content of this writable

write_command_locations(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]
write_files(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Module contents