Skip to content

Commit

Permalink
Sort outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Mar 1, 2024
1 parent 9ed0b1b commit 4356742
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion visualdataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
|_|
"""

__version__ = '0.2.1'
__version__ = '0.2.2'
2 changes: 1 addition & 1 deletion visualdataset/brain_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
18 changes: 16 additions & 2 deletions visualdataset/manifest.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
"""
Expand All @@ -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)

0 comments on commit 4356742

Please sign in to comment.