Skip to content

Commit

Permalink
Merge pull request #37 from candleindark/enh
Browse files Browse the repository at this point in the history
Ensure fetching of subdirectories are in order
  • Loading branch information
candleindark authored Dec 5, 2024
2 parents b6b67d5 + a6946ae commit b4963c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/dandisets_linkml_status_tools/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from dandisets_linkml_status_tools.tools import (
compile_dandiset_linkml_translation_report,
create_or_replace_dir,
iter_direct_subdirs,
get_direct_subdirs,
output_reports,
pydantic_validate,
write_reports,
Expand Down Expand Up @@ -240,13 +240,11 @@ def extend_asset_validation_reports() -> None:

dandiset_validation_reports: list[DandisetValidationReport] = []
asset_validation_reports: list[AssetValidationReport] = []
for dandiset_dir in sorted(
iter_direct_subdirs(manifest_path), key=lambda p: p.name
):
for dandiset_dir in get_direct_subdirs(manifest_path):
# === In a dandiset directory ===
dandiset_identifier = dandiset_dir.name

for version_dir in iter_direct_subdirs(dandiset_dir):
for version_dir in get_direct_subdirs(dandiset_dir):
# === In a dandiset version directory ===
dandiset_version = version_dir.name

Expand Down
29 changes: 21 additions & 8 deletions src/dandisets_linkml_status_tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,30 @@
isorted = partial(sorted, key=str.casefold)


def iter_direct_subdirs(path: Path) -> Iterable[Path]:
def iter_direct_subdirs(dir_path: Path) -> Iterable[Path]:
"""
Get an iterable of the direct subdirectories of a given path.
Get an iterable of the direct subdirectories of a given directory
:param path: The given path
:return: The iterable of the direct subdirectories of the given path
:raises: ValueError if the given path is not a directory
:param dir_path: The path of the given directory
:return: The iterable of the direct subdirectories of the given directory.
Note: The subdirectories are yielded in arbitrary order.
:raises: ValueError if the given path doesn't point to a directory
"""
if not path.is_dir():
raise ValueError(f"The given path is not a directory: {path}")
return (p for p in path.iterdir() if p.is_dir())
if not dir_path.is_dir():
raise ValueError(f"The given path is not a directory: {dir_path}")
return (p for p in dir_path.iterdir() if p.is_dir())


def get_direct_subdirs(dir_path: Path) -> list[Path]:
"""
Get a list of the direct subdirectories of a given directory
:param dir_path: The path of the given directory
:return: The list of the direct subdirectories of the given directory in sorted
order by the final component of their path
:raises: ValueError if the given path doesn't point to a directory
"""
return sorted(iter_direct_subdirs(dir_path), key=lambda p: p.name)


def pydantic_validate(data: DandiMetadata | str, model: type[BaseModel]) -> str:
Expand Down

0 comments on commit b4963c4

Please sign in to comment.