diff --git a/renku/api/datasets.py b/renku/api/datasets.py
index eacb30a3c6..91a87123a7 100644
--- a/renku/api/datasets.py
+++ b/renku/api/datasets.py
@@ -187,7 +187,12 @@ def add_data_to_dataset(
# Generate the DatasetFiles
dataset_files = []
for data in files:
- dataset_files.append(DatasetFile.from_revision(self, **data))
+ datasetfile = DatasetFile.from_revision(self, **data)
+
+ # Set dataset file path relative to projects root for submodules
+ if datasetfile.client != self:
+ datasetfile.path = str(data['path'])
+ dataset_files.append(datasetfile)
dataset.update_files(dataset_files)
def _add_from_url(self, dataset, path, url, link=False, **kwargs):
diff --git a/renku/cli/_format/graph.py b/renku/cli/_format/graph.py
index a49c44f093..e7f6115a9b 100644
--- a/renku/cli/_format/graph.py
+++ b/renku/cli/_format/graph.py
@@ -271,7 +271,7 @@ def color(p):
fields[sn].add((qname(p, g), formatliteral(o, g)))
for u, n in nodes.items():
- stream.write(u"# %s %s\n" % (u, n))
+ stream.write(u'# %s %s\n' % (u, n))
f = [
'
| %s | '
'%s |
' % x for x in sorted(types[n])
diff --git a/renku/models/datasets.py b/renku/models/datasets.py
index 2382b32778..8fc7aa0967 100644
--- a/renku/models/datasets.py
+++ b/renku/models/datasets.py
@@ -88,7 +88,7 @@ def short_name(self):
def check_email(self, attribute, value):
"""Check that the email is valid."""
if self.email and not (
- isinstance(value, str) and re.match(r"[^@]+@[^@]+\.[^@]+", value)
+ isinstance(value, str) and re.match(r'[^@]+@[^@]+\.[^@]+', value)
):
raise ValueError('Email address is invalid.')
@@ -465,3 +465,15 @@ def __attrs_post_init__(self):
if not self.path:
self.path = str(self.client.renku_datasets_path / str(self.uid))
+
+ if self.files:
+ for datasetfile in self.files:
+ if datasetfile.client is None:
+ client, _, _ = self.client.resolve_in_submodules(
+ self.client.find_previous_commit(
+ datasetfile.path, revision='HEAD'
+ ),
+ datasetfile.path,
+ )
+
+ datasetfile.client = client
diff --git a/renku/models/provenance/agents.py b/renku/models/provenance/agents.py
index fba38d14cb..c6ee2c7f15 100644
--- a/renku/models/provenance/agents.py
+++ b/renku/models/provenance/agents.py
@@ -54,7 +54,7 @@ def default_id(self):
@email.validator
def check_email(self, attribute, value):
"""Check that the email is valid."""
- if not (isinstance(value, str) and re.match(r"[^@]+@[^@]+", value)):
+ if not (isinstance(value, str) and re.match(r'[^@]+@[^@]+', value)):
raise ValueError('Email address "{0}" is invalid.'.format(value))
@classmethod
diff --git a/tests/cli/test_datasets.py b/tests/cli/test_datasets.py
index b07df83b72..a088ad72a5 100644
--- a/tests/cli/test_datasets.py
+++ b/tests/cli/test_datasets.py
@@ -440,6 +440,39 @@ def test_dataset_add_with_copy(tmpdir, runner, project, client):
assert inode not in original_inodes
+def test_dataset_file_path_from_subdirectory(runner, project, client):
+ """Test adding a file into a dataset and check path independent
+ of the CWD """
+ # create a dataset
+ result = runner.invoke(cli.cli, ['dataset', 'create', 'dataset'])
+ assert 0 == result.exit_code
+ assert 'OK' in result.output
+
+ with (client.path / 'a').open('w') as fp:
+ fp.write('a')
+
+ client.repo.git.add('a')
+ client.repo.git.commit(message='Added file a')
+
+ # add data
+ result = runner.invoke(
+ cli.cli,
+ ['dataset', 'add', 'dataset', 'a'],
+ catch_exceptions=False,
+ )
+ assert 0 == result.exit_code
+
+ with client.with_dataset('dataset') as dataset:
+ datasetfile = dataset.find_file('a')
+ assert datasetfile
+
+ assert datasetfile.full_path == client.path / 'a'
+
+ os.chdir('./data')
+
+ assert datasetfile.full_path == client.path / 'a'
+
+
def test_datasets_ls_files_tabular_empty(runner, project):
"""Test listing of data within empty dataset."""
# create a dataset