diff --git a/visualdataset/__init__.py b/visualdataset/__init__.py index 79c2a2c..294ab80 100644 --- a/visualdataset/__init__.py +++ b/visualdataset/__init__.py @@ -9,4 +9,4 @@ |_| """ -__version__ = '0.2.1' +__version__ = '0.2.2' diff --git a/visualdataset/brain_dataset.py b/visualdataset/brain_dataset.py index 1b53a20..a55dc31 100644 --- a/visualdataset/brain_dataset.py +++ b/visualdataset/brain_dataset.py @@ -58,7 +58,7 @@ def brain_dataset( ) manifest_path = output_dir / '.chrisvisualdataset.tagmanifest.json' - manifest_path.write_text(manifest.model_dump_json()) + manifest_path.write_text(manifest.sort().model_dump_json()) if readme is not None: readme_path = output_dir / 'README.txt' diff --git a/visualdataset/manifest.py b/visualdataset/manifest.py index e47a4fe..3d3bf7b 100644 --- a/visualdataset/manifest.py +++ b/visualdataset/manifest.py @@ -1,6 +1,7 @@ from pathlib import PurePath +from typing import Sequence, Mapping, Set, Self + from pydantic import BaseModel, ConfigDict -from typing import Sequence, FrozenSet, Tuple, Mapping, Optional, Set from visualdataset.options import ChrisViewerFileOptions @@ -37,7 +38,7 @@ class VisualDatasetManifest(BaseModel): """ A list of all the files and metadata of a "visual dataset". """ - tags: Mapping[str, Set[str]] + tags: Mapping[str, Set[str] | Sequence[str]] """ All known tags and all known values for each tag. """ @@ -55,3 +56,16 @@ class VisualDatasetManifest(BaseModel): """ __pydantic_config__ = ConfigDict(extra='forbid') + + def sort(self) -> Self: + return self.model_copy(update={ + 'tags': { + k: sorted(v) + for k, v in sorted(self.tags.items()) + }, + 'files': sorted(self.files, key=_get_path) + }) + + +def _get_path(x: VisualDatasetFile) -> str: + return str(x.path)