Skip to content

Commit

Permalink
Fix warning messages
Browse files Browse the repository at this point in the history
All the warnings were displaying the wrong stack level: now corrected to
show user code rather than snakebids code.

The warnings relating to bids were poorly worded or slightly inaccurate.
These have been corrected
  • Loading branch information
pvandyken committed Feb 20, 2024
1 parent de838a5 commit 45ce959
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
8 changes: 4 additions & 4 deletions snakebids/core/input_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,14 @@ def _normalize_database_args(
"The parameter `pybids_database_dir` in generate_inputs() is deprecated "
"and will be removed in the next release. To set the pybids database, use "
"the `pybidsdb_dir` parameter instead.",
stacklevel=1,
stacklevel=3,
)
if pybids_reset_database is not None:
warnings.warn(
"The parameter `pybids_reset_database` in generate_inputs() is deprecated "
"and will be removed in the next release. To reset the pybids database, "
"use the `pybidsdb_reset` parameter instead.",
stacklevel=1,
stacklevel=3,
)

pybidsdb_dir = pybidsdb_dir or pybids_database_dir
Expand All @@ -361,7 +361,7 @@ def _normalize_database_args(
"The config value `pybids_db_dir` is deprecated and will be removed in a "
"future release. To access a CLI-specified pybids database directory, use "
'`config.get("pybidsdb_dir")` instead.',
stacklevel=1,
stacklevel=3,
)
pybidsdb_dir = str(pybidsdb_dir)[depr_len:-depr_len]
try:
Expand All @@ -375,7 +375,7 @@ def _normalize_database_args(
"The config value `pybids_db_reset` is deprecated and will be removed "
"in a future release. To access CLI-specified pybids database reset "
'instructions, use `config.get("pybidsdb_reset")` instead.',
stacklevel=1,
stacklevel=3,
)
except ValueError as err:
msg = "pybidsdb_reset must be a boolean"
Expand Down
39 changes: 21 additions & 18 deletions snakebids/paths/_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def _handle_subses_dir(
"will be removed in a future release. Builder functions without "
"directories can be created using the bids_factory and spec "
"functions:\n"
" from snakebids.paths import set_bids_spec, specs\n"
" set_bids_spec(specs.v0_0_0(subject_dir=False, "
"session_dir=False))"
)
warnings.warn(wrn_msg, stacklevel=1)
"\tfrom snakebids.paths import bids_factory, specs\n"
"\tbids_ses = bids_factory(specs.v0_0_0(subject_dir=False))\n"
"\tbids_ses(...)\n"
).expandtabs(4)
warnings.warn(wrn_msg, stacklevel=4)
if newspec:
return bids_factory(newspec)(
root,
Expand Down Expand Up @@ -226,18 +226,6 @@ def bids(
for key, value in parsed.items():
custom_parts.append(f"{key}-{value}")

if custom_parts and _implicit and not in_interactive_session():
wrn_msg = (
f"The segment '{custom_parts}' has custom entities not part of the "
"current BIDS spec, but a spec has not been explicitly declared. This "
"could break when snakebids is upgraded, as specs can be updated "
"without warning, and these entities may be included in future specs. "
"Please declare a spec using:\n"
" from snakebids import set_bids_spec\n"
f' set_bids_spec("{specs.LATEST}")'
)
warnings.warn(wrn_msg, stacklevel=1)

if datatype:
path_parts.append(datatype)
path_parts.append(
Expand All @@ -246,6 +234,21 @@ def bids(

tail = f"_{suffix}{extension or ''}" if suffix else extension or ""

return os.path.join(*path_parts) + tail
result = os.path.join(*path_parts) + tail
if custom_parts and _implicit and not in_interactive_session():
wrn_msg = (
f"Path generated with custom entities not part of the default BIDS "
"spec, and a spec has not been explicitly declared. This could break "
"when snakebids is upgraded, as the default spec can be updated "
"without warning, and these entities may be included in future specs.\n"
f"\tpath = {result!r}\n"
f"\tentities = {custom_parts!r}\n\n"
"Please declare a spec using:\n"
"\tfrom snakebids import set_bids_spec\n"
f'\tset_bids_spec("{specs.LATEST}")\n'
).expandtabs(4)
warnings.warn(wrn_msg, stacklevel=3)

return result

return bids

0 comments on commit 45ce959

Please sign in to comment.