Skip to content

[ENH] Use BIDS schema to "drive" pybids #818#1163

Merged
effigies merged 13 commits intobids-standard:mainfrom
astewartau:schema-integration
Jan 8, 2026
Merged

[ENH] Use BIDS schema to "drive" pybids #818#1163
effigies merged 13 commits intobids-standard:mainfrom
astewartau:schema-integration

Conversation

@astewartau
Copy link
Contributor

This is my first PR as a BIDS maintainer. Appreciate any feedback! This attempts to address #818.

Summary

  • Implement schema-driven BIDSLayout configuration loading
  • Enables version-specific schema loading via bidsschematools
  • Existing JSON-based config is unchanged

Implementation

  • Added Config._from_schema() method that loads schema via bidsschematools.schema.load_schema()
  • Support remote schema loading from versioned URLs (e.g., https://bids-specification.readthedocs.io/en/v1.9.0/schema.json)
  • Extract entity names from schema file rules across raw/deriv/common sections using rules.regexify_filename_rules()
  • Generate Entity objects with regex patterns derived from schema format definitions (bids_schema.objects.formats)
  • Combine BIDS entity prefixes with schema format patterns (e.g., sub- + [0-9a-zA-Z]+ for subjects)
  • Special entities (suffix, extension, datatype) still require some special handling logic

Usage

# Load from current schema
config = Config.load('bids-schema')

# Load specific BIDS version
config = Config.load({'schema_version': '1.9.0'})

@astewartau astewartau closed this Sep 9, 2025
@astewartau astewartau deleted the schema-integration branch September 9, 2025 06:35
@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 90.97345% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.48%. Comparing base (504a861) to head (476d32f).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
...ids/layout/tests/test_schema_pattern_validation.py 77.55% 10 Missing and 12 partials ⚠️
...rc/bids/layout/tests/test_schema_vs_json_config.py 88.19% 8 Missing and 11 partials ⚠️
src/bids/layout/layout.py 93.93% 0 Missing and 4 partials ⚠️
src/bids/layout/tests/test_schema_config.py 94.52% 1 Missing and 3 partials ⚠️
src/bids/layout/models.py 97.93% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1163      +/-   ##
==========================================
+ Coverage   89.34%   89.48%   +0.13%     
==========================================
  Files          66       70       +4     
  Lines        7276     7828     +552     
  Branches      854      951      +97     
==========================================
+ Hits         6501     7005     +504     
- Misses        567      584      +17     
- Partials      208      239      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@astewartau astewartau reopened this Sep 9, 2025
@astewartau astewartau closed this Sep 9, 2025
@astewartau astewartau reopened this Sep 9, 2025
@astewartau astewartau marked this pull request as draft September 9, 2025 06:52
@astewartau astewartau marked this pull request as ready for review September 9, 2025 06:53
@bendhouseart
Copy link
Contributor

Awesome, will start with trying the notebook!

Copy link
Contributor

@bendhouseart bendhouseart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sold!

Legacy initialization: 1.531 seconds
Schema initialization: 1.282 seconds

Difference: 0.249 seconds
Schema is faster by 16.3%

Get the CI passing and will approve, although I think folks will want to increase coverage, so maybe that too?

astewartau and others added 7 commits September 23, 2025 13:06
=== Do not change lines below ===
{
 "chain": [],
 "cmd": "uv lock",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [
  "pyproject.toml"
 ],
 "outputs": [
  "uv.lock"
 ],
 "pwd": "."
}
^^^ Do not change lines above ^^^
@astewartau
Copy link
Contributor Author

Hi @bendhouseart, I've improved code coverage, and CI looks to be passing. :)

Copy link
Contributor

@bendhouseart bendhouseart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍

@effigies effigies merged commit d3a68ce into bids-standard:main Jan 8, 2026
23 checks passed
effigies added a commit that referenced this pull request Mar 12, 2026
Version 0.22.0 (March 11, 2026)

New feature release in the 0.22.x series.

This release introduces schema-based layout configurations::

    from bids.layout import BIDSLayout

    layout = BIDSLayout('/path/to/dataset', config='bids-schema')

This will use the version of the schema included in
the installed version of bidsschematools_.
The schema configuration will be the way to incorporate updates from
new versions of BIDS (v1.11+), and will eventually be made the default
configuration.
Please try it out and report any issues you encounter
to help us make the transition as smooth as possible.
We are particularly interested in reports from
users who supply custom configurations.

The following dependencies have been updated to new minimum versions:

* NumPy 1.25
* SciPy 1.11
* NiBabel 5.1

* ENH: Sort BIDS file name entities (#1220)
* ENH: Use BIDS schema to "drive" pybids #818 (#1163)
* DOC: Fix documentation deployment (#1224)
* MNT: Add Python 3.14 tests (#1175)
* MNT: Skip pre-release checks on unlabeled PRs (#1188)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants