API Reference¶
All functions documented on this page are exported by the zoti_yaml
module.
Handlers¶
- class Project(keys: List[str] = [], pathvar: List[str] = [], ext: List[str] = ['.yaml', '.yml'], argfields: List[str] = ['zoti-args'], **kwargs)[source]¶
Handler for loading and containing a set of ZOTI-YAML modules. All modules are loaded relative to the roots specified by pathvar, in a similar fashion as UNIX path variables. The order of priority for resolving paths to module names is right-to-left.
- Parameters:
keys – list of keys to mark for storing positional metadata (see Syntax Reference)
pathvar – list of root paths where modules will be searched (see Syntax Reference)
ext – list of file extensions for searching module sources. Any file with another extension that specified here will be ignored.
argfields – list of keys for fields used as placholders for, e.g., argument exchange. These fields will be deleted from the output result.
- resolve_path(name) Path [source]¶
Return a global file path where the source file for module name is found. If none found returns FileNotFoundError.
- class Module(preamble={}, doc={})[source]¶
A ZOTI-YAML module wraps a document with metadata and a bunch of utilities used for convenient data access and manipulation.
The basic constructor requires the (possibly pre-stored) preamble and doc trees (see
to_dump()
).- name: str¶
- path: Path¶
- preamble: Dict¶
- doc: Dict¶
- classmethod from_zoml(stream, filepath: str, key_nodes: List = [])[source]¶
Module
constructor which incoprorates both file loader and parser.- Parameters:
stream – input stream (e.g., file or stdin)
filepath – mandatory identifier for source of input. Used in debug and error handling.
tool – optional identifier for tool downstream. Used in logging.
key_nodes – nodes whose children will be marked with positional info.
- map_doc(f, with_path=False, **kwargs)[source]¶
Functor on a Module document. Maps function f(n) on each node n in the document tree. If with_path is set to True, it expects function to be of form f(n, path) where path is this node’s path relative to the document root (see
TreePath
).’
- get(ref_path: Union[TreePath, PurePosixPath, str], strict=True)[source]¶
Returns an arbitrary node in the document tree vased on its path relative to the document root (see
TreePath
). The path is formed like:/key1/key2[index2]/key3[index3]/....
where
keyN
is the dictionary key of that node, respectivelyindexN
can be either the index postion of the node in a list, or the node in a list which has a fieldname: indexN
.The strict argument controls whether this method throws an exception or returns None if the path is not found.
OBS: it is the designer’s responsibility to ensure that no two nodes in a list share the same
name
value.
Document Tree Paths¶
- class TreePath(path: Union[str, PurePosixPath] = '')[source]¶
Simple structure used to reference subtrees/nodes using a sytax similar to:
{/path/to/node}
The
{path/to/node}
part is stored as a PurePosixPath, thus it can also be a relative path.- path: PurePosixPath¶
Position Helpers¶
- INFO¶
alias of _info
- POS¶
alias of _pos
- class Pos(line, column, ibegin=0, iend=-1, path=None, who=None)[source]¶
Container for positional information in a YAML file. Depends on the info from a PyYAML loader.
- line: int¶
line number
- column: int¶
column number
- ibegin: int¶
start index in the text file
- iend: int¶
end index in the text file
- path: str¶
location of the source file
- who: Optional[str]¶
string for bookkeeping the processing pipeline for this node
Exceptions¶
- exception ModuleError(what, module=None, path=None)[source]¶
Raised when some specific module metadata is missing or other reasons why a module cannot be loaded,
- exception SearchError(what, path=None, obj=None)[source]¶
Raised when a search based on a
zoti_yaml.core.TreePath
fails.