Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion renku/api/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion renku/cli/_format/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
'<tr><td align="left"><b>%s</b></td><td align="left">'
'<b>%s</b></td></tr>' % x for x in sorted(types[n])
Expand Down
14 changes: 13 additions & 1 deletion renku/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion renku/models/provenance/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions tests/cli/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down