How to use the renku.core.models.jsonld.ib function in renku

To help you get started, we’ve selected a few renku examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SwissDataScienceCenter / renku-python / renku / core / models / provenance / qualified.py View on Github external
@jsonld.s(
    type='prov:Association',
    context={
        'prov': 'http://www.w3.org/ns/prov#',
    },
)
class Association:
    """Assign responsibility to an agent for an activity."""

    plan = jsonld.ib(
        context='prov:hadPlan',
        type='renku.core.models.provenance.processes.Process'
    )
    agent = jsonld.ib(
        context='prov:agent',
        default=None,
        type='renku.core.models.provenance.agents.SoftwareAgent'
    )

    _id = jsonld.ib(context='@id', kw_only=True)

    @classmethod
    def from_activity(cls, activity, commit=None):
        """Create an instance from the activity."""
        from .agents import SoftwareAgent

        agent = SoftwareAgent.from_commit(activity.commit)
        return cls(
            plan=activity.__association_cls__(
                commit=commit or activity.commit,
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / activities.py View on Github external
type='wfprov:WorkflowRun',
    context={
        'wfprov': 'http://purl.org/wf4ever/wfprov#',
    },
    cmp=False,
)
class WorkflowRun(ProcessRun):
    """A workflow run typically contains several subprocesses."""

    __association_cls__ = Workflow

    # @reverse wfprov:wasPartOfWorkflowRun

    children = attr.ib(kw_only=True)

    _processes = jsonld.ib(
        context={
            '@reverse': 'wfprov:wasPartOfWorkflowRun',
        },
        default=attr.Factory(list),
        kw_only=True,
        type=Process
    )
    subprocesses = attr.ib(kw_only=True)

    outputs = attr.ib(kw_only=True)

    generated = jsonld.container.list(
        Generation, context={
            '@reverse': 'prov:activity',
        }, kw_only=True
    )
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / qualified.py View on Github external
cmp=False,
)
class Generation(EntityProxyMixin):
    """Represent an act of generating a file."""

    entity = jsonld.ib(
        context={
            '@reverse': 'prov:qualifiedGeneration',
        },
        type=[
            'renku.core.models.entities.Entity',
            'renku.core.models.entities.Collection', Dataset, DatasetFile
        ]
    )

    role = jsonld.ib(context='prov:hadRole', default=None)

    _activity = attr.ib(
        default=None,
        kw_only=True,
        converter=lambda value: weakref.ref(value)
        if value is not None else None,
    )
    _id = jsonld.ib(context='@id', kw_only=True)

    @property
    def activity(self):
        """Return the activity object."""
        return self._activity() if self._activity is not None else None

    @_id.default
    def default_id(self):
github SwissDataScienceCenter / renku-python / renku / core / models / datasets.py View on Github external
description = jsonld.ib(
        default=None,
        kw_only=True,
        validator=instance_of(str),
        context='schema:description'
    )

    commit = jsonld.ib(
        default=None,
        kw_only=True,
        validator=instance_of(str),
        context='schema:location'
    )

    created = jsonld.ib(
        converter=parse_date, context='schema:startDate', kw_only=True
    )

    dataset = jsonld.ib(context='schema:about', default=None, kw_only=True)

    _id = jsonld.ib(kw_only=True, context='@id')

    @created.default
    def _now(self):
        """Define default value for datetime fields."""
        return datetime.datetime.now(datetime.timezone.utc)

    @_id.default
    def default_id(self):
        """Define default value for id field."""
        return '_:{0}@{1}'.format(self.name, self.commit)
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / processes.py View on Github external
@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()
        ]
github SwissDataScienceCenter / renku-python / renku / core / models / datasets.py View on Github external
"""Convert based_on to DatasetFile."""
    if v:
        return DatasetFile.from_jsonld(v)


@jsonld.s(
    type='schema:DigitalDocument',
    slots=True,
    context={
        'schema': 'http://schema.org/',
    }
)
class DatasetFile(Entity, CreatorMixin):
    """Represent a file in a dataset."""

    added = jsonld.ib(
        converter=parse_date, context='schema:dateCreated', kw_only=True
    )

    checksum = attr.ib(default=None, kw_only=True)

    filename = attr.ib(kw_only=True, converter=convert_filename_path)

    name = jsonld.ib(context='schema:name', kw_only=True, default=None)

    filesize = attr.ib(default=None, kw_only=True)

    filetype = attr.ib(default=None, kw_only=True)

    url = jsonld.ib(default=None, context='schema:url', kw_only=True)

    based_on = jsonld.ib(
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / qualified.py View on Github external
cmp=False,
)
class Usage(EntityProxyMixin):
    """Represent a dependent path."""

    entity = jsonld.ib(
        context='prov:entity',
        kw_only=True,
        type=[
            'renku.core.models.entities.Entity',
            'renku.core.models.entities.Collection', Dataset, DatasetFile
        ]
    )
    role = jsonld.ib(context='prov:hadRole', default=None, kw_only=True)

    _id = jsonld.ib(context='@id', default=None, kw_only=True)

    @classmethod
    def from_revision(cls, client, path, revision='HEAD', **kwargs):
        """Return dependency from given path and revision."""
        from renku.core.models.entities import Entity

        return cls(
            entity=Entity.from_revision(client, path, revision), **kwargs
        )


@jsonld.s(
    type='prov:Generation',
    context={
        'prov': 'http://www.w3.org/ns/prov#',
    },
github SwissDataScienceCenter / renku-python / renku / core / models / datasets.py View on Github external
"""Define default value for id field."""
        return '_:{0}@{1}'.format(self.name, self.commit)


@jsonld.s(
    type='schema:Language',
    context={'schema': 'http://schema.org/'},
    slots=True,
)
class Language:
    """Represent a language of an object."""

    alternate_name = jsonld.ib(
        default=None, kw_only=True, context='schema:alternateName'
    )
    name = jsonld.ib(default=None, kw_only=True, context='schema:name')


def convert_filename_path(p):
    """Return name of the file."""
    if p:
        return Path(p).name


def convert_based_on(v):
    """Convert based_on to DatasetFile."""
    if v:
        return DatasetFile.from_jsonld(v)


@jsonld.s(
    type='schema:DigitalDocument',