Skip to content

Commit ac9bac3

Browse files
committed
fix: make Creator a subclass of Person
closes #793
1 parent 6bfb8be commit ac9bac3

File tree

5 files changed

+30
-70
lines changed

5 files changed

+30
-70
lines changed

renku/core/commands/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
from renku.core.models.cwl.workflow import Workflow
3232
from renku.core.models.entities import Collection, Entity
3333
from renku.core.models.git import Range
34-
from renku.core.models.provenance import Activity, Generation, ProcessRun, \
35-
Usage
34+
from renku.core.models.provenance.activities import Activity, ProcessRun, Usage
3635
from renku.core.models.provenance.processes import Process
36+
from renku.core.models.provenance.qualified import Generation
3737

3838
LINK_CWL = CommandLineTool(
3939
baseCommand=['true'],

renku/core/models/creators.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,26 @@
1717
# limitations under the License.
1818
"""Model objects representing a creator."""
1919
import configparser
20-
import re
21-
import uuid
2220

2321
import attr
24-
from attr.validators import instance_of
2522

2623
from renku.core import errors
24+
from renku.core.models.provenance.agents import Person
2725

2826
from . import jsonld as jsonld
2927

3028

31-
@jsonld.s(
32-
type='schema:Person',
33-
context={'schema': 'http://schema.org/'},
34-
slots=True,
35-
)
36-
class Creator(object):
29+
class Creator(Person):
3730
"""Represent the creator of a resource."""
3831

39-
client = attr.ib(default=None, kw_only=True)
40-
4132
affiliation = jsonld.ib(
4233
default=None, kw_only=True, context='schema:affiliation'
4334
)
4435

45-
email = jsonld.ib(default=None, kw_only=True, context='schema:email')
46-
4736
alternate_name = jsonld.ib(
4837
default=None, kw_only=True, context='schema:alternateName'
4938
)
5039

51-
name = jsonld.ib(
52-
default=None,
53-
kw_only=True,
54-
validator=instance_of(str),
55-
context='schema:name'
56-
)
57-
58-
_id = jsonld.ib(kw_only=True, context='@id')
59-
6040
@property
6141
def short_name(self):
6242
"""Gives full name in short form."""
@@ -70,14 +50,6 @@ def short_name(self):
7050

7151
return '{0}.{1}'.format('.'.join(initials), last_name)
7252

73-
@email.validator
74-
def check_email(self, attribute, value):
75-
"""Check that the email is valid."""
76-
if self.email and not (
77-
isinstance(value, str) and re.match(r'[^@]+@[^@]+\.[^@]+', value)
78-
):
79-
raise ValueError('Email address is invalid.')
80-
8153
@classmethod
8254
def from_git(cls, git):
8355
"""Create an instance from a Git repo."""
@@ -104,18 +76,6 @@ def from_git(cls, git):
10476

10577
return cls(name=name, email=email)
10678

107-
@classmethod
108-
def from_commit(cls, commit):
109-
"""Create an instance from a Git commit."""
110-
return cls(name=commit.author.name, email=commit.author.email)
111-
112-
@_id.default
113-
def default_id(self):
114-
"""Set the default id."""
115-
if self.email:
116-
return 'mailto:{email}'.format(email=self.email)
117-
return '_:{}'.format(str(uuid.uuid4()))
118-
11979
def __attrs_post_init__(self):
12080
"""Finish object initialization."""
12181
# handle the case where ids were improperly set

renku/core/models/provenance/__init__.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,3 @@
1919
2020
.. seealso:: https://www.w3.org/TR/prov-o/
2121
"""
22-
23-
from .activities import Activity, ProcessRun, WorkflowRun
24-
from .agents import Person, SoftwareAgent
25-
from .qualified import Generation, Usage
26-
from .processes import Process, Workflow
27-
28-
__all__ = (
29-
'Activity',
30-
'Entity',
31-
'Collection',
32-
'Generation',
33-
'Person',
34-
'Process',
35-
'ProcessRun',
36-
'SoftwareAgent',
37-
'Usage',
38-
'Workflow',
39-
'WorkflowRun',
40-
)

renku/core/models/provenance/agents.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import re
2121

22+
from attr.validators import instance_of
23+
2224
from renku.core.models import jsonld as jsonld
2325
from renku.version import __version__, version_url
2426

@@ -31,28 +33,41 @@
3133
context={
3234
'schema': 'http://schema.org/',
3335
'prov': 'http://www.w3.org/ns/prov#',
36+
'rdfs': 'http://www.w3.org/2000/01/rdf-schema#'
3437
},
3538
frozen=True,
3639
slots=True,
3740
)
3841
class Person:
3942
"""Represent a person."""
4043

41-
name = jsonld.ib(context='rdfs:label')
42-
email = jsonld.ib(context='schema:email')
44+
name = jsonld.ib(
45+
context='schema:name', kw_only=True, validator=instance_of(str)
46+
)
47+
email = jsonld.ib(context='schema:email', default=None, kw_only=True)
48+
label = jsonld.ib(context='rdfs:label', kw_only=True)
4349

44-
_id = jsonld.ib(context='@id', init=False, kw_only=True)
50+
_id = jsonld.ib(context='@id', kw_only=True)
4551

4652
@_id.default
4753
def default_id(self):
48-
"""Configure calculated ID."""
49-
return 'mailto:{0}'.format(self.email)
54+
"""Set the default id."""
55+
if self.email:
56+
return 'mailto:{email}'.format(email=self.email)
57+
return '_:{}'.format(''.join(self.name.lowercase.split()))
5058

5159
@email.validator
5260
def check_email(self, attribute, value):
5361
"""Check that the email is valid."""
54-
if not (isinstance(value, str) and re.match(r'[^@]+@[^@]+', value)):
55-
raise ValueError('Email address "{0}" is invalid.'.format(value))
62+
if self.email and not (
63+
isinstance(value, str) and re.match(r'[^@]+@[^@]+\.[^@]+', value)
64+
):
65+
raise ValueError('Email address is invalid.')
66+
67+
@label.default
68+
def default_label(self):
69+
"""Set the default label."""
70+
return self.name
5671

5772
@classmethod
5873
def from_commit(cls, commit):

tests/core/models/test_projects.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def test_project_creator_deserialization(client, project):
169169
)
170170
# the project creator should always be the one in the metadata
171171
assert client.project.creator.email == 'johndoe@example.com'
172+
assert client.project.creator.name == 'Johnny Doe'
173+
assert client.project.creator.label == client.project.creator.name
172174

173175
# Remove the creator from metadata
174176
project = client.project
@@ -181,3 +183,5 @@ def test_project_creator_deserialization(client, project):
181183
# now the creator should be the one from the commit
182184
project = Project.from_yaml(client.renku_metadata_path, client=client)
183185
assert project.creator.email == 'janedoe@example.com'
186+
assert project.creator.name == 'Jane Doe'
187+
assert project.creator.label == project.creator.name

0 commit comments

Comments
 (0)