makeprov.core
Functions
|
Recursively build a target and its prerequisites. |
|
Build all concrete targets that have no dependents. |
|
Add dunder methods based on the fields defined in the class. |
|
Log the steps required to build |
|
Log the rule used for each target in build order. |
|
Return an object to identify dataclass fields. |
|
Write or propagate the most recent provenance buffer. |
|
Get type arguments with all substitutions performed. |
|
Get the unsubscripted version of a type. |
|
Return type hints for an object. |
|
Return registered rule names in alphabetical order. |
|
Return concrete targets produced by non-pattern rules. |
|
Determine whether outputs are stale relative to dependencies. |
Create a fresh session with isolated registries and buffers. |
|
|
Create a Parser instance to parse "format". |
|
Return the execution order for building a target. |
|
Resolve a target to its registered rule and parameters. |
|
Return concrete targets that are not dependencies of other rules. |
|
Decorate a function as a build rule with automatic provenance. |
|
Create a provenance buffer to batch writes. |
|
Render the dependency graph for |
Classes
|
Special type indicating an unconstrained type. |
|
Input wrapper that lazily downloads and records source metadata. |
|
Input directory that tracks files declared within it. |
|
Marker for input paths where |
|
Output directory that tracks files declared within it. |
|
Marker for output paths where |
|
Encapsulate a format string that may be used to parse other strings. |
|
PurePath subclass that can make system calls. |
|
|
|
Runtime configuration for provenance generation. |
|
Provide JSON-LD serialization helpers for dataclasses. |
|
Minimal description of a build rule. |
|
In-memory registries and buffers for a makeprov run. |
|
The year, month and day arguments are required. |
|
Fixed offset from UTC implementation of tzinfo. |
- class makeprov.core.Rule(name, func, deps=<factory>, outputs=<factory>, dep_templates=<factory>, out_templates=<factory>, out_parsers=<factory>, phony=False)
Bases:
objectMinimal description of a build rule.
Rules capture the callable to execute, their declared dependencies and outputs, and optional parse templates for parameterized targets. Thin registry helpers in this module use these objects to resolve targets, explain the execution plan, and run builds.
- class makeprov.core.Session(rules_by_target=<factory>, rules_by_name=<factory>, pattern_rules=<factory>, commands=<factory>, prov_buffers=<factory>)
Bases:
objectIn-memory registries and buffers for a makeprov run.
- makeprov.core.build(target, _seen=None, *, session=None, **kwargs)
Recursively build a target and its prerequisites.
- makeprov.core.build_all(*, session=None)
Build all concrete targets that have no dependents.
- makeprov.core.dry_run_build(target, *, session=None)
Log the steps required to build
targetwithout executing rules.- Return type:
- makeprov.core.explain(target, *, session=None)
Log the rule used for each target in build order.
- Return type:
- makeprov.core.flush_prov_buffer(*, prov_path=None, config=None, fmt=None, frame=None, context=None, context_url=None, session=None, label=None)
Write or propagate the most recent provenance buffer.
Returns the merged
Provobject for the flushed buffer. When a parent buffer exists, the merged provenance is appended to it for further aggregation. Whenprov_pathis provided, the merged provenance is written even if a parent buffer exists. Without a parent buffer, the merged provenance is written to disk using the provided configuration (falling back to the process-wide configuration viamakeprov.ProvenanceConfig).
- makeprov.core.list_rules(*, session=None)
Return registered rule names in alphabetical order.
- makeprov.core.list_targets(*, session=None)
Return concrete targets produced by non-pattern rules.
- makeprov.core.needs_update(outputs, deps)
Determine whether outputs are stale relative to dependencies.
- Parameters:
- Returns:
Trueif any output is missing or older than a dependency; the absence of dependencies returnsFalseto avoid unnecessary rebuilds.- Return type:
Examples
from makeprov.core import needs_update if needs_update(["data/output.txt"], ["data/input.txt"]): regenerate()
- makeprov.core.new_session()
Create a fresh session with isolated registries and buffers.
- Return type:
- makeprov.core.plan(target, *, session=None)
Return the execution order for building a target.
The plan is derived using
resolve_target()for each dependency, ensuring concrete and templated rules are treated uniformly.
- makeprov.core.resolve_target(target, *, session=None)
Resolve a target to its registered rule and parameters.
Concrete targets are looked up directly in
RULES_BY_TARGET. Pattern rules are attempted in registration order usingparsetemplates.
- makeprov.core.root_targets(*, session=None)
Return concrete targets that are not dependencies of other rules.
- makeprov.core.rule(*, name=None, phony=False, base_iri=None, prov_dir=None, prov_path=None, force=None, dry_run=None, out_fmt=None, frame=None, config=None, context=None, merge=None, session=None)
Decorate a function as a build rule with automatic provenance.
- Parameters:
name (
str|None) – Logical name for the rule; defaults to the function name.phony (
bool) – WhenTrue, do not require anOutPathparameter and always execute the wrapped function regardless of timestamps. Useful for meta-rules such as aggregators or reporting commands.base_iri (
str|None) – Base IRI for provenance identifiers; overrides global configuration when provided.prov_dir (
str|None) – Directory where provenance documents are saved.prov_path (
str|None) – Explicit path for the provenance file; overridesprov_dirwhen set.force (
bool|None) – WhenTrue, always run the rule regardless of timestamps.dry_run (
bool|None) – WhenTrue, log activity without executing the wrapped function.out_fmt (
Optional[Literal['json','trig']]) – Output format for provenance files ("json"or"trig").frame (
Optional[Literal['provenance','results']]) – Which structure to make primary subject of jsonld or trig named graph. Options: “provenance” or “results”.config (
ProvenanceConfig|None) – Configuration object to use instead of the process-wide configuration returned bymakeprov.ProvenanceConfig.context (
bool|None) – Whether to embed JSON-LD context in output when writing provenance.merge (
bool|None) – WhenTrue, buffer provenance for this rule and any nested rule calls, emitting a single merged document. Defaults to the configured merge behavior.session (
Session|None) – Registry and buffer container to use instead of the process-wide default session. Passing a dedicated session isolates rules, commands, and provenance buffers from other runs.
- Returns:
A decorator that wraps the target function and registers it as a rule when outputs are discoverable from annotations. Templated
InPathorOutPathdefaults usingstr.formatstyle placeholders (e.g."data/{sample:d}.txt") register as pattern rules and are resolved dynamically for matching targets.- Return type:
Callable
Examples
Annotate parameters with
InPathandOutPathto let the decorator infer dependencies:from makeprov import InPath, OutPath, rule @rule() def uppercase(src: InPath, dst: OutPath): dst.write_text(src.read_text().upper()) uppercase("data/input.txt", "data/output.txt")
- makeprov.core.start_prov_buffer(*, session=None)
Create a provenance buffer to batch writes.
Buffers capture provenance from multiple rule invocations and emit a single merged document when flushed. Callers should prefer one top-level buffer per workflow run; nested buffers are supported for backward compatibility but are avoided by the public APIs to keep merge semantics predictable.
- Return type: