Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad-alisafaee committed Feb 26, 2021
1 parent 8446437 commit 35461fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
13 changes: 8 additions & 5 deletions renku/core/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,24 +894,27 @@ def is_dataset_name_valid(name):

def generate_default_name(dataset_title, dataset_version=None):
"""Get dataset name."""
max_length = 24
# For compatibility with older versions use name as name
# if it is valid; otherwise, use encoded name
if is_dataset_name_valid(dataset_title):
return dataset_title

slug = get_slug(dataset_title)
slug = slug.lower()[:24]
name = slug[:max_length]

if dataset_version:
version_slug = get_slug(dataset_version)
return f"{slug}_{version_slug}"
max_version_length = 10
version_slug = get_slug(dataset_version)[:max_version_length]
name = f"{name[:-(len(version_slug) + 1)]}_{version_slug}"

return slug
return name


def get_slug(name):
"""Create a slug from name."""
no_space = re.sub(r"\s+", "_", name)
lower_case = name.lower()
no_space = re.sub(r"\s+", "_", lower_case)
normalized = unicodedata.normalize("NFKD", no_space).encode("ascii", "ignore").decode("utf-8")
no_invalid_characters = re.sub(r"[^a-zA-Z0-9._-]", "_", normalized)
no_duplicates = re.sub(r"([._-])[._-]+", r"\1", no_invalid_characters)
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/test_integration_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
[
{
"doi": "10.5281/zenodo.2658634",
"name": "pyndl_naive_discriminati_v0.6.4",
"name": "pyndl_naive_discr_v0.6.4",
"creator": "Konstantin Sering, Marc Weitz, David-Elias Künstle, Lennart Schneider",
"version": "v0.6.4",
},
{
"doi": "10.7910/DVN/F4NUMR",
"name": "replication_data_for_cam_2.2",
"name": "replication_data_for_2.2",
"creator": "James Druckman, Martin Kifer, Michael Parkin",
"version": "2",
},
Expand Down Expand Up @@ -171,7 +171,7 @@ def test_dataset_import_real_doi_warnings(runner, project, sleep_after):

result = runner.invoke(cli, ["dataset", "ls"])
assert 0 == result.exit_code, result.output + str(result.stderr_bytes)
assert "pyndl_naive_discriminat" in result.output
assert "pyndl_naive_discr_v0.7.2" in result.output


@pytest.mark.parametrize(
Expand Down
1 change: 1 addition & 0 deletions tests/core/commands/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def test_cannot_mutate_immutable_dataset():
@pytest.mark.parametrize(
"name, slug",
[
("UPPER-CASE", "upper-case"),
(" a name ", "a_name"),
("..non-alphanumeric start or end-_", "non-alphanumeric_start_or_end"),
("double ..__._- non-alphanumeric", "double_non-alphanumeric"),
Expand Down

0 comments on commit 35461fd

Please sign in to comment.