Skip to content

Commit b8b1ae2

Browse files
authored
Hotfix for jsonld context (#782)
* feat: Enhances jsonld representation with scoped, type specific contexts at the top-level *fix: compaction now works in all cases * feat: enable other entities for show context
1 parent 6084c87 commit b8b1ae2

File tree

11 files changed

+285
-138
lines changed

11 files changed

+285
-138
lines changed

docs/models/provenance.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ Activities
4141
:inherited-members:
4242

4343

44-
Entities and Plans
45-
------------------
44+
Entities
45+
--------
4646

47-
.. py:module:: renku.core.models.provenance.entities
47+
.. py:module:: renku.core.models.entities
4848
4949
.. autoclass:: Entity
5050
:members:
@@ -54,6 +54,12 @@ Entities and Plans
5454
:members:
5555
:inherited-members:
5656

57+
58+
Plans
59+
-----
60+
61+
.. py:module:: renku.core.models.provenance.processes
62+
5763
.. autoclass:: Process
5864
:members:
5965
:inherited-members:
@@ -62,7 +68,6 @@ Entities and Plans
6268
:members:
6369
:inherited-members:
6470

65-
6671
Agents
6772
------
6873

renku/cli/show.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,10 @@ def outputs(ctx, client, revision, paths):
179179

180180
def _context_names():
181181
"""Return list of valid context names."""
182-
import inspect
183-
184-
from renku.core.models import provenance
185182
from renku.core.models.jsonld import JSONLDMixin
186183

187-
for name in dir(provenance):
188-
cls = getattr(provenance, name)
189-
if inspect.isclass(cls) and issubclass(cls, JSONLDMixin):
190-
yield name
184+
for cls in JSONLDMixin.__type_registry__.values():
185+
yield cls.__name__
191186

192187

193188
def print_context_names(ctx, param, value):
@@ -200,13 +195,14 @@ def print_context_names(ctx, param, value):
200195

201196
def _context_json(name):
202197
"""Return JSON-LD string for given context name."""
203-
from renku.core.models import provenance
198+
from renku.core.models.jsonld import JSONLDMixin
204199

205-
cls = getattr(provenance, name)
206-
return {
207-
'@context': cls._jsonld_context,
208-
'@type': cls._jsonld_type,
209-
}
200+
for cls in JSONLDMixin.__type_registry__.values():
201+
if cls.__name__ == name:
202+
return {
203+
'@context': cls._jsonld_context,
204+
'@type': cls._jsonld_type,
205+
}
210206

211207

212208
@show.command()

renku/core/commands/ascii.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def node_text(self, node):
122122
indentation = ' ' * len(_RE_ESC.sub('', formatted_sha1))
123123

124124
# Handle subprocesses of a workflow.
125-
from renku.core.models.provenance.entities import Process
125+
from renku.core.models.provenance.processes import Process
126126

127127
part_of = None
128128
if isinstance(node, Process):

renku/core/commands/graph.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
WorkflowOutputParameter
3030
from renku.core.models.cwl.types import PATH_TYPES
3131
from renku.core.models.cwl.workflow import Workflow
32+
from renku.core.models.entities import Collection, Entity
3233
from renku.core.models.git import Range
3334
from renku.core.models.provenance import Activity, Generation, ProcessRun, \
3435
Usage
35-
from renku.core.models.provenance.entities import Collection, Entity, Process
36+
from renku.core.models.provenance.processes import Process
3637

3738
LINK_CWL = CommandLineTool(
3839
baseCommand=['true'],

renku/core/models/datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from attr.validators import instance_of
3131

3232
from renku.core.models.creators import Creator, CreatorsMixin
33-
from renku.core.models.provenance.entities import Entity
33+
from renku.core.models.entities import Entity
3434
from renku.core.utils.datetime8601 import parse_date
3535
from renku.core.utils.doi import extract_doi, is_doi
3636

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -209,56 +209,3 @@ def entities(self):
209209
for member in self.members:
210210
yield from member.entities
211211
yield self
212-
213-
214-
@jsonld.s(
215-
type=[
216-
'wfdesc:Process',
217-
'prov:Entity',
218-
'prov:Plan',
219-
],
220-
context={
221-
'wfdesc': 'http://purl.org/wf4ever/wfdesc#',
222-
'prov': 'http://www.w3.org/ns/prov#',
223-
},
224-
cmp=False,
225-
)
226-
class Process(CommitMixin):
227-
"""Represent a process."""
228-
229-
_activity = jsonld.ib(
230-
context='prov:activity',
231-
kw_only=True,
232-
converter=weakref.ref,
233-
)
234-
235-
@property
236-
def activity(self):
237-
"""Return the activity object."""
238-
return self._activity()
239-
240-
241-
@jsonld.s(
242-
type=[
243-
'wfdesc:Workflow',
244-
'prov:Entity',
245-
'prov:Plan',
246-
],
247-
context={
248-
'wfdesc': 'http://purl.org/wf4ever/wfdesc#',
249-
'prov': 'http://www.w3.org/ns/prov#',
250-
},
251-
cmp=False,
252-
)
253-
class Workflow(Process):
254-
"""Represent workflow with subprocesses."""
255-
256-
subprocesses = jsonld.ib(context='wfdesc:hasSubProcess', kw_only=True)
257-
258-
@subprocesses.default
259-
def default_subprocesses(self):
260-
"""Load subprocesses."""
261-
return [
262-
subprocess.association.plan
263-
for subprocess in self.activity.subprocesses.values()
264-
]

0 commit comments

Comments
 (0)