Skip to content

Commit

Permalink
shacl-shape
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Dec 16, 2022
1 parent 25cf12a commit 48457ad
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 9 deletions.
7 changes: 4 additions & 3 deletions renku/command/graph.py
Expand Up @@ -227,16 +227,17 @@ def _convert_entities_to_graph(
for entity in entities:
if entity.id in processed_plans:
continue
if isinstance(entity, (Dataset, Activity, AbstractPlan)):
if isinstance(entity, (Dataset, Activity, AbstractPlan, WorkflowFileActivityCollection)):
# NOTE: Since the database is read-only, it's OK to modify objects; they won't be written back
entity.unfreeze()
entity.project_id = project_id

if isinstance(entity, Activity):
if isinstance(entity, (Activity, WorkflowFileActivityCollection)):
entity.association.plan.unfreeze()
entity.association.plan.project_id = project_id
schema = next(s for t, s in schemas.items() if isinstance(entity, t))
graph.extend(schema(flattened=True).dump(entity))
data = schema(flattened=True).dump(entity)
graph.extend(data)

if not isinstance(entity, (Activity, WorkflowFileActivityCollection)):
continue
Expand Down
4 changes: 2 additions & 2 deletions renku/command/schema/activity.py
Expand Up @@ -52,7 +52,7 @@ def __getattr__(self, name):
def _fix_id(obj):
"""Fix ids under an activity that were wrong due to a bug."""

if not obj.id.startswith("/activities/"):
if not obj.id.startswith("/activities/") and not obj.id.startswith("/workflow-file-activity-collection/"):
obj = _ObjectWrapper(obj, id=f"/activities/{obj.id}")

return obj
Expand Down Expand Up @@ -179,7 +179,7 @@ class WorkflowFileActivityCollectionSchema(JsonLDSchema):
class Meta:
"""Meta class."""

rdf_type = [prov.Activity, prov.Collection]
rdf_type = [renku.WorkflowFileActivityCollection, prov.Collection]
model = WorkflowFileActivityCollection
unknown = EXCLUDE

Expand Down
81 changes: 78 additions & 3 deletions renku/data/shacl_shape.json
Expand Up @@ -235,6 +235,13 @@
},
"sh:pattern": "http(s)?://[^/]+/activities/[0-9a-f]+"
},
{
"path": "renku:hasActivityCollection",
"sh:class": {
"@id": "renku:WorkflowFileActivityCollection"
},
"sh:pattern": "http(s)?://[^/]+/workflow-file-activity-collection/[0-9a-f]+"
},
{
"nodeKind": "sh:Literal",
"path": "schema:keywords",
Expand Down Expand Up @@ -877,6 +884,74 @@
}
]
},
{
"@id": "_:workflowFileActivityCollectionShape",
"@type": "sh:NodeShape",
"ignoredProperties": [
{
"@id": "rdf:type"
}
],
"closed": true,
"targetClass": "renku:WorkflowFileActivityCollection",
"property": [
{
"path": "prov:wasAssociatedWith",
"or": [
{
"sh:class": {
"@id": "prov:SoftwareAgent"
}
},
{
"sh:class": {
"@id": "schema:Person"
}
},
{
"nodeKind": "sh:IRI"
}
],
"minCount": 2,
"maxCount": 2
},
{
"path": "prov:qualifiedAssociation",
"sh:class": {
"@id": "prov:Association"
},
"sh:pattern": "http(s)?://[^/]+/workflow-file-activity-collection/[0-9a-f]+/association"
},
{
"path": "schema:hasPart",
"sh:class": {
"@id": "prov:Activity"
},
"sh:pattern": "http(s)?://[^/]+/activities/[0-9a-f]+"
},
{
"nodeKind": "sh:Literal",
"path": "prov:endedAtTime",
"datatype": {
"@id": "xsd:dateTime"
},
"minCount": 1,
"maxCount": 1,
"sh:moreThanOrEquals": {
"@id": "prov:startedAtTime"
}
},
{
"nodeKind": "sh:Literal",
"path": "prov:startedAtTime",
"datatype": {
"@id": "xsd:dateTime"
},
"minCount": 1,
"maxCount": 1
}
]
},
{
"@id": "_:associationShape",
"@type": "sh:NodeShape",
Expand Down Expand Up @@ -998,7 +1073,7 @@
"@id": "renku:CommandParameter"
},
"path": "renku:hasArguments",
"sh:pattern": "http(s)?://[^/]+/plans/[0-9a-f-]+/parameters/[0-9a-z]+"
"sh:pattern": "http(s)?://[^/]+/plans/[0-9a-f-]+/parameters/[0-9a-zA-Z_-]+"
},
{
"nodeKind": "sh:Literal",
Expand All @@ -1019,7 +1094,7 @@
"@id": "renku:CommandInput"
},
"path": "renku:hasInputs",
"sh:pattern": "http(s)?://[^/]+/plans/[0-9a-f-]+/inputs/(stdin|[0-9a-f]+)"
"sh:pattern": "http(s)?://[^/]+/plans/[0-9a-f-]+/inputs/([0-9a-zA-Z_-]+)"
},
{
"nodeKind": "sh:Literal",
Expand All @@ -1034,7 +1109,7 @@
"@id": "renku:CommandOutput"
},
"path": "renku:hasOutputs",
"sh:pattern": "http(s)?://[^/]+/plans/[0-9a-f-]+/outputs/(stdout|stderr|[0-9a-f]+)"
"sh:pattern": "http(s)?://[^/]+/plans/[0-9a-f-]+/outputs/([0-9a-zA-Z_-]+)"
},
{
"nodeKind": "sh:Literal",
Expand Down
3 changes: 3 additions & 0 deletions renku/domain_model/provenance/activity.py
Expand Up @@ -342,3 +342,6 @@ def from_activities(
def generate_id() -> str:
"""Generate an identifier."""
return f"/workflow-file-activity-collection/{uuid4().hex}"

def __repr__(self):
return f"<WorkflowFileActivityCollection '{self.id}': {self.association.plan.name} @ {self.ended_at_time}>"
12 changes: 11 additions & 1 deletion tests/cli/test_workflow_file.py
Expand Up @@ -161,13 +161,14 @@ def test_export_graph_with_workflow_file(runner, workflow_file_project):
result = runner.invoke(cli, ["run", workflow_file_project.workflow_file])
assert 0 == result.exit_code, format_result_exception(result)

result = runner.invoke(cli, ["graph", "export", "--full"])
result = runner.invoke(cli, ["graph", "export", "--full", "--strict"])
assert 0 == result.exit_code, format_result_exception(result)

assert "workflow-file" in result.output
assert "workflow-file.head" in result.output
assert "workflow-file.tail" in result.output
assert "workflow-file.line-count" in result.output
assert "renku-ontology#WorkflowFileActivityCollection" in result.output
assert "renku-ontology#WorkflowFileCompositePlan" in result.output
assert "renku-ontology#WorkflowFilePlan" in result.output

Expand Down Expand Up @@ -467,3 +468,12 @@ def test_workflow_file_status(runner, workflow_file_project):

assert "Outdated workflow files and their outputs(1):" in result.output
assert "workflow-file.yml: intermediate, results/output.csv, results/output.csv.wc" in result.output

result = runner.invoke(cli, ["run", workflow_file_project.workflow_file])
assert 0 == result.exit_code, format_result_exception(result)

result = runner.invoke(cli, ["status"])
assert 0 == result.exit_code, format_result_exception(result)

assert "Outdated workflow files and their outputs(1):" not in result.output
assert "Everything is up-to-date" in result.output

0 comments on commit 48457ad

Please sign in to comment.