From fe63e700b6d73084325fe63eca24a133b1196780 Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Mon, 5 Feb 2024 17:51:39 -0500 Subject: [PATCH 1/5] Update updated spec name, declare spec for tests --- snakebids/paths/_config.py | 2 +- .../{spec.0.10.1.yaml => spec.0.11.0.yaml} | 8 ++++---- snakebids/paths/specs.py | 6 +++--- snakebids/paths/specs.pyi | 14 +++++++------- snakebids/tests/conftest.py | 5 +++-- 5 files changed, 18 insertions(+), 17 deletions(-) rename snakebids/paths/resources/{spec.0.10.1.yaml => spec.0.11.0.yaml} (83%) diff --git a/snakebids/paths/_config.py b/snakebids/paths/_config.py index 2d2ff0a9..c34ff1a4 100644 --- a/snakebids/paths/_config.py +++ b/snakebids/paths/_config.py @@ -18,7 +18,7 @@ # poetry run poe update-bids # -VALID_SPECS: TypeAlias = Literal["v0_10_1", "v0_0_0", "latest"] +VALID_SPECS: TypeAlias = Literal["v0_11_0", "v0_0_0", "latest"] # __all__ = ["set_bids_spec"] diff --git a/snakebids/paths/resources/spec.0.10.1.yaml b/snakebids/paths/resources/spec.0.11.0.yaml similarity index 83% rename from snakebids/paths/resources/spec.0.10.1.yaml rename to snakebids/paths/resources/spec.0.11.0.yaml index 12e26cb3..db307b3f 100644 --- a/snakebids/paths/resources/spec.0.10.1.yaml +++ b/snakebids/paths/resources/spec.0.11.0.yaml @@ -1,11 +1,11 @@ -version: "v0.10.1" +version: "v0.11.0" description: | Spec corresponding to `BIDS v1.9.0`_. Significantly expanded from the v0.0.0 spec, now including long names for - every relevant entity. In addition to the spec, it includes `from` and `to` - entities intended for transformations. Unknown entities are placed just before - desc, so that the description entity is always last. + every relevant entity. In addition to the official spec, it includes `from` + and `to` entities intended for transformations. Unknown entities are placed + just before desc, so that the description entity is always last. .. _BIDS v1.9.0: https://bids-specification.readthedocs.io/en/v1.9.0/ diff --git a/snakebids/paths/specs.py b/snakebids/paths/specs.py index d8b564f9..28011bc5 100644 --- a/snakebids/paths/specs.py +++ b/snakebids/paths/specs.py @@ -15,7 +15,7 @@ # if not TYPE_CHECKING: __all__ = [ # noqa:F822 - "v0_10_1", + "v0_11_0", "v0_0_0", "latest", "LATEST", @@ -25,8 +25,8 @@ def __dir__(): return __all__ -_SPECS = ["v0_10_1", "v0_0_0"] -# LATEST = "v0_10_1" +_SPECS = ["v0_11_0", "v0_0_0"] +# LATEST = "v0_11_0" # # To automatically use latest spec as "LATEST", remove this line and uncomment the diff --git a/snakebids/paths/specs.pyi b/snakebids/paths/specs.pyi index 2fb5baa4..421dac53 100644 --- a/snakebids/paths/specs.pyi +++ b/snakebids/paths/specs.pyi @@ -7,13 +7,13 @@ from ._utils import BidsPathSpec LATEST: str -def v0_10_1(subject_dir: bool = True, session_dir: bool = True) -> BidsPathSpec: +def v0_11_0(subject_dir: bool = True, session_dir: bool = True) -> BidsPathSpec: """Spec corresponding to `BIDS v1.9.0`_. Significantly expanded from the v0.0.0 spec, now including long names for every - relevant entity. In addition to the spec, it includes `from` and `to` entities - intended for transformations. Unknown entities are placed just before desc, so that - the description entity is always last. + relevant entity. In addition to the official spec, it includes `from` and `to` + entities intended for transformations. Unknown entities are placed just before desc, + so that the description entity is always last. .. _BIDS v1.9.0: https://bids-specification.readthedocs.io/en/v1.9.0/ @@ -73,9 +73,9 @@ def latest(subject_dir: bool = True, session_dir: bool = True) -> BidsPathSpec: """Spec corresponding to `BIDS v1.9.0`_. Significantly expanded from the v0.0.0 spec, now including long names for every - relevant entity. In addition to the spec, it includes `from` and `to` entities - intended for transformations. Unknown entities are placed just before desc, so that - the description entity is always last. + relevant entity. In addition to the official spec, it includes `from` and `to` + entities intended for transformations. Unknown entities are placed just before desc, + so that the description entity is always last. .. _BIDS v1.9.0: https://bids-specification.readthedocs.io/en/v1.9.0/ diff --git a/snakebids/tests/conftest.py b/snakebids/tests/conftest.py index be0b6295..283141c1 100644 --- a/snakebids/tests/conftest.py +++ b/snakebids/tests/conftest.py @@ -10,7 +10,7 @@ from pyfakefs.fake_filesystem import FakeFilesystem import snakebids.paths.resources as specs -from snakebids import resources +from snakebids import resources, set_bids_spec ## Hypothesis profiles @@ -27,9 +27,10 @@ settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "dev")) -# Fixtures +set_bids_spec("v0_0_0") +# Fixtures @pytest.fixture def fakefs( request: pytest.FixtureRequest, From 210332e165fda0125efcb5f0d1a0c06e7ee34a42 Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Sat, 10 Feb 2024 20:43:06 -0500 Subject: [PATCH 2/5] Show git diff on update-bids failure --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9227ca53..f427613f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: run: | poetry run poe update-bids git diff --quiet || ( - git status + git diff echo 'bids specs out of date, run `poetry run poe update-bids`' exit 1 ) From 6447384cd43116c1f71fbb277545ce8417ddfcfc Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Sat, 10 Feb 2024 20:48:20 -0500 Subject: [PATCH 3/5] sort bids specs in update-bids --- scripts/update_bids.py | 2 +- snakebids/paths/_config.py | 2 +- snakebids/paths/specs.py | 4 +-- snakebids/paths/specs.pyi | 52 +++++++++++++++++++------------------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/scripts/update_bids.py b/scripts/update_bids.py index 26a59480..beef1606 100644 --- a/scripts/update_bids.py +++ b/scripts/update_bids.py @@ -133,7 +133,7 @@ def get_latest(versions: Iterable[BidsPathSpecFile]) -> tuple[str, BidsPathSpecF def main(): """update_bids entrypoint.""" - all_specs = list(get_specs()) + all_specs = sorted(get_specs(), key=lambda o: o["version"]) latest_version, latest_spec = get_latest(all_specs) generate_stub( specs, diff --git a/snakebids/paths/_config.py b/snakebids/paths/_config.py index c34ff1a4..fc059edd 100644 --- a/snakebids/paths/_config.py +++ b/snakebids/paths/_config.py @@ -18,7 +18,7 @@ # poetry run poe update-bids # -VALID_SPECS: TypeAlias = Literal["v0_11_0", "v0_0_0", "latest"] +VALID_SPECS: TypeAlias = Literal["v0_0_0", "v0_11_0", "latest"] # __all__ = ["set_bids_spec"] diff --git a/snakebids/paths/specs.py b/snakebids/paths/specs.py index 28011bc5..0f0ff435 100644 --- a/snakebids/paths/specs.py +++ b/snakebids/paths/specs.py @@ -15,8 +15,8 @@ # if not TYPE_CHECKING: __all__ = [ # noqa:F822 - "v0_11_0", "v0_0_0", + "v0_11_0", "latest", "LATEST", ] @@ -25,7 +25,7 @@ def __dir__(): return __all__ -_SPECS = ["v0_11_0", "v0_0_0"] +_SPECS = ["v0_0_0", "v0_11_0"] # LATEST = "v0_11_0" # diff --git a/snakebids/paths/specs.pyi b/snakebids/paths/specs.pyi index 421dac53..893b1578 100644 --- a/snakebids/paths/specs.pyi +++ b/snakebids/paths/specs.pyi @@ -7,27 +7,21 @@ from ._utils import BidsPathSpec LATEST: str -def v0_11_0(subject_dir: bool = True, session_dir: bool = True) -> BidsPathSpec: - """Spec corresponding to `BIDS v1.9.0`_. - - Significantly expanded from the v0.0.0 spec, now including long names for every - relevant entity. In addition to the official spec, it includes `from` and `to` - entities intended for transformations. Unknown entities are placed just before desc, - so that the description entity is always last. +def v0_0_0(subject_dir: bool = True, session_dir: bool = True) -> BidsPathSpec: + """Get the v0.0.0 BidsPathSpec. - .. _BIDS v1.9.0: https://bids-specification.readthedocs.io/en/v1.9.0/ + This spec alone equips :func:`~snakebids.bids` with 2 extra arguments: + ``include_subject_dir`` and ``include_session_dir``. These default to ``True``, but + if set ``False``, remove the subject and session dirs respectively from the output + path. For future specs, this behaviour should be achieved by modifying the spec and + generating a new :func:`~snakebids.bids` function Formatted as:: sub-{subject}/ses-{session}/{datatype}/{prefix}_sub-{subject}_ses-{session}_ - sample-{sample}_task-{task}_tracksys-{tracksys}_acq-{acquisition}_ - ce-{ceagent}_stain-{staining}_trc-{tracer}_rec-{reconstruction}_ - dir-{direction}_run-{run}_mod-{modality}_echo-{echo}_flip-{flip}_ - inv-{inversion}_mt-{mt}_proc-{processed}_part-{part}_space-{space}_ - atlas-{atlas}_seg-{segmentation}_hemi-{hemisphere}_res-{resolution}_ - den-{density}_roi-{roi}_from-{from}_to-{to}_split-{split}_ - recording-{recording}_chunk-{chunk}_model-{model}_subset-{subset}_ - label-{label}_..._desc-{description}_{suffix}{extension} + task-{task}_acq-{acq}_ce-{ce}_rec-{rec}_dir-{dir}_run-{run}_mod-{mod}_ + echo-{echo}_hemi-{hemi}_space-{space}_res-{res}_den-{den}_label-{label}_ + desc-{desc}_..._{suffix}{extension} Parameters @@ -41,21 +35,27 @@ def v0_11_0(subject_dir: bool = True, session_dir: bool = True) -> BidsPathSpec: """ ... -def v0_0_0(subject_dir: bool = True, session_dir: bool = True) -> BidsPathSpec: - """Get the v0.0.0 BidsPathSpec. +def v0_11_0(subject_dir: bool = True, session_dir: bool = True) -> BidsPathSpec: + """Spec corresponding to `BIDS v1.9.0`_. - This spec alone equips :func:`~snakebids.bids` with 2 extra arguments: - ``include_subject_dir`` and ``include_session_dir``. These default to ``True``, but - if set ``False``, remove the subject and session dirs respectively from the output - path. For future specs, this behaviour should be achieved by modifying the spec and - generating a new :func:`~snakebids.bids` function + Significantly expanded from the v0.0.0 spec, now including long names for every + relevant entity. In addition to the official spec, it includes `from` and `to` + entities intended for transformations. Unknown entities are placed just before desc, + so that the description entity is always last. + + .. _BIDS v1.9.0: https://bids-specification.readthedocs.io/en/v1.9.0/ Formatted as:: sub-{subject}/ses-{session}/{datatype}/{prefix}_sub-{subject}_ses-{session}_ - task-{task}_acq-{acq}_ce-{ce}_rec-{rec}_dir-{dir}_run-{run}_mod-{mod}_ - echo-{echo}_hemi-{hemi}_space-{space}_res-{res}_den-{den}_label-{label}_ - desc-{desc}_..._{suffix}{extension} + sample-{sample}_task-{task}_tracksys-{tracksys}_acq-{acquisition}_ + ce-{ceagent}_stain-{staining}_trc-{tracer}_rec-{reconstruction}_ + dir-{direction}_run-{run}_mod-{modality}_echo-{echo}_flip-{flip}_ + inv-{inversion}_mt-{mt}_proc-{processed}_part-{part}_space-{space}_ + atlas-{atlas}_seg-{segmentation}_hemi-{hemisphere}_res-{resolution}_ + den-{density}_roi-{roi}_from-{from}_to-{to}_split-{split}_ + recording-{recording}_chunk-{chunk}_model-{model}_subset-{subset}_ + label-{label}_..._desc-{description}_{suffix}{extension} Parameters From d0a0471419cafac341bc1af5182175f57148451e Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Mon, 12 Feb 2024 22:26:52 -0500 Subject: [PATCH 4/5] fix pyright errors --- snakebids/tests/test_paths/test_bids.py | 2 +- snakebids/tests/test_paths/test_specs.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snakebids/tests/test_paths/test_bids.py b/snakebids/tests/test_paths/test_bids.py index 6303f5d9..12c8ef2e 100644 --- a/snakebids/tests/test_paths/test_bids.py +++ b/snakebids/tests/test_paths/test_bids.py @@ -302,7 +302,7 @@ def test_missing_essential_entities_gives_error(self, args: dict[str, str]): TestV0_0_0 = make_bids_testsuite(specs.v0_0_0()) -TestV0_10_1 = make_bids_testsuite(specs.v0_10_1()) +TestV0_10_1 = make_bids_testsuite(specs.v0_11_0()) def test_benchmark_bids(benchmark: Benchmark): diff --git a/snakebids/tests/test_paths/test_specs.py b/snakebids/tests/test_paths/test_specs.py index 4aa61ec2..367867b7 100644 --- a/snakebids/tests/test_paths/test_specs.py +++ b/snakebids/tests/test_paths/test_specs.py @@ -53,14 +53,14 @@ def test_session_dir_can_be_excluded(): def test_spec_can_be_set_with_str(): set_bids_spec("v0_0_0") assert bids(acquisition="foo") == "acquisition-foo" - set_bids_spec("v0_10_1") + set_bids_spec("v0_11_0") assert bids(acquisition="foo") == "acq-foo" def test_spec_can_be_set_with_obj(): set_bids_spec(specs.v0_0_0()) assert bids(acquisition="foo") == "acquisition-foo" - set_bids_spec(specs.v0_10_1()) + set_bids_spec(specs.v0_11_0()) assert bids(acquisition="foo") == "acq-foo" From 919eb182cf45ac29dce4de8624e1ca6357cf91bf Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Wed, 14 Feb 2024 17:52:16 -0500 Subject: [PATCH 5/5] Exclude control characters from yaml tests These expose a bug in ruamel round-tripping (not critical for our application) --- snakebids/tests/test_yaml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snakebids/tests/test_yaml.py b/snakebids/tests/test_yaml.py index 4efa0422..5272e4dc 100644 --- a/snakebids/tests/test_yaml.py +++ b/snakebids/tests/test_yaml.py @@ -16,7 +16,7 @@ import snakebids.io.yaml as yamlio from snakebids.tests.helpers import allow_function_scoped -YAML_SAFE_CHARS = st.characters(blacklist_characters=["\x85"]) +YAML_SAFE_CHARS = st.characters(blacklist_characters=["\\"], blacklist_categories=["C"]) @given(path=st.text(YAML_SAFE_CHARS, min_size=1).map(Path))