Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
18 changes: 10 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
```

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 9 additions & 10 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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())
```

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down