neu_vol.location¶
Destination/source locations: local paths, s3:///gs:// URLs, kvstore dicts.
Everything downstream speaks TensorStore kvstore specs (plain dicts), so the ops behave identically for local files and object stores. This module normalizes a user-facing location into a kvstore and joins subpaths uniformly.
Functions¶
|
A copy of |
|
Default manifest path for a destination (local: alongside it; remote: cwd). |
|
Bootstrap object-store credentials for a kvstore that is about to be opened. |
|
True if the object exists. One request; safe against object stores. |
|
True if |
|
Append path segments to a kvstore's |
|
Key names directly under a prefix. |
|
The filesystem path for a local location; raises if it is remote. |
|
Read one object; |
|
Read and parse a JSON object; |
|
Read the half-open byte range |
|
kvstore for a backend spec (handles 'kvstore', 'path', and scheme URLs). |
|
Normalize a location to a TensorStore kvstore spec. |
|
Write one object, creating parent directories for the file driver. |
|
Serialize |
Module Contents¶
- neu_vol.location.as_directory(kvstore: Mapping[str, Any]) dict[str, Any]¶
A copy of
kvstorewhosepathends in/, for a driver given it as a root.
- neu_vol.location.default_progress_path(dst: str | Mapping[str, Any]) str¶
Default manifest path for a destination (local: alongside it; remote: cwd).
A manifest is appended to and fsynced, so for a remote destination it lands in the working directory. Its name then carries a digest of the whole location beside the last component (
seg.4f2a91c7.progress.jsonl), so two destinations ending in the same word never share a manifest, which would make each resume skip the other’s blocks. The digest covers driver, bucket and path only, trailing slash removed, so one destination always maps to one manifest.
- neu_vol.location.ensure_credentials(kvstore: Mapping[str, Any]) dict[str, Any]¶
Bootstrap object-store credentials for a kvstore that is about to be opened.
Call it wherever a store is opened, not where a spec is built: tensorstore’s S3 profile provider cannot read
~/.aws/credentials, so the profile is copied intoAWS_*environment variables, per process. A dask worker that skipped it would get 403s while others succeed.
- neu_vol.location.exists(location: str | Mapping[str, Any], *parts: str) bool¶
True if the object exists. One request; safe against object stores.
- neu_vol.location.is_local(location: str | Mapping[str, Any]) bool¶
True if
locationresolves to an ordinary filesystem path, for callers that need POSIX semantics (sqlite, appended logs) to refuse an object store up front.
- neu_vol.location.join(kvstore: Mapping[str, Any], *parts: str) dict[str, Any]¶
Append path segments to a kvstore’s
path(leading ‘/’ kept for files).
- neu_vol.location.list_keys(location: str | Mapping[str, Any], *parts: str, limit: int | None = None) list[str]¶
Key names directly under a prefix.
limittruncates the result, not the request: tensorstore enumerates the whole prefix first, so a prefix with millions of objects costs the same either way. To ask about one object, probe it by name withexists(); to bound a listing, list a narrower prefix.
- neu_vol.location.local_path(location: str | Mapping[str, Any]) str¶
The filesystem path for a local location; raises if it is remote.
- neu_vol.location.read_bytes(location: str | Mapping[str, Any], *parts: str) bytes | None¶
Read one object;
Noneif it does not exist.
- neu_vol.location.read_json(location: str | Mapping[str, Any], *parts: str)¶
Read and parse a JSON object;
Noneif it does not exist.
- neu_vol.location.read_range(location: str | Mapping[str, Any], start: int, end: int, *parts: str) bytes | None¶
Read the half-open byte range
[start, end)of one object;Noneif absent.A range reaching past the end of the object raises
OUT_OF_RANGE(aValueError) on both the file and S3 drivers. On an object store this is an HTTP Range request.
- neu_vol.location.spec_kvstore(spec: Mapping[str, Any]) dict[str, Any]¶
kvstore for a backend spec (handles ‘kvstore’, ‘path’, and scheme URLs).
- neu_vol.location.to_kvstore(location: str | Mapping[str, Any]) dict[str, Any]¶
Normalize a location to a TensorStore kvstore spec.
Accepts a local path (made absolute,
~expanded), ans3://bucket/prefix/gs://bucket/prefixURL, or an existing kvstore dict.
- neu_vol.location.write_bytes(location: str | Mapping[str, Any], data: bytes, *parts: str) None¶
Write one object, creating parent directories for the file driver.
- neu_vol.location.write_json(location: str | Mapping[str, Any], obj: Any, *parts: str, indent: int | None = 2) None¶
Serialize
objas JSON and write it.