makeprov.prov
Functions
|
Bind a document-level context to a node and rebuild its term aliases. |
|
Add dunder methods based on the fields defined in the class. |
|
Deep copy operation on arbitrary Python objects. |
|
Return an object to identify dataclass fields. |
|
Load the built-in profiles, preceded by any user-supplied ones. |
|
Normalize a package name according to PEP 503 rules. |
|
Extract package metadata for provenance enrichment. |
|
Each part of a URL, e.g. the path info, the query, etc., has a different set of reserved characters that must be quoted. |
|
Match a git remote against the known forges. |
|
Decide how a document's identifiers are minted. |
Whether the checkout has uncommitted changes. |
Classes
|
|
|
|
|
Special type indicating an unconstrained type. |
|
A reference to an entity a run consumed or produced. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Mints the identifiers for one provenance document. |
|
PurePath subclass that can make system calls. |
|
|
|
Prospective structure for one rule: its name and the rules it needs. |
|
The recipe an activity carried out, distinct from whoever ran it. |
|
|
|
|
|
Provide JSON-LD serialization helpers for dataclasses. |
|
The year, month and day arguments are required. |
|
Fixed offset from UTC implementation of tzinfo. |
Exceptions
Raised when a rule's provenance record could not be written. |
|
Raised when a declared output could not be resolved to a real artifact. |
- class makeprov.prov.ActivityNode(id, type, startedAtTime=None, endedAtTime=None, duration=None, wasAssociatedWith=None, qualifiedAssociation=None, used=None, generated=None, comment=None)
Bases:
BaseNode
- class makeprov.prov.AgentNode(id, type, label=None, hasVersion=None, source=None, operatingSystem=None)
Bases:
BaseNode
- class makeprov.prov.EnvNode(id, type, label='Python environment', title=None, hasVersion=None, requires=None, resolved=None, wasDerivedFrom=None)
Bases:
BaseNode
- class makeprov.prov.FileEntity(id, type, format=None, extent=None, modified=None, identifier=None, sha256=None, wasGeneratedBy=None)
Bases:
BaseNode
- class makeprov.prov.GraphEntity(id, type, wasGeneratedBy=None, wasAttributedTo=None, generatedAtTime=None)
Bases:
BaseNode
- class makeprov.prov.IriMinter(base_iri, prefix, pinned, file_segment='', repo_root=None)
Bases:
objectMints the identifiers for one provenance document.
Holds the base-IRI policy shared by the decorator API and the Snakemake bridge, so both name things the same way.
- class makeprov.prov.PlanGraph(rule, requires=())
Bases:
objectProspective structure for one rule: its name and the rules it needs.
Kept separate from the retrospective record so a document can state what the workflow is without asserting that any of it ran.
- class makeprov.prov.PlanNode(id, type, label=None, hasVersion=None, source=None, requires=None)
Bases:
BaseNodeThe recipe an activity carried out, distinct from whoever ran it.
PROV separates the plan from the agent executing it. The script at a given commit is the plan; the Python runtime and the person invoking it are agents. Keeping them apart is what makes the graph mappable onto Workflow Run RO-Crate, whose
instrumentandagentare distinct slots.
- class makeprov.prov.Prov(base_iri, name, provenance, results, context=<factory>)
Bases:
object- classmethod create(base_iri, name, run_id, t0, t1, inputs, outputs, results, success=True, metadata=None, activity_id=None, parent_id=None, record_user=False, record_environment=False, forge_profiles=None, plan_graph=None, origin=None, revision=None)
Assemble a provenance graph from rule execution details.
- Parameters:
name (
str) – Logical rule name.run_id (
str) – Unique identifier for this run, typically timestamp-based.t0 (
datetime) – Start time of the rule execution.t1 (
datetime) – End time of the rule execution.inputs (
list[ArtifactRef]) – Entities consumed by the rule. Local refs are hashed and stat-ed; external refs are cited by IRI.outputs (
list[ArtifactRef]) – Entities produced by the rule.results (
list[RDFMixin]) – Optional result graphs to embed alongside provenance records.success (
bool) – Whether the rule completed successfully.record_user (
bool) – Record the invoking user fromgit configas aschema:Personagent. Off by default, since provenance documents are routinely committed and published.record_environment (
bool) – Also record retrospective environment evidence: the distributions this run actually imported (pinned to exact versions, unlike the declaredrequiresrange specs), and a citation of any lockfile found (uv.lock,poetry.lock,Pipfile.lock,pdm.lock,pylock.toml). Off by default: a full dependency snapshot adds real document weight most rules don’t need.origin (
str|None) – Reuse an already-looked-upgit config --get remote.origin.urlinstead of running it again, e.g. when a caller mintedactivity_idbeforehand.revision (
str|None) – Reuse an already-looked-upgit rev-parse HEADinstead of running it again.
- Returns:
A populated
Provinstance ready for serialization.- Return type:
Examples
prov = Prov.create( base_iri=None, name="uppercase", run_id="20240101T120000-1a2b3c4d", t0=start, t1=end, inputs=[ArtifactRef.local("input.txt")], outputs=[ArtifactRef.local("output.txt")], results=[], )
- classmethod merge(provs)
Combine multiple provenance documents into one.
- Parameters:
- Returns:
A new object containing combined provenance and results from all inputs.
- Return type:
Examples
merged = Prov.merge([prov_a, prov_b])
- results: tuple[GraphEntity, list[RDFMixin]]
- to_graph(frame='provenance')
- write(prov_path, fmt='json', frame='provenance', context=False, context_url=None)
Serialize provenance to disk.
- Parameters:
prov_path (
str|Path) – Output path (without extension) where the provenance document should be written.fmt (str) – Output format,
"json"for JSON-LD or"trig"for RDF TriG.frame (str) – Which structure to make primary subject of jsonld or trig named graph. Options: “provenance” or “results”.
context (bool) – Whether to include the JSON-LD context inline when writing JSON.
- Returns:
The path to the written provenance document with extension.
- Return type:
- Raises:
Exception – If the requested format is unsupported.
Examples
output = prov.write("prov/uppercase", fmt="json", context=True)
- exception makeprov.prov.ProvenanceWriteError
Bases:
RuntimeErrorRaised when a rule’s provenance record could not be written.
Under
ProvenanceConfig’s defaultstrict=True, this replaces the historical behavior of silently logging a warning and returning a successful result with no provenance on disk.
- exception makeprov.prov.UnresolvedArtifactError
Bases:
ProvenanceWriteErrorRaised when a declared output could not be resolved to a real artifact.
A rule that reports success while one of its declared outputs is missing has either failed silently or mis-declared its outputs. Earlier versions dropped such artifacts from the graph without comment; that produced provenance which looked complete but wasn’t.
- makeprov.prov.apply_context(node, context)
Bind a document-level context to a node and rebuild its term aliases.
- Return type:
- makeprov.prov.pep503_normalize(name)
Normalize a package name according to PEP 503 rules.
- makeprov.prov.project_metadata(dist_name=None)
Extract package metadata for provenance enrichment.
- Parameters:
dist_name (
str|None) – Distribution name; whenNonethe caller’s package name is inferred from the module context.- Returns:
Distribution name, version, and dependency specifications. Empty values are returned when metadata cannot be found.
- Return type:
Examples
name, version, requires = project_metadata("makeprov")
- makeprov.prov.resolve_iris(base_iri, context, *, file_segment='', origin=None, revision=None, forge_profiles=None)
Decide how a document’s identifiers are minted.
An explicit
base_iriis used as-is. Failing that, a remote on a known forge (seeforges.toml) makes the repository URL the document’s@baseand pins file identifiers to the current commit through ablob:prefix — pinning to the commit rather than the branch matters, since a branch URL names different bytes after every push. With neither, identifiers stay relative to the document, which is preferable to inventing a namespace that would collide across unrelated workflows.contextis mutated in place when the forge heuristic applies.originandrevisionlet a caller reuse git lookups it has already made.- Return type: