Skip to content

Commit

Permalink
Update updated spec name, declare spec for tests (#369)
Browse files Browse the repository at this point in the history
* Update updated spec name, declare spec for tests

* Show git diff on update-bids failure

* Exclude control characters from yaml tests
    These expose a bug in ruamel round-tripping (not critical for our
    application)
  • Loading branch information
pvandyken authored Feb 15, 2024
1 parent 8acbd9f commit 8fce792
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion snakebids/paths/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_0_0", "v0_11_0", "latest"]
# </AUTOUPDATE>

__all__ = ["set_bids_spec"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
6 changes: 3 additions & 3 deletions snakebids/paths/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#
if not TYPE_CHECKING:
__all__ = [ # noqa:F822
"v0_10_1",
"v0_0_0",
"v0_11_0",
"latest",
"LATEST",
]
Expand All @@ -25,8 +25,8 @@ def __dir__():
return __all__


_SPECS = ["v0_10_1", "v0_0_0"]
# LATEST = "v0_10_1"
_SPECS = ["v0_0_0", "v0_11_0"]
# LATEST = "v0_11_0"
# </AUTOUPDATE>

# To automatically use latest spec as "LATEST", remove this line and uncomment the
Expand Down
58 changes: 29 additions & 29 deletions snakebids/paths/specs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,21 @@ from ._utils import BidsPathSpec

LATEST: str

def v0_10_1(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.
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
Expand All @@ -41,21 +35,27 @@ def v0_10_1(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
Expand All @@ -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/
Expand Down
5 changes: 3 additions & 2 deletions snakebids/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion snakebids/tests/test_paths/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions snakebids/tests/test_paths/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
2 changes: 1 addition & 1 deletion snakebids/tests/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 8fce792

Please sign in to comment.