Skip to content

Commit

Permalink
fix(dataset): set isBasedOn for renku datasets (#1617)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Oct 16, 2020
1 parent 3ef04fb commit 3aee6b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
11 changes: 3 additions & 8 deletions renku/core/commands/dataset.py
Expand Up @@ -150,7 +150,6 @@ def add_file(
sources=(),
destination="",
ref=None,
with_metadata=None,
urlscontext=contextlib.nullcontext,
commit_message=None,
progress=None,
Expand All @@ -168,7 +167,6 @@ def add_file(
sources=sources,
destination=destination,
ref=ref,
with_metadata=with_metadata,
urlscontext=urlscontext,
progress=progress,
interactive=interactive,
Expand Down Expand Up @@ -247,14 +245,11 @@ def _add_to_dataset(
click.echo(WARNING + msg)

if with_metadata:
for file_ in dataset.files:
file_.based_on = None
# dataset has the correct list of files
with_metadata.files = dataset.files
with_metadata.url = dataset._id

dataset.update_metadata_from(with_metadata)
dataset.same_as = with_metadata.same_as

except DatasetNotFound:
raise DatasetNotFound(
Expand Down Expand Up @@ -296,7 +291,7 @@ def file_unlink(client, name, include, exclude, interactive=False, yes=False, co
(
"include or exclude filters not found.\n"
"Check available filters with `renku dataset unlink --help`\n"
"Hint: `renku dataset unlink mydataset -I myfile`"
"Hint: `renku dataset unlink my-dataset -I path`"
)
)

Expand Down Expand Up @@ -649,9 +644,9 @@ def _filter(client, names=None, creators=None, include=None, exclude=None):

if unused_names:
unused_names = ", ".join(unused_names)
raise ParameterError(f"Dataset doesn't exist: {unused_names}")
raise ParameterError(f"Dataset does not exist: {unused_names}")

return sorted(records, key=lambda file_: file_.added)
return sorted(records, key=lambda r: r.added)


@pass_local_client(
Expand Down
6 changes: 4 additions & 2 deletions renku/core/models/datasets.py
Expand Up @@ -350,16 +350,16 @@ class Dataset(Entity, CreatorMixin, ReferenceMixin):

EDITABLE_FIELDS = [
"creators",
"date_created",
"date_published",
"description",
"files",
"in_language",
"keywords",
"license",
"title",
"url",
"version",
"date_created",
"files",
]

_id = attr.ib(default=None, kw_only=True)
Expand Down Expand Up @@ -491,6 +491,8 @@ def update_metadata_from(self, other_dataset):
self._modified = True
setattr(self, field_, val)

self.same_as = other_dataset.same_as

return self

def update_files(self, files):
Expand Down
10 changes: 7 additions & 3 deletions tests/cli/test_integration_datasets.py
Expand Up @@ -314,9 +314,13 @@ def test_import_renku_dataset_preserves_directory_hierarchy(runner, project, cli
assert 0 == runner.invoke(cli, ["dataset", "import", "--yes", "--name", "remote", url]).exit_code

dataset = client.load_dataset("remote")
assert (client.path / dataset.data_dir / "README.md").exists()
assert (client.path / dataset.data_dir / "python" / "data" / "README.md").exists()
assert (client.path / dataset.data_dir / "r" / "data" / "README.md").exists()
paths = ["README.md", os.path.join("python", "data", "README.md"), os.path.join("r", "data", "README.md")]

for path in paths:
assert (client.path / dataset.data_dir / path).exists()
file_ = dataset.find_file(dataset.data_dir / path)
assert file_.based_on
assert file_.based_on.path.endswith(path)


@pytest.mark.integration
Expand Down

0 comments on commit 3aee6b8

Please sign in to comment.