How to use the renku.core.models.provenance.agents.Person 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 / tests / core / models / test_projects.py View on Github external
def test_project_creator_deserialization(client, project):
    """Check that the correct creator is returned on deserialization."""
    from renku.core.models.provenance.agents import Person

    # modify the project metadata to change the creator
    project = client.project
    project.creator = Person(email='johndoe@example.com', name='Johnny Doe')
    project.to_yaml()
    client.repo.git.commit(
        '-a', '--amend', '-C', 'HEAD', '--author',
        'Johnny Doe ', '--no-verify'
    )
    # the project creator should always be the one in the metadata
    assert client.project.creator.email == 'johndoe@example.com'
    assert client.project.creator.name == 'Johnny Doe'
    assert client.project.creator.label == client.project.creator.name

    # Remove the creator from metadata
    project = client.project
    project.creator = None
    project.to_yaml()
    client.repo.git.commit(
        '-a', '--amend', '-C', 'HEAD', '--author',
github SwissDataScienceCenter / renku-python / tests / core / models / test_shacl_schema.py View on Github external
def test_project_shacl(project, client):
    """Test project metadata structure."""
    from renku.core.models.provenance.agents import Person

    path = Path(
        __file__
    ).parent.parent.parent / 'fixtures' / 'force_project_shacl.json'

    project = client.project
    project.creator = Person(email='johndoe@example.com', name='Johnny Doe')

    g = project.asjsonld()
    rdf = pyld.jsonld.to_rdf(
        g,
        options={
            'format': 'application/n-quads',
            'produceGeneralizedRdf': False
        }
    )
    r, _, t = validate_graph(rdf, shacl_path=str(path))
    assert r is True, t

    r, _, t = validate_graph(rdf)
    assert r is True, t
github SwissDataScienceCenter / renku-python / tests / core / models / test_projects.py View on Github external
def test_project_serialization():
    """Test project serialization with JSON-LD context."""
    with freeze_time('2017-03-01T08:00:00.000000+00:00') as frozen_time:
        project = Project(name='demo')
        assert project.name == 'demo'
        assert project.created == frozen_time().replace(tzinfo=timezone.utc)
        assert project.updated == frozen_time().replace(tzinfo=timezone.utc)

    data = asjsonld(project)
    assert 'schema:Project' in data['@type']
    assert 'prov:Location' in data['@type']

    context = data['@context']
    assert 'schema:name' == context['name']
    assert Person._jsonld_context == context['creator']['@context']
    assert 'schema:dateUpdated' == context['updated']
    assert 'schema:dateCreated' == context['created']
    assert 'schema:schemaVersion' == context['version']
github SwissDataScienceCenter / renku-python / renku / core / commands / dataset.py View on Github external
def create_dataset(
    client, name, short_name, description, creators, commit_message=None
):
    """Create an empty dataset in the current repo.

    :raises: ``renku.core.errors.ParameterError``
    """
    if not creators:
        creators = [Person.from_git(client.repo)]
    else:
        creators = [Person.from_string(c) for c in creators]

    dataset, _, __ = client.create_dataset(
        name=name,
        short_name=short_name,
        description=description,
        creators=creators
    )

    return dataset
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / agents.py View on Github external
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
github SwissDataScienceCenter / renku-python / renku / core / models / provenance / activities.py View on Github external
def default_person_agent(self):
        """Set person agent to be the author of the commit."""
        if self.commit:
            return Person.from_commit(self.commit)
        return None
github SwissDataScienceCenter / renku-python / renku / core / management / datasets.py View on Github external
self.repo.index.commit(
            'renku dataset: updated {} files and deleted {} files'.format(
                len(updated_files), len(deleted_files)
            )
        )

        # Update datasets' metadata

        modified_datasets = {}

        for file_ in updated_files:
            # Re-create list of creators
            creators = []
            # grab all the creators from the commit history
            for commit in repo.iter_commits(paths=file_.path):
                creator = Person.from_commit(commit)
                if creator not in creators:
                    creators.append(creator)

            new_file = DatasetFile.from_revision(
                self,
                path=file_.path,
                based_on=file_.based_on,
                creator=creators
            )
            file_.dataset.update_files([new_file])
            modified_datasets[file_.dataset.name] = file_.dataset

        if delete:
            for file_ in deleted_files:
                file_.dataset.unlink_file(file_.path)
                modified_datasets[file_.dataset.name] = file_.dataset
github SwissDataScienceCenter / renku-python / renku / core / models / creators.py View on Github external
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Model objects representing a creator."""
import configparser

import attr

from renku.core import errors
from renku.core.models.provenance.agents import Person

from . import jsonld as jsonld


class Creator(Person):
    """Represent the creator of a resource."""

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

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

    @property
    def short_name(self):
        """Gives full name in short form."""
        names = self.name.split()
        if len(names) == 1:
            return self.name
github SwissDataScienceCenter / renku-python / renku / core / models / projects.py View on Github external
def __attrs_post_init__(self):
        """Initialize computed attributes."""
        if not self.creator and self.client:
            if self.client.renku_metadata_path.exists():
                self.creator = Person.from_commit(
                    self.client.find_previous_commit(
                        self.client.renku_metadata_path, return_first=True
                    ),
                )
            else:
                # this assumes the project is being newly created
                self.creator = Person.from_git(self.client.repo)

        self._id = self.project_id
github SwissDataScienceCenter / renku-python / renku / core / models / datasets.py View on Github external
def _convert_creators(value):
    """Convert creators."""
    if isinstance(value, dict):  # compatibility with previous versions
        return [Person.from_jsonld(value)]

    if isinstance(value, list):
        return [Person.from_jsonld(v) for v in value]


@attr.s
class CreatorMixin:
    """Mixin for handling creators container."""

    creator = jsonld.container.list(
        Person,
        kw_only=True,
        context='schema:creator',
        converter=_convert_creators
    )

    @property
    def creators_csv(self):
        """Comma-separated list of creators associated with dataset."""
        return ','.join(creator.name for creator in self.creator)


def _extract_doi(value):
    """Return either a string or the doi part of a URL."""
    value = str(value)
    if is_doi(value):
        return extract_doi(value)