Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize spaces and ,s in organized filenames #1351

Merged
merged 1 commit into from
Nov 9, 2023
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
6 changes: 4 additions & 2 deletions dandi/organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def _sanitize_value(value, field):
Of particular importance is _ which we use, as in BIDS, to separate
_key-value entries
"""
value = re.sub(r"[_*\\/<>:|\"'?%@;]", "-", value)
value = re.sub(r"[_*\\/<>:|\"'?%@;,\s]", "-", value)
if field != "extension":
value = value.replace(".", "-")
return value
Expand Down Expand Up @@ -814,7 +814,9 @@ def _get_metadata(path):
meta["path"] = path
return meta

if not devel_debug and jobs != 1: # Do not use joblib at all if number_of_jobs=1
if (
not devel_debug and jobs != 1
): # Do not use joblib at all if number_of_jobs=1
# Note: It is Python (pynwb) intensive, not IO, so ATM there is little
# to no benefit from Parallel without using multiproc! But that would
# complicate progress bar indication... TODO
Expand Down
17 changes: 15 additions & 2 deletions dandi/tests/test_organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def test_sanitize_value() -> None:
assert _sanitize_value("_.ext", "extension") == "-.ext"
assert _sanitize_value("_.ext", "unrelated") == "--ext"
assert _sanitize_value("A;B", "unrelated") == "A-B"
# no spaces or tabs please
assert _sanitize_value("A B\t C", "unrelated") == "A-B--C"
assert _sanitize_value("A;B,C", "unrelated") == "A-B-C"
assert _sanitize_value("A\\/B", "unrelated") == "A--B"
assert _sanitize_value("A\"'B", "unrelated") == "A--B"

Expand Down Expand Up @@ -111,7 +114,9 @@ def c() -> Any: # shortcut
@pytest.mark.integration
@pytest.mark.parametrize("mode", no_move_modes)
@pytest.mark.parametrize("jobs", (1, -1))
def test_organize_nwb_test_data(nwb_test_data: Path, tmp_path: Path, mode: str, jobs: int) -> None:
def test_organize_nwb_test_data(
nwb_test_data: Path, tmp_path: Path, mode: str, jobs: int
) -> None:
outdir = tmp_path / "organized"

relative = False
Expand Down Expand Up @@ -153,7 +158,15 @@ def test_organize_nwb_test_data(nwb_test_data: Path, tmp_path: Path, mode: str,

input_files = nwb_test_data / "v2.0.1"

cmd = ["-d", str(outdir), "--files-mode", mode, str(input_files), "--jobs", str(jobs)]
cmd = [
"-d",
str(outdir),
"--files-mode",
mode,
str(input_files),
"--jobs",
str(jobs),
]
r = CliRunner().invoke(organize, cmd)

# with @map_to_click_exceptions we loose original str of message somehow
Expand Down