feat: add schema and entity helper utilities - #107
Open
kaitj wants to merge 4 commits into
Open
Conversation
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
effigies
reviewed
Aug 10, 2026
Comment on lines
+223
to
+227
| _FORMAT_RE: dict[str, str] = { | ||
| "label": "[a-zA-Z0-9]+", | ||
| "index": "[0-9]+", | ||
| "special": ".+", | ||
| } |
Contributor
There was a problem hiding this comment.
Note that label and index are found in schema.objects.formats. Label should support plus (+) characters.
https://github.com/bids-standard/bids-specification/blob/bb1df92/src/schema/objects/formats.yaml#L21
Contributor
Author
There was a problem hiding this comment.
Thanks! These are now derived from the schema with the "special" fallback and stored as part of the adapter in 219b02f instead of the hardcoded regex pattern mapping.
Benchmark Results
|
kaitj
force-pushed
the
feat/generalize-ents/phase1
branch
from
August 11, 2026 20:51
219b02f to
6011261
Compare
4 tasks
kaitj
marked this pull request as ready for review
August 20, 2026 18:14
kaitj
force-pushed
the
feat/generalize-ents/phase1
branch
2 times, most recently
from
August 27, 2026 20:30
6d659e2 to
b418662
Compare
Add `rules` field to BIDSSchemaAdapter storing `schema["rules"].to_dict()`
so downstream helpers can query directories, files, and tabular data
without re-loading the schema. The `Namespace` cannot be pickled
(circular references), so the dict representation is used with
`hash=False` to keep adapter hashing stable (similar to entities).
Add three schema helper functions:
- get_dataset_types(adapter) — returns dataset type keys ("study", "raw", "derivative")
- get_json_data_suffixes(adapter) — derives JSON data file suffixes from
rules.files/tabular_data, replacing the previously hardcoded {"coordsystem"}
- get_entity_directory_order(adapter) — BFS over rules.directories to return
depth-ordered deque of entity prefixes (e.g. sub, tpl, ses, cohort)
All helpers accept the adapter (not spec) to ensure the queried rules
correspond to the same schema spec used to build the adapter, avoiding
repeated load_schema calls.
Add schema-driven helper functions for querying BIDS entity metadata, replacing hardcoded entity assumptions. New functions in _entities.py: - get_entity_name() — map entity type to short prefix (e.g. "subject" -> "sub") - get_entity_regex() — compiled regex for prefix-value matching - get_entity_glob_pattern() — glob pattern for entity discovery - get_root_entity_types() — root-level directory entity prefixes - get_file_entity_prefixes() — non-directory, non-special entity prefixes Unknown entity types return None and log a warning instead of raising, matching the graceful degradation pattern used throughout bids2table. get_file_entity_prefixes excludes all directory entities via get_entity_directory_order() (not just root-level ones), so ses, cohort, and future directory entities are also filtered out. Adds a module-scoped adapter fixture to conftest.py so tests load the BIDS schema once instead of repeatedly.
Extract label and index format patterns from schema.objects.formats
instead of hardcoding them. This ensures regex patterns stay in sync
with the BIDS schema version.
The adapter now carries a `format_patterns` dict with only the
entity-relevant formats ("label", "index"). "special" is added as a
fallback since it is not defined in the BIDS schema.
kaitj
force-pushed
the
feat/generalize-ents/phase1
branch
from
September 2, 2026 17:38
b418662 to
6d980c1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR
Phase 1 of the generalized entities refactor (supersedes #86). Adds a schema-driven helper function for querying BIDS entities in order to replace hard coded entity assumptions in downstream phases.
_schema.py — 3 new functions:
_entities.py — 5 new functions:
All three entity lookup functions gracefully handle unknown entities by returning None and logging a warning.
Type of Change
Related Issue(s)
Stack created with GitHub Stacks CLI • Give Feedback 💬