dandi_compute_code.dandiset#

class dandi_compute_code.dandiset.AssetMetadata(path, date_modified, content_size, content_id)[source]#

Bases: object

Minimal indexed metadata for one asset path.

Parameters:
  • path (str)

  • date_modified (str)

  • content_size (int)

  • content_id (str)

path: str#
date_modified: str#
content_size: int#
content_id: str#
class dandi_compute_code.dandiset.AssetsJsonldMetadata(content_id_to_asset, path_to_asset_metadata)[source]#

Bases: object

Indexed metadata loaded from DANDI assets.jsonld.

Parameters:
content_id_to_asset: dict[str, dict[str, object]]#
path_to_asset_metadata: dict[str, AssetMetadata]#
dandi_compute_code.dandiset.delete_dandiset_version(dandiset_directory, version)[source]#

Delete all version-{version} directories from the DANDI archive and the local filesystem.

Scans {dandiset_directory}/derivatives/dandiset-*/ for directories named version-{version} at any depth, runs dandi delete on each one (answering the interactive confirmation prompt automatically), and then removes the local directory tree.

Parameters:
  • dandiset_directory (Path) – Path to a local clone of the dandiset repository.

  • version (str) – The base version string to delete (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.

Returns:

A list of version directories that were deleted, in sorted order.

Return type:

list[Path]

Raises:

RuntimeError – If the DANDI_API_KEY environment variable is not set or is blank.

dandi_compute_code.dandiset.load_assets_jsonld_metadata(dandiset_id='001697')[source]#

Load content-id and path metadata from a DANDI draft assets.jsonld stream.

Parameters:

dandiset_id (str) – The Dandiset whose draft assets.jsonld is loaded. Defaults to the job capsules Dandiset (001697), where jobs run; pass the failed runs archive Dandiset (001873) to describe the archived state instead.

Returns:

Indexed assets metadata.

Return type:

AssetsJsonldMetadata

dandi_compute_code.dandiset.move_job_capsule(
*,
capsule_path,
source_dandiset_id='001697',
target_dandiset_id='001873',
processing_directory=None,
test=False,
)[source]#

Move a single job capsule folder from one Dandiset to another.

The capsule subtree is downloaded from source_dandiset_id into a fresh temporary working tree via dandi download --preserve-tree, copied under a locally materialized copy of the target_dandiset_id tree, uploaded via dandi upload --allow-any-path, and only then removed from source_dandiset_id via dandi delete. The temporary working tree is removed on success. Each step is restricted to the single capsule subtree so the operation touches the minimum number of assets.

The path of the capsule inside the Dandiset is preserved exactly. Only the enclosing Dandiset changes. Deletion from the source happens only after the upload to the target succeeds, so a failed upload never destroys the original.

Parameters:
  • capsule_path (str) – Path of the job capsule folder relative to the Dandiset root (for example derivatives/dandiset-000409/sub-mouse01/pipeline-aind+ephys/ version-v1.0_params-default_config-abc123_attempt-1).

  • source_dandiset_id (str) – Dandiset the capsule is moved from. Defaults to the job capsules Dandiset (001697).

  • target_dandiset_id (str) – Dandiset the capsule is moved to. Defaults to the failed runs archive Dandiset (001873).

  • processing_directory (Path | None) – Directory in which the temporary per-capsule working tree is created. When None, the system default temporary location is used.

  • test (bool) – When True, leave the temporary working tree on disk after a successful move for debugging.

Raises:

RuntimeError – If DANDI_API_KEY is unset or blank, or if any dandi subprocess returns a non-zero exit code. The temporary working tree is intentionally left in place when any step fails so that it can be inspected.

Return type:

None

dandi_compute_code.dandiset.scan_version_directories(dandiset_directory, version)[source]#

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.

Parameters:
  • dandiset_directory (Path) – Path to a local clone of the dandiset repository.

  • version (str) – 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.

Returns:

Sorted list of matching version directory paths.

Return type:

list[Path]