Skip to content

Commit

Permalink
store label & doc fields as prospective provenance
Browse files Browse the repository at this point in the history
TODO: fix intent list

add/amend tests
  • Loading branch information
mr-c committed Dec 18, 2023
1 parent 8edabf8 commit 25b3ddb
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions cwltool/cwlprov/provenance_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@
)
from .writablebagfile import create_job, write_bag_file # change this later

# from schema_salad.utils import convert_to_dict


if TYPE_CHECKING:
from .ro import ResearchObject

_attributes_type = Dict[str | Identifier, Any]


def copy_job_order(job: Union[Process, JobsType], job_order_object: CWLObjectType) -> CWLObjectType:
"""Create copy of job object for provenance."""
Expand Down Expand Up @@ -235,13 +240,13 @@ def evaluate(
"""Evaluate the nature of job."""
if not hasattr(process, "steps"):
# record provenance of independent commandline tool executions
self.prospective_prov(job)
self.prospective_prov(job, process)

Check warning on line 243 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L243

Added line #L243 was not covered by tests
customised_job = copy_job_order(job, job_order_object)
self.used_artefacts(customised_job, self.workflow_run_uri)
create_job(research_obj, customised_job)
elif hasattr(job, "workflow"):
# record provenance of workflow executions
self.prospective_prov(job)
self.prospective_prov(job, process)

Check warning on line 249 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L249

Added line #L249 was not covered by tests
customised_job = copy_job_order(job, job_order_object)
self.used_artefacts(customised_job, self.workflow_run_uri)
# if CWLPROV['prov'].uri in job_order_object: # maybe move this to another place
Expand Down Expand Up @@ -734,35 +739,38 @@ def generate_output_prov(
entity, process_run_id, timestamp, None, {"prov:role": role}
)

def prospective_prov(self, job: JobsType) -> None:
def prospective_prov(self, job: JobsType, process: Process) -> None:
"""Create prospective prov recording as wfdesc prov:Plan."""
prov_items: _attributes_type = {

Check warning on line 744 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L744

Added line #L744 was not covered by tests
PROV_TYPE: WFDESC["Workflow"] if isinstance(job, WorkflowJob) else WFDESC["Process"],
"prov:type": PROV["Plan"],
"prov:label": "Prospective provenance",
}
if "doc" in process.tool:
prov_items["schema:description"] = process.tool["doc"]

Check warning on line 750 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L750

Added line #L750 was not covered by tests
if "label" in process.tool:
prov_items["schema:name"] = process.tool["label"]

Check warning on line 752 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L752

Added line #L752 was not covered by tests
# # TypeError: unhashable type: 'list'
# if "intent" in process.tool:
# prov_items["schema:featureList"] = convert_to_dict(process.tool["intent"])
self.document.entity("wf:main", prov_items)

Check warning on line 756 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L756

Added line #L756 was not covered by tests
if not isinstance(job, WorkflowJob):
# direct command line tool execution
self.document.entity(
"wf:main",
{
PROV_TYPE: WFDESC["Process"],
"prov:type": PROV["Plan"],
"prov:label": "Prospective provenance",
},
)
return

self.document.entity(
"wf:main",
{
PROV_TYPE: WFDESC["Workflow"],
"prov:type": PROV["Plan"],
"prov:label": "Prospective provenance",
},
)

for step in job.steps:
stepnametemp = "wf:main/" + str(step.name)[5:]
stepname = urllib.parse.quote(stepnametemp, safe=":/,#")
provstep_items: _attributes_type = {

Check warning on line 763 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L763

Added line #L763 was not covered by tests
PROV_TYPE: WFDESC["Process"],
"prov:type": PROV["Plan"],
}
if "doc" in step.tool:
provstep_items["schema:description"] = step.tool["doc"]

Check warning on line 768 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L768

Added line #L768 was not covered by tests
if "label" in step.tool:
provstep_items["schema:name"] = step.tool["label"]

Check warning on line 770 in cwltool/cwlprov/provenance_profile.py

View check run for this annotation

Codecov / codecov/patch

cwltool/cwlprov/provenance_profile.py#L770

Added line #L770 was not covered by tests
provstep = self.document.entity(
stepname,
{PROV_TYPE: WFDESC["Process"], "prov:type": PROV["Plan"]},
provstep_items,
)
self.document.entity(
"wf:main",
Expand Down

0 comments on commit 25b3ddb

Please sign in to comment.