Skip to content

Hotfix for jsonld context #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions docs/models/provenance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Activities
:inherited-members:


Entities and Plans
------------------
Entities
--------

.. py:module:: renku.core.models.provenance.entities
.. py:module:: renku.core.models.entities

.. autoclass:: Entity
:members:
Expand All @@ -54,6 +54,12 @@ Entities and Plans
:members:
:inherited-members:


Plans
-----

.. py:module:: renku.core.models.provenance.processes

.. autoclass:: Process
:members:
:inherited-members:
Expand All @@ -62,7 +68,6 @@ Entities and Plans
:members:
:inherited-members:


Agents
------

Expand Down
22 changes: 9 additions & 13 deletions renku/cli/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,10 @@ def outputs(ctx, client, revision, paths):

def _context_names():
"""Return list of valid context names."""
import inspect

from renku.core.models import provenance
from renku.core.models.jsonld import JSONLDMixin

for name in dir(provenance):
cls = getattr(provenance, name)
if inspect.isclass(cls) and issubclass(cls, JSONLDMixin):
yield name
for cls in JSONLDMixin.__type_registry__.values():
yield cls.__name__


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

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

cls = getattr(provenance, name)
return {
'@context': cls._jsonld_context,
'@type': cls._jsonld_type,
}
for cls in JSONLDMixin.__type_registry__.values():
if cls.__name__ == name:
return {
'@context': cls._jsonld_context,
'@type': cls._jsonld_type,
}


@show.command()
Expand Down
2 changes: 1 addition & 1 deletion renku/core/commands/ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def node_text(self, node):
indentation = ' ' * len(_RE_ESC.sub('', formatted_sha1))

# Handle subprocesses of a workflow.
from renku.core.models.provenance.entities import Process
from renku.core.models.provenance.processes import Process

part_of = None
if isinstance(node, Process):
Expand Down
3 changes: 2 additions & 1 deletion renku/core/commands/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
WorkflowOutputParameter
from renku.core.models.cwl.types import PATH_TYPES
from renku.core.models.cwl.workflow import Workflow
from renku.core.models.entities import Collection, Entity
from renku.core.models.git import Range
from renku.core.models.provenance import Activity, Generation, ProcessRun, \
Usage
from renku.core.models.provenance.entities import Collection, Entity, Process
from renku.core.models.provenance.processes import Process

LINK_CWL = CommandLineTool(
baseCommand=['true'],
Expand Down
2 changes: 1 addition & 1 deletion renku/core/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from attr.validators import instance_of

from renku.core.models.creators import Creator, CreatorsMixin
from renku.core.models.provenance.entities import Entity
from renku.core.models.entities import Entity
from renku.core.utils.datetime8601 import parse_date
from renku.core.utils.doi import extract_doi, is_doi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,56 +209,3 @@ def entities(self):
for member in self.members:
yield from member.entities
yield self


@jsonld.s(
type=[
'wfdesc:Process',
'prov:Entity',
'prov:Plan',
],
context={
'wfdesc': 'http://purl.org/wf4ever/wfdesc#',
'prov': 'http://www.w3.org/ns/prov#',
},
cmp=False,
)
class Process(CommitMixin):
"""Represent a process."""

_activity = jsonld.ib(
context='prov:activity',
kw_only=True,
converter=weakref.ref,
)

@property
def activity(self):
"""Return the activity object."""
return self._activity()


@jsonld.s(
type=[
'wfdesc:Workflow',
'prov:Entity',
'prov:Plan',
],
context={
'wfdesc': 'http://purl.org/wf4ever/wfdesc#',
'prov': 'http://www.w3.org/ns/prov#',
},
cmp=False,
)
class Workflow(Process):
"""Represent workflow with subprocesses."""

subprocesses = jsonld.ib(context='wfdesc:hasSubProcess', kw_only=True)

@subprocesses.default
def default_subprocesses(self):
"""Load subprocesses."""
return [
subprocess.association.plan
for subprocess in self.activity.subprocesses.values()
]
Loading