Skip to content

Commit 04411dd

Browse files
committed
rf: Use data.load_resource instead of files()
1 parent f0c39e5 commit 04411dd

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

tools/schemacode/src/bidsschematools/__main__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
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-
10+
from .data import load_resource
1511
from .rules import regexify_filename_rules
1612
from .schema import export_schema, load_schema
1713
from .utils import configure_logger, get_logger
@@ -52,7 +48,7 @@ def export(ctx, schema, output):
5248
@click.pass_context
5349
def export_metaschema(ctx, output):
5450
"""Export BIDS schema to JSON document"""
55-
metaschema = files("bidsschematools.data").joinpath("metaschema.json").read_text()
51+
metaschema = load_resource("metaschema.json").read_text()
5652
if output == "-":
5753
print(metaschema, end="")
5854
else:

tools/schemacode/src/bidsschematools/schema.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33
import json
44
import os
55
import re
6-
import sys
76
import tempfile
87
from collections.abc import Iterable, Mapping
98
from copy import deepcopy
109
from functools import lru_cache
1110

1211
from jsonschema import ValidationError, validate
1312

14-
if sys.version_info < (3, 9):
15-
from importlib_resources import files
16-
else:
17-
from importlib.resources import files
18-
1913
from . import __bids_version__, __version__, utils
14+
from .data import load_resource
2015
from .types import Namespace
2116

2217
lgr = utils.get_logger()
@@ -298,7 +293,7 @@ def filter_schema(schema, **kwargs):
298293

299294
def validate_schema(schema: Namespace):
300295
"""Validate a schema against the BIDS metaschema."""
301-
metaschema = json.loads(files("bidsschematools.data").joinpath("metaschema.json").read_text())
296+
metaschema = json.loads(load_resource("metaschema.json").read_text())
302297

303298
# validate is put in this try/except clause because the error is sometimes too long to
304299
# print in the terminal

0 commit comments

Comments
 (0)