How to use the renku.core.models.jsonld 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 / agents.py View on Github external
'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
    },
    frozen=True,
    slots=True,
)
class SoftwareAgent:
    """Represent executed software."""

    label = jsonld.ib(context='rdfs:label', kw_only=True)
    was_started_by = jsonld.ib(
        context='prov:wasStartedBy',
        default=None,
        kw_only=True,
    )

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

    @classmethod
    def from_commit(cls, commit):
        """Create an instance from a Git commit."""
        author = Person.from_commit(commit)
        if commit.author != commit.committer:
            return cls(
                label=commit.committer.name,
                id=commit.committer.email,
                was_started_by=author,
            )
        return author


# set up the default agent
github SwissDataScienceCenter / renku-python / renku / core / models / datasets.py View on Github external
converter=_convert_dataset_files,
        context='schema:hasPart',
        kw_only=True
    )

    tags = jsonld.container.list(
        DatasetTag,
        default=None,
        converter=_convert_dataset_tags,
        context={
            '@id': 'schema:subjectOf',
        },
        kw_only=True
    )

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

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

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

    @short_name.validator
    def short_name_validator(self, attribute, value):
        """Validate short_name."""
        # short_name might have been scaped and have '%' in it
        if value and not is_dataset_name_valid(value, safe='%'):
            raise errors.ParameterError(
github SwissDataScienceCenter / renku-python / renku / core / models / entities.py View on Github external
@attr.s(cmp=False)
class CommitMixin:
    """Represent a commit mixin."""

    commit = attr.ib(default=None, kw_only=True)
    client = attr.ib(default=None, kw_only=True)
    path = jsonld.ib(
        context='prov:atLocation',
        default=None,
        kw_only=True,
        converter=_str_or_none
    )

    _id = jsonld.ib(context='@id', kw_only=True)
    _label = jsonld.ib(context='rdfs:label', kw_only=True)
    _project = jsonld.ib(
        context='schema:isPartOf', type=Project, kw_only=True, default=None
    )

    @property
    def submodules(self):
        """Proxy to client submodules."""
        return self.client.submodules

    @_id.default
    def default_id(self):
        """Configure calculated ID."""
        if self.commit:
            hexsha = self.commit.hexsha
        else:
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / agents.py View on Github external
context={
        'schema': 'http://schema.org/',
        'prov': 'http://www.w3.org/ns/prov#',
        'rdfs': 'http://www.w3.org/2000/01/rdf-schema#'
    },
    slots=True,
)
class Person:
    """Represent a person."""

    name = jsonld.ib(
        context='schema:name', kw_only=True, validator=instance_of(str)
    )
    email = jsonld.ib(context='schema:email', default=None, kw_only=True)
    label = jsonld.ib(context='rdfs:label', kw_only=True)
    affiliation = jsonld.ib(
        default=None, kw_only=True, context='schema:affiliation'
    )
    alternate_name = jsonld.ib(
        default=None, kw_only=True, context='schema:alternateName'
    )
    _id = jsonld.ib(context='@id', kw_only=True)

    @_id.default
    def default_id(self):
        """Set the default id."""
        import string
        if self.email:
            return 'mailto:{email}'.format(email=self.email)

        # prep name to be a valid ntuple string
        name = self.name.translate(str.maketrans('', '', string.punctuation))
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / agents.py View on Github external
)
        if not email:  # pragma: no cover
            raise errors.ParameterError(
                'Email is not valid: Valid format is "Name "'
            )

        return cls(name=name, email=email)

    def __attrs_post_init__(self):
        """Finish object initialization."""
        # handle the case where ids were improperly set
        if self._id == 'mailto:None':
            self._id = self.default_id()


@jsonld.s(
    type=[
        'prov:SoftwareAgent',
        'wfprov:WorkflowEngine',
    ],
    context={
        'prov': 'http://www.w3.org/ns/prov#',
        'wfprov': 'http://purl.org/wf4ever/wfprov#',
        'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
    },
    frozen=True,
    slots=True,
)
class SoftwareAgent:
    """Represent executed software."""

    label = jsonld.ib(context='rdfs:label', kw_only=True)
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / activities.py View on Github external
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
    )

    @children.default
    def default_children(self):
        """Load children from process."""
        basedir = os.path.dirname(self.path) if self.path is not None else None

        def _load(step):
            """Load step definition."""
            if isinstance(step.run, WORKFLOW_STEP_RUN_TYPES):
                return step.run

            if self.commit:
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / activities.py View on Github external
yield output


@jsonld.s(
    type='prov:Activity',
    context={
        'prov': 'http://www.w3.org/ns/prov#',
        'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
        'schema': 'http://schema.org/'
    },
    cmp=False,
)
class Activity(CommitMixin):
    """Represent an activity in the repository."""

    _id = jsonld.ib(context='@id', kw_only=True)
    _message = jsonld.ib(context='rdfs:comment', kw_only=True)
    _was_informed_by = jsonld.ib(
        context='prov:wasInformedBy',
        kw_only=True,
    )

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

    process = attr.ib(default=None, kw_only=True)
    outputs = attr.ib(kw_only=True)

    _collections = attr.ib(
        default=attr.Factory(OrderedDict), init=False, kw_only=True
    )
    generated = jsonld.container.list(
        Generation, context={
github SwissDataScienceCenter / renku-python / renku / core / models / entities.py View on Github external
from renku.core.models import jsonld as jsonld
from renku.core.models.projects import Project


def _str_or_none(data):
    """Return str representation or None."""
    return str(data) if data is not None else data


@attr.s(cmp=False)
class CommitMixin:
    """Represent a commit mixin."""

    commit = attr.ib(default=None, kw_only=True)
    client = attr.ib(default=None, kw_only=True)
    path = jsonld.ib(
        context='prov:atLocation',
        default=None,
        kw_only=True,
        converter=_str_or_none
    )

    _id = jsonld.ib(context='@id', kw_only=True)
    _label = jsonld.ib(context='rdfs:label', kw_only=True)
    _project = jsonld.ib(
        context='schema:isPartOf', type=Project, kw_only=True, default=None
    )

    @property
    def submodules(self):
        """Proxy to client submodules."""
        return self.client.submodules