diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa74100..3981649e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,8 @@ A new public function, `get_available_hed_versions()`, lists the HED schema vers ```python from hed.schema import get_available_hed_versions, load_schema_version -choices = get_available_hed_versions() # ['8.4.0', '8.3.0', ...] — listing calls only -if choices: # empty if GitHub is unreachable or rate-limited +choices = get_available_hed_versions() # ['8.4.0', '8.3.0', ...] — listing calls only +if choices: # empty if GitHub is unreachable or rate-limited schema = load_schema_version(choices[0]) # this is the step that downloads schema content ``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index afb6a448..e4a5ecfc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -133,16 +133,16 @@ We use several tools to maintain code quality: Example docstring: ```python -def validate_hed_string(hed_string, schema)->list[dict]: +def validate_hed_string(hed_string, schema) -> list[dict]: """Validate a HED string against a schema. - + Parameters: hed_string (str): The HED string to validate. schema (HedSchema): The schema to validate against. - + Returns: list: A list of validation issues, empty if valid. - + Example: >>> schema = load_schema_version('8.4.0') >>> issues = validate_hed_string("Event", schema) @@ -173,22 +173,24 @@ Example test: import unittest from hed import HedString, load_schema + class TestHedValidation(unittest.TestCase): @classmethod def setUpClass(cls): - cls.schema = load_schema_version('8.4.0') - + cls.schema = load_schema_version("8.4.0") + def test_valid_hed_string(self): hed_string = HedString("Event", self.schema) issues = hed_string.validate() self.assertEqual(len(issues), 0) - + def test_invalid_hed_string(self): hed_string = HedString("InvalidTag", self.schema) issues = hed_string.validate() self.assertGreater(len(issues), 0) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() ``` diff --git a/README.md b/README.md index 12c0cd21..333b077d 100644 --- a/README.md +++ b/README.md @@ -287,7 +287,8 @@ By default, HED schemas are cached in `~/.hedtools/` (location varies by OS). ```python # Change the cache directory import hed -hed.schema.set_cache_directory('/custom/path/to/cache') + +hed.schema.set_cache_directory("/custom/path/to/cache") ``` Starting with `hedtools 0.2.0`, local copies of recent schema versions are bundled within the package for offline access. diff --git a/docs/user_guide.md b/docs/user_guide.md index adeec011..0184c79e 100644 --- a/docs/user_guide.md +++ b/docs/user_guide.md @@ -113,7 +113,9 @@ schema = load_schema_version("8.4.0") schema = load_schema("path/to/schema.xml") # Load from URL (this URL is the raw content of a HED standard prerelease) -schema = load_schema("https://raw.githubusercontent.com/hed-standard/hed-schemas/refs/heads/main/standard_schema/prerelease/HED8.5.0.json") +schema = load_schema( + "https://raw.githubusercontent.com/hed-standard/hed-schemas/refs/heads/main/standard_schema/prerelease/HED8.5.0.json" +) ``` **Note:** The released schemas are automatically downloaded and cached in `~/.hedtools/` for offline use. @@ -152,7 +154,6 @@ from hed import HedString, load_schema_version schema = load_schema_version("8.4.0") hed_string = HedString("Red, Blue, Green", schema) issues = hed_string.validate() - ``` ### Validating a BIDS dataset @@ -194,10 +195,7 @@ from hed import TabularInput, load_schema_version schema = load_schema_version("8.4.0") # Load events file with sidecar -tabular = TabularInput( - file="sub-01_task-rest_events.tsv", - sidecar="task-rest_events.json" -) +tabular = TabularInput(file="sub-01_task-rest_events.tsv", sidecar="task-rest_events.json") # Validate the file issues = tabular.validate(schema) @@ -360,8 +358,8 @@ When you call `load_schema_version("8.4.0")`, HEDTools looks for that version in ```python from hed.schema import load_schema_version -schema = load_schema_version("8.4.0") # downloaded and cached on first use -schema = load_schema_version("8.4.0") # reused from disk on every call after that +schema = load_schema_version("8.4.0") # downloaded and cached on first use +schema = load_schema_version("8.4.0") # reused from disk on every call after that ``` Nothing here is fetched again once a version is cached, since released schemas are immutable — the same version number never changes content. @@ -445,8 +443,8 @@ To prepare an environment that won't have network access later (an offline works ```python from hed.schema import cache_xml_versions, set_cache_directory -set_cache_directory("/opt/hed_cache") # optional: a specific location to ship or mount -cache_xml_versions() # downloads every discovered version's full content +set_cache_directory("/opt/hed_cache") # optional: a specific location to ship or mount +cache_xml_versions() # downloads every discovered version's full content ``` This is a much heavier operation than `get_available_hed_versions()` — it downloads every version it finds, not just a listing — so it's meant to be run once (e.g. during image build or setup), not on a request-handling hot path. It's throttled independently (won't re-run within 30 minutes of its last successful run in the same cache folder) to avoid accidental repeated use. @@ -992,6 +990,7 @@ If you are annotating an NWB dataset, the instructions are somewhat similar but ```python # Check cache location from hed.schema import get_cache_directory + print(get_cache_directory()) ``` diff --git a/pyproject.toml b/pyproject.toml index 506ef58d..6ad289db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ docs = [ "furo>=2024.1.29", "sphinx-copybutton>=0.5.2", "myst-parser>=3.0.0", - "sphinx-autodoc-typehints>=1.24.0", + "sphinx-autodoc-typehints>=3.0.0,<3.12.1", "linkify-it-py>=2.0.3", ] test = [ diff --git a/spec_tests/hed-tests b/spec_tests/hed-tests index 9844ab8e..0fd68b1d 160000 --- a/spec_tests/hed-tests +++ b/spec_tests/hed-tests @@ -1 +1 @@ -Subproject commit 9844ab8eaec3c2dafe211e88ee8407a28b1d76ac +Subproject commit 0fd68b1d7b1a6445d0ca23e6e150f6fe390e7a6c