Skip to content

Commit a60c20c

Browse files
rokroskarjsam
authored andcommitted
feat: add SoftwareAgent to Activity (#590)
closes #508
1 parent fb443d7 commit a60c20c

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

renku/api/_git.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def ensure_unstaged(self, path):
228228
def commit(self, author_date=None, commit_only=None):
229229
"""Automatic commit."""
230230
from git import Actor
231-
from renku.version import __version__
231+
from renku.version import __version__, version_url
232232

233233
author_date = author_date or formatdate(localtime=True)
234234

@@ -243,10 +243,7 @@ def commit(self, author_date=None, commit_only=None):
243243

244244
yield
245245

246-
committer = Actor(
247-
'renku {0}'.format(__version__),
248-
'renku+{0}@datascience.ch'.format(__version__),
249-
)
246+
committer = Actor('renku {0}'.format(__version__), version_url)
250247

251248
if isinstance(commit_only, list):
252249
for path_ in commit_only:

renku/models/provenance/activities.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from renku.models.cwl._ascwl import CWLClass
3030
from renku.models.cwl.types import PATH_OBJECTS
3131

32+
from .agents import renku_agent
3233
from .entities import Collection, CommitMixin, Entity, Process, Workflow
3334
from .qualified import Association, Generation, Usage
3435

@@ -100,6 +101,8 @@ class Activity(CommitMixin):
100101
kw_only=True,
101102
)
102103

104+
agent = jsonld.ib(context='prov:agent', kw_only=True, default=renku_agent)
105+
103106
@generated.default
104107
def default_generated(self):
105108
"""Entities generated by this Action."""

renku/models/provenance/agents.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121

2222
from renku.models import _jsonld as jsonld
23+
from renku.version import __version__, version_url
2324

2425

2526
@jsonld.s(
@@ -96,7 +97,14 @@ def from_commit(cls, commit):
9697
if commit.author != commit.committer:
9798
return cls(
9899
label=commit.committer.name,
99-
id='mailto:{0}'.format(commit.committer.email),
100+
id=commit.committer.email,
100101
was_started_by=author,
101102
)
102103
return author
104+
105+
106+
# set up the default agent
107+
108+
renku_agent = SoftwareAgent(
109+
label='renku {0}'.format(__version__), id=version_url
110+
)

setup.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# limitations under the License.
1818
"""Python SDK and CLI for the Renku platform."""
1919

20-
import datetime
2120
import os
2221

2322
from setuptools import find_packages, setup
@@ -114,14 +113,27 @@
114113
# See the License for the specific language governing permissions and
115114
# limitations under the License.
116115
\"\"\"Version information for Renku.\"\"\"
116+
import re
117117
118118
__version__ = {version!r}
119-
""" % (datetime.date.today().year, )
119+
120+
121+
def _get_disribution_url():
122+
import pkg_resources
123+
d = pkg_resources.get_distribution('renku')
124+
metadata = d._get_metadata(d.PKG_INFO)
125+
home_page = [m for m in metadata if m.startswith('Home-page:')]
126+
return home_page[0].split(':', 1)[1].strip()
127+
128+
129+
_components = re.findall(r'(\d\.\d\.\d)(?:.+g(\w+))?', __version__)[0]
130+
_version = _components[1] or 'v' + _components[0]
131+
version_url = '{{}}/tree/{{}}'.format(_get_disribution_url(), _version)
132+
"""
120133

121134
setup(
122135
name='renku',
123136
use_scm_version={
124-
'local_scheme': 'dirty-tag',
125137
'write_to': os.path.join('renku', 'version.py'),
126138
'write_to_template': version_template,
127139
},

0 commit comments

Comments
 (0)