research_helpers.build
This module covers the registry of generated artefacts and the drift checks over them, as well as the Document that groups a manuscript’s registries. See Adding a generated table for the end-to-end workflow, and several documents for an example of a project with more than one manuscript.
- class research_helpers.build.Kind(name, suffix, directory, label_prefix, setting, reference, block, float_is_generated, binary=False)[source]
Bases:
objectA class of generated artefact (and how the paper refers to it).
- Parameters:
- hand_written(paper)[source]
Return the floats the paper carries with no emitter behind them, keyed by label.
Where the emitter produces the float itself, any literal float is hand-written. Where it produces only the contents, a float counts as hand-written when nothing inside it is pulled in from this kind’s directory.
- class research_helpers.build.Artefact(label, emitter, description='', metadata=<factory>)[source]
Bases:
objectA registered artefact.
- class research_helpers.build.Drift(stale, missing, ungenerated)[source]
Bases:
NamedTupleThe three ways a paper and its emitters can disagree.
Checked without a manuscript, in a repository that publishes a document’s floats but not its source, ‘missing’ is None.
- class research_helpers.build.Registry(kind)[source]
Bases:
objectThe emitters for one kind of artefact and the checks over them.
- Parameters:
kind (Kind)
- register(label, *, description='', **metadata)[source]
Register the decorated function as the emitter for ‘label’.
- Parameters:
- Return type:
Callable[[TypeVar(EmitterT, bound= Callable[[], str | bytes])],TypeVar(EmitterT, bound= Callable[[], str | bytes])]- Returns:
The decorator, which returns the emitter unchanged so it stays directly callable.
- Raises:
ValueError – if the label is already registered or lacks the kind’s prefix.
- build_dir(directory=None)[source]
Return where artefacts are built, defaulting to the project’s build directory.
- install_dir(destination=None)[source]
Return where the paper reads artefacts from, defaulting to the project’s setting.
- write_all(directory=None)[source]
Build every artefact into ‘directory’, one file per label, and return the paths.
- install(destination=None, source=None)[source]
Copy built artefacts to where the paper reads them.
- Parameters:
- Return type:
- Returns:
The paths written.
- Raises:
FileNotFoundError – if an artefact has not been built.
- drift(paper=None, destination=None, *, manuscript=None)[source]
Compare what the paper carries against what the emitters produce.
- Parameters:
paper (
Path|str|None, default:None) – the manuscript. Defaults to the project’s ‘paper.main’.destination (
Path|str|None, default:None) – where the paper reads artefacts from. Defaults to the project’s setting.manuscript (
bool|None, default:None) – whether there is a manuscript to read. Defaults to true if ‘paper’ is given, and otherwise to the project’s ‘paper.manuscript’.
- Return type:
- Returns:
The three ways they disagree; falsy when they do not.
- Raises:
FileNotFoundError – if a manuscript is expected and is not there.
ValueError – if ‘paper’ is given while ‘manuscript’ is false.
- class research_helpers.build.Document(name, *registries, prose=None, settings=None)[source]
Bases:
objectOne manuscript, the registries of what it carries, and the checks over them.
A project with one paper can use its registries directly. A project with a second document (a technical note, a supplement, the second half of a split paper) gives each document its own registries and a ‘Document’ class, so that each is built into its own directories and checked against its own manuscript:
paper = Document(‘paper’, tables, figures, prose=prose) note = Document(‘note’, note_tables, note_figures, prose=prose)
A float both documents carry is registered in both documents’ registries. The decorator returns the emitter unchanged, so it stacks. A prose registry may be shared, since each document checks only the entries it prints.
- Parameters:
name (str)
registries (Registry)
prose (ProseRegistry | None)
settings (PaperSettings | None)
- property settings: PaperSettings
Return where the document lives.
- manuscript()[source]
Return the manuscript.
- Raises:
FileNotFoundError – if it does not exist, or the document is configured without one.
- Return type:
- drift()[source]
Compare the manuscript against every registry by kind.
A document configured without a manuscript has each artefact compared with its installed copy instead (see ‘Drift’).
- check_prose()[source]
Check the numbers this document states in prose.
- Return type:
- Returns:
What the check found, or None if the document has no prose registry or no manuscript.
- report(drift, prose=None)[source]
Return a description of everything that drifted, and of anything left unchecked.
- Return type:
- Parameters:
prose (ProseCheck | None)