Source code for dandi_compute_code.dandiset._scan_version_directories
import pathlib
[docs]
def scan_version_directories(dandiset_directory: pathlib.Path, version: str) -> list[pathlib.Path]:
"""
Find all ``version-{version}*`` directories under *dandiset_directory*.
Scans ``{dandiset_directory}/derivatives/dandiset-*/`` and returns every
directory whose name equals ``version-{version}`` or starts with
``version-{version}+`` (to capture hash-suffixed variants such as
``version-v1.0.0+fixes+20abeb6``). Directories not inside a
``dandiset-*`` subtree are ignored.
:param dandiset_directory: Path to a local clone of the dandiset repository.
:type dandiset_directory: pathlib.Path
:param version: The base version string to search for (e.g. ``"v1.0.0"``).
Matches the exact directory ``version-v1.0.0`` as well as any
hash-suffixed variant such as ``version-v1.0.0+fixes+20abeb6``.
:type version: str
:returns: Sorted list of matching version directory paths.
:rtype: list[pathlib.Path]
"""
derivatives = dandiset_directory / "derivatives"
if not derivatives.is_dir():
return []
version_prefix = f"version-{version}"
version_dirs: list[pathlib.Path] = []
for dandiset_path in sorted(derivatives.iterdir()):
if not dandiset_path.is_dir() or not dandiset_path.name.startswith("dandiset-"):
continue
for candidate in sorted(dandiset_path.rglob(f"{version_prefix}*")):
name = candidate.name
if candidate.is_dir() and (name == version_prefix or name.startswith(version_prefix + "+")):
version_dirs.append(candidate)
return version_dirs