Skip to content

Commit ff60d64

Browse files
authored
Merge pull request #2109 from effigies/maint/pyproject-acres
rf(schemacode): Update packaging, minimum Python, resource loading
2 parents 44c7088 + a63e775 commit ff60d64

17 files changed

+165
-231
lines changed

.github/workflows/schemacode_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
fail-fast: false
6262
matrix:
6363
os: ["ubuntu-latest"]
64-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
64+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
6565
include:
6666
- os: macos-latest
6767
python-version: 3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
src/schema.json
2+
13
site/
24
.DS_Store
35
.idea

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ repos:
7272
- id: mypy
7373
# Sync with project.optional-dependencies.typing
7474
additional_dependencies:
75+
- acres
7576
- click
7677
- markdown-it-py
77-
- importlib_resources
7878
- pandas-stubs
7979
- pyparsing
8080
- pytest

tools/schemacode/MANIFEST.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/schemacode/pyproject.toml

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,98 @@
11
[build-system]
2-
requires = ["setuptools"]
2+
requires = ["setuptools>=61.2"]
33
build-backend = "setuptools.build_meta"
44

5+
[project]
6+
name = "bidsschematools"
7+
description = "Python tools for working with the BIDS schema."
8+
authors = [{name = "bids-standard developers"}]
9+
maintainers = [{name = "bids-standard developers", email = "[email protected]"}]
10+
license = {text = "MIT"}
11+
readme = "README.md"
12+
requires-python = ">=3.9"
13+
dependencies = [
14+
"acres",
15+
"click",
16+
"pyyaml",
17+
]
18+
classifiers = [
19+
"Development Status :: 4 - Beta",
20+
"Intended Audience :: Science/Research",
21+
"Topic :: Scientific/Engineering :: Information Analysis",
22+
"License :: OSI Approved :: MIT License",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Programming Language :: Python :: 3.13",
28+
]
29+
dynamic = ["version"]
30+
31+
[project.optional-dependencies]
32+
validation = [
33+
"jsonschema",
34+
]
35+
doc = [
36+
"sphinx>=1.5.3",
37+
"sphinx_rtd_theme",
38+
]
39+
render = [
40+
"tabulate",
41+
"pandas",
42+
"markdown-it-py",
43+
]
44+
expressions = ["pyparsing"]
45+
tests = [
46+
"bidsschematools[validation,render,expressions]",
47+
"codecov",
48+
"coverage[toml]",
49+
"flake8",
50+
"flake8-black",
51+
"flake8-isort",
52+
"pytest",
53+
"pytest-cov",
54+
]
55+
all = [
56+
"bidsschematools[doc,tests]",
57+
]
58+
59+
[project.scripts]
60+
bst = "bidsschematools.__main__:cli"
61+
62+
[project.urls]
63+
Homepage = "https://github.com/bids-standard/bids-specification"
64+
65+
[tool.setuptools.package-data]
66+
bidsschematools = [
67+
"data/metaschema.json",
68+
"data/schema.json",
69+
"data/schema/BIDS_VERSION",
70+
"data/schema/SCHEMA_VERSION",
71+
"data/schema/**/*.yaml",
72+
"tests/data/*",
73+
]
74+
75+
[tool.setuptools.dynamic]
76+
version = {file = ["src/bidsschematools/data/schema/SCHEMA_VERSION"]}
77+
578
[tool.black]
679
line-length = 99
7-
target-version = ['py37']
880
include = '\.pyi?$'
9-
exclude = '''
10-
(
11-
/(
12-
\.eggs # exclude a few common directories in the
13-
| \.git # root of the project
14-
| \.github
15-
| \.hg
16-
| \.pytest_cache
17-
| _build
18-
| build
19-
| dist
20-
)/
21-
)
22-
'''
2381

2482
[tool.isort]
2583
profile = "black"
2684
multi_line_output = 3
2785

2886
[tool.pytest.ini_options]
87+
addopts = "-ra --strict-markers --strict-config"
88+
log_cli = true
89+
log_cli_level = "INFO"
2990
markers = [
3091
"validate_schema: tests that validate the schema itself",
3192
]
93+
minversion = "6.0"
94+
xfail_strict = true
95+
3296

3397
[tool.coverage.paths]
3498
source = [

tools/schemacode/setup.cfg

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,7 @@
1-
[metadata]
2-
name = bidsschematools
3-
version = file:src/bidsschematools/data/schema/SCHEMA_VERSION
4-
url = https://github.com/bids-standard/bids-specification
5-
author = bids-standard developers
6-
author_email = [email protected]
7-
description = Python tools for working with the BIDS schema.
8-
long_description = file:README.md
9-
long_description_content_type = text/markdown; charset=UTF-8; variant=GFM
10-
license = MIT
11-
classifiers =
12-
Development Status :: 4 - Beta
13-
Intended Audience :: Science/Research
14-
Topic :: Scientific/Engineering :: Information Analysis
15-
License :: OSI Approved :: MIT License
16-
Programming Language :: Python :: 3.8
17-
Programming Language :: Python :: 3.9
18-
Programming Language :: Python :: 3.10
19-
Programming Language :: Python :: 3.11
20-
21-
[options]
22-
python_requires = >=3.8
23-
install_requires =
24-
click
25-
pyyaml
26-
importlib_resources; python_version < "3.9"
27-
jsonschema
28-
zip_safe = false
29-
30-
[options.extras_require]
31-
doc =
32-
sphinx>=1.5.3
33-
sphinx_rtd_theme
34-
render =
35-
tabulate
36-
pandas
37-
markdown-it-py
38-
expressions =
39-
pyparsing
40-
tests =
41-
codecov
42-
coverage[toml]
43-
flake8
44-
flake8-black
45-
flake8-isort
46-
pytest
47-
pytest-cov
48-
all =
49-
%(doc)s
50-
%(render)s
51-
%(tests)s
52-
%(expressions)s
53-
54-
[options.package_data]
55-
bidsschematools =
56-
data/metaschema.json
57-
data/schema/BIDS_VERSION
58-
data/schema/SCHEMA_VERSION
59-
data/schema/**/*.yaml
60-
tests/data/*
61-
62-
[options.entry_points]
63-
console_scripts =
64-
bst=bidsschematools.__main__:cli
65-
661
[flake8]
672
max-line-length = 99
683
exclude = *build/
694
ignore = E203,E402,E722,W503
705
per-file-ignores =
716
*/__init__.py : F401
727
docstring-convention = numpy
73-
74-
[tool:pytest]
75-
log_cli = true

tools/schemacode/src/bidsschematools/__init__.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@
44
.. autodata:: __bids_version__
55
"""
66

7-
try: # Prefer backport to leave consistency to dependency spec
8-
from importlib_resources import files
9-
except ImportError:
10-
from importlib.resources import files # type: ignore
11-
12-
version_file = files("bidsschematools.data") / "schema" / "SCHEMA_VERSION"
13-
__version__ = version_file.read_text().strip()
14-
"Schema version"
15-
16-
bids_version_file = files("bidsschematools.data") / "schema" / "BIDS_VERSION"
17-
__bids_version__ = bids_version_file.read_text().strip()
18-
"BIDS specification version"
7+
__version__: str
8+
__bids_version__: str
9+
10+
__all__ = ("__version__", "__bids_version__")
11+
12+
13+
def __getattr__(attr: str) -> str:
14+
"""Lazily load the schema version and BIDS version from the filesystem."""
15+
from typing import TypeVar
16+
17+
from .data import load
18+
19+
T = TypeVar("T")
20+
21+
def document(obj: T, docstring: str) -> T:
22+
tp = type(obj)
23+
return type(tp.__name__, (tp,), {"__doc__": docstring})(obj)
24+
25+
versions = {
26+
"__version__": ("schema/SCHEMA_VERSION", "Schema version"),
27+
"__bids_version__": ("schema/BIDS_VERSION", "BIDS specification version"),
28+
}
29+
30+
if attr in versions:
31+
resource, docstring = versions[attr]
32+
globals()[attr] = document(load.readable(resource).read_text().strip(), docstring)
33+
return globals()[attr]
34+
35+
raise AttributeError(f"module {__spec__.name!r} has no attribute {attr!r}")

tools/schemacode/src/bidsschematools/__main__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
import click
99

10-
if sys.version_info < (3, 9):
11-
from importlib_resources import files
12-
else:
13-
from importlib.resources import files
14-
1510
from .rules import regexify_filename_rules
1611
from .schema import export_schema, load_schema
1712
from .utils import configure_logger, get_logger
@@ -52,7 +47,9 @@ def export(ctx, schema, output):
5247
@click.pass_context
5348
def export_metaschema(ctx, output):
5449
"""Export BIDS schema to JSON document"""
55-
metaschema = files("bidsschematools.data").joinpath("metaschema.json").read_text()
50+
from .data import load
51+
52+
metaschema = load.readable("metaschema.json").read_text()
5653
if output == "-":
5754
print(metaschema, end="")
5855
else:

tools/schemacode/src/bidsschematools/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import tempfile
33
from pathlib import Path
44
from subprocess import run
5+
from typing import Generator
56

67
import pytest
78

9+
from . import data
10+
811
lgr = logging.getLogger()
912

1013
# This selects a subset of the bids-examples collection to run the test suite on.
@@ -90,12 +93,10 @@ def fixture(tests_data_dir):
9093

9194

9295
@pytest.fixture(scope="session")
93-
def schema_dir():
96+
def schema_dir() -> Generator[str, None, None]:
9497
"""Path to the schema housed in the bids-specification repo."""
95-
from bidsschematools import utils
96-
97-
bids_schema = utils.get_bundled_schema_path()
98-
return bids_schema
98+
with data.load.as_path("schema") as schema_path:
99+
yield str(schema_path)
99100

100101

101102
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)