Skip to content

Commit 5855da4

Browse files
committed
Provide explicit empty suffix so we allow for README without extension
1 parent 56c0f66 commit 5855da4

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

heudiconv/bids.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def populate_bids_templates(
181181
"each sequence, replicating directory hierarchy of the BIDS dataset"
182182
" itself.",
183183
# TODO: get from schema
184-
glob_suffixes=[".md", ".txt", ".rst"],
184+
glob_suffixes=[".md", ".txt", ".rst", ""],
185185
)
186186
create_file_if_missing(
187187
op.join(path, "CHANGES"),
@@ -197,7 +197,7 @@ def populate_bids_templates(
197197
"TODO: Provide description for the dataset -- basic details about the "
198198
"study, possibly pointing to pre-registration (if public or embargoed)",
199199
# TODO: get from schema
200-
glob_suffixes=[".md", ".txt", ".rst"],
200+
glob_suffixes=[".md", ".txt", ".rst", ""],
201201
)
202202
create_file_if_missing(
203203
op.join(path, "scans.json"), json_dumps(SCANS_FILE_FIELDS, sort_keys=False)

heudiconv/tests/test_main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,17 @@ def test_create_file_if_missing(tmp_path: Path) -> None:
6161
assert not tf_base.exists() # was not created, since there is .md
6262

6363
# non-matching glob - change
64-
for g in [".md", ".json"], [".d*", ".*d"], []:
64+
for g in [".md", ".json"], [".d*", ".*d"]:
6565
assert create_file_if_missing(str(tf_base), "content3", glob_suffixes=g)
6666
assert tf_base.read_text() == "content3"
67+
# now that we have suffix less README, we do not match, so we keep creating it
68+
assert create_file_if_missing(str(tf_base), "content4", glob_suffixes=g)
69+
assert tf_base.read_text() == "content4"
70+
# unless we list it explicitly
71+
assert not create_file_if_missing(
72+
str(tf_base), "content5", glob_suffixes=g + [""]
73+
)
74+
assert tf_base.read_text() == "content4"
6775
tf_base.unlink()
6876

6977

heudiconv/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ def create_file_if_missing(
168168
filename: str, content: str, glob_suffixes: list[str] | None = None
169169
) -> bool:
170170
"""Create file if missing, so we do not
171-
override any possibly introduced changes"""
171+
override any possibly introduced changes.
172+
173+
Note: if glob_suffixes list is used, and it is desired
174+
also to allow for original filename to 'match', add an empty
175+
string within glob_suffixes.
176+
"""
172177
if glob_suffixes:
173178
if any(glob(filename + s) for s in glob_suffixes):
174179
return False

0 commit comments

Comments
 (0)