Skip to content
This repository was archived by the owner on Feb 22, 2026. It is now read-only.

fix(storage): ensure parent directory exists before opening ZarrStream#65

Merged
jacopoabramo merged 10 commits into
mainfrom
fix/zarr-parent-mkdir
Feb 22, 2026
Merged

fix(storage): ensure parent directory exists before opening ZarrStream#65
jacopoabramo merged 10 commits into
mainfrom
fix/zarr-parent-mkdir

Conversation

@jacopoabramo
Copy link
Copy Markdown
Collaborator

acquire-zarr requires the parent directory of the store URI to exist before ZarrStream is created. _build_writer in redsun creates the base directory at container-build time, but on Windows the file:// URI round-trip (Path.as_uri() -> ZarrStream) can fail to resolve to the same filesystem path that mkdir created, causing:

ZarrStream_s: Parent path '...' does not exist or is not a directory

Fix: add ZarrWriter._ensure_parent(store_uri) called at the top of kickoff(), just before ZarrStream is opened. It parses the file:// URI back to a filesystem path (handling the Windows /C:/... leading slash), and mkdir -p's the parent. Non-file:// URIs (s3://, etc.) are skipped unconditionally.

acquire-zarr requires the parent directory of the store URI to exist
before ZarrStream is created. _build_writer in redsun creates the base
directory at container-build time, but on Windows the file:// URI
round-trip (Path.as_uri() -> ZarrStream) can fail to resolve to the
same filesystem path that mkdir created, causing:

  ZarrStream_s: Parent path '...' does not exist or is not a directory

Fix: add ZarrWriter._ensure_parent(store_uri) called at the top of
kickoff(), just before ZarrStream is opened. It parses the file://
URI back to a filesystem path (handling the Windows /C:/... leading
slash), and mkdir -p's the parent. Non-file:// URIs (s3://, etc.)
are skipped unconditionally.
The previous approach parsed the store URI back to a filesystem path
in _ensure_parent(), but the Windows URI round-trip (Path.as_uri() ->
urlparse -> path_str) produced '/C:/Users/...' which Path() on Windows
interpreted as a rooted path without a drive letter, causing:

  OSError: [WinError 123] The filename, directory name, or volume label
  syntax is incorrect: '\C:\Users\...'

Simpler fix: ZarrWriter now accepts base_dir: Path directly at
construction time. kickoff() calls base_dir.mkdir(parents=True,
exist_ok=True) — a plain Path operation with no URI parsing.
_build_writer in redsun already has base_dir as a Path, so it passes
it straight through. No platform-specific logic needed anywhere.
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/sunflare/storage/_proxy.py 85.71% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/sunflare/storage/__init__.py 100.00% <100.00%> (ø)
src/sunflare/storage/_path.py 96.15% <ø> (ø)
src/sunflare/storage/_zarr.py 92.68% <100.00%> (+50.57%) ⬆️
src/sunflare/storage/_proxy.py 81.08% <85.71%> (+0.43%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…lity

These features were speculative design notes that are not implemented.
Keeping them in the docs creates false expectations. Simplified to
describe only what actually exists: local file:// stores via ZarrWriter.
Previously _HasStorage and _HasStorageMeta lived as private implementation
details in redsun.containers.container, with two TODO comments asking for
them to be moved here.

Changes:
- HasStorageMeta: metaclass that overrides __instancecheck__ to walk the
  MRO looking for a StorageDescriptor, so isinstance(device, HasStorage)
  is True only for devices that have genuinely opted in to storage
- HasStorage: public runtime_checkable Protocol with storage: StorageProxy
  (not StorageProxy | None), so after an isinstance check mypy narrows
  the type without requiring a if device.storage is not None guard
- Both exported from sunflare.storage.__init__ and documented
@jacopoabramo jacopoabramo merged commit 613a957 into main Feb 22, 2026
19 checks passed
@jacopoabramo jacopoabramo deleted the fix/zarr-parent-mkdir branch February 22, 2026 09:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant