Skip to content

feat(fs): typed async-first filesystem core (upathtools.fs) - #14

Draft
phil65 wants to merge 12 commits into
mainfrom
core-fs
Draft

phil65 wants to merge 12 commits into
mainfrom
core-fs

Conversation

@phil65

@phil65 phil65 commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Typed, async-first filesystem core in upathtools.fs, built step by step on this branch. Design: docs/design/core-fs-plan.md (its "Review notes" section overrides the body). Everything is additive: existing modules are untouched until plan Step 7.

Each step: written by Gemini 4 Neon (agy), reviewed and fixed by Claude.

  • Step 1: types, errors, capability protocols, sync metadata
  • Step 2: paths, glob, batch, thread-safe DirCache
  • Step 3a: AsyncFS base + streams + MemoryFS
  • Step 3b: LoopRunner + SyncFS
  • Step 4: from_fsspec / to_fsspec / registry / FilesystemPool + UPath bridge, fsspec.tests.abstract on to_fsspec(MemoryFS())
  • Step 5: LocalFS, DirFS (+ conformance)
  • Step 6: divergence matrix, free-threading stress suite, sync-note test

Status: 1344 passed, 3 strict xfails (fsspec backend quirks, see tests/fs/conformance/DIVERGENCES.md). fsspec's own abstract suite (copy/get/put/open/pipe incl. glob edge cases) passes against to_fsspec(MemoryFS()), to_fsspec(LocalFS()), to_fsspec(DirFS(MemoryFS(), "/root")) and the round trip to_fsspec(from_fsspec(fsspec memory)): 4 x 136 passed, 0 xfails. CI minutes are out until 2026-12-01; verified locally.

Decided (owner, 2026-11-26):

  • coremem alias: dropped, MemoryFS answers to memory only (a9e8de1).
  • copy/move: keep pathlib.Path.copy semantics (exact target, trees, no recursive); to_fsspec keeps fsspec's cp/mv.
  • Free-threaded CI: template option ci_free_threading (copier-phil65 v2.16.1: a 3.14t job on ubuntu, allowed to fail, syncs without extras that lack a free-threaded wheel); on for this repo (0b9311b).
  • reset_after_fork: no upstream PR needed, fsspec master already fixed it (reset_lock()); not in a release yet (2026.9.0 still has it).

Still open before merging: the Windows job fails (70 tests, all LocalFS: get/put/copy conformance and the free-threading stress tests).

Not in this PR: plan Step 7 and later (rewiring existing modules).

🤖 Generated with Claude Code

phil65 and others added 2 commits November 26, 2026 20:15
First step of upathtools.fs (docs/design/core-fs-plan.md, Step 1): FileInfo
(frozen, slots, kw_only; from_fsspec_dict/to_fsspec_dict), GrepMatch, the
error hierarchy, runtime-checkable capability protocols and
FSSPEC_SYNC_VERSION / FsspecSyncNote.

Written by Gemini 4 Neon (agy), reviewed by Claude. Changed in review:
- FileInfo is hashable (extra excluded from the hash, still compared).
- from_fsspec_dict keeps an unparsable timestamp in extra instead of raising.
- ty's override rules are re-enabled for src/upathtools/fs (pyproject override).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.04783% with 266 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.02%. Comparing base (b47a2c6) to head (2c23c48).

Files with missing lines Patch % Lines
src/upathtools/fs/implementations/local.py 87.50% 62 Missing ⚠️
src/upathtools/fs/interop/to_fsspec.py 86.20% 48 Missing ⚠️
src/upathtools/fs/base.py 91.93% 40 Missing ⚠️
src/upathtools/fs/interop/from_fsspec.py 87.08% 31 Missing ⚠️
src/upathtools/fs/implementations/dirfs.py 86.23% 19 Missing ⚠️
src/upathtools/fs/streams.py 93.57% 14 Missing ⚠️
src/upathtools/fs/implementations/memory.py 94.19% 13 Missing ⚠️
src/upathtools/fs/runner.py 91.87% 13 Missing ⚠️
src/upathtools/fs/sync.py 95.67% 10 Missing ⚠️
src/upathtools/fs/pool.py 90.16% 6 Missing ⚠️
... and 4 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #14       +/-   ##
===========================================
+ Coverage   39.95%   51.02%   +11.06%     
===========================================
  Files          82      104       +22     
  Lines       12415    15760     +3345     
===========================================
+ Hits         4960     8041     +3081     
- Misses       7455     7719      +264     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

phil65 and others added 10 commits November 26, 2026 20:34
Step 2 of docs/design/core-fs-plan.md: paths.py (split/strip_protocol,
normalize/parent/join, unchain, check_contained, infer_storage_options,
tokenize), glob.py (glob_translate, compile_glob, has_magic, other_paths),
batch.py (run_bounded: TaskGroup worker pool, ordered results, first error
cancels the rest) and cache.py (DirCache: lock-guarded, TTL, LRU, prefix
invalidation). Each ported module carries __fsspec_sync__; the tests use
fsspec's own functions as the oracle.

Written by Gemini 4 Neon (agy), reviewed by Claude. Changed in review:
- run_bounded(return_exceptions=True) captures Exception only, so
  KeyboardInterrupt / SystemExit are not turned into results.
- DirCache.invalidate(path) also drops the parent's listing (it lists path).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oryFS

Step 3a of docs/design/core-fs-plan.md (as split in its review notes):
- AsyncFS[TInfo]: three required primitives (info, ls, read_bytes), optional
  mutation primitives raising UnsupportedOperation, and derived operations
  (exists/is_file/is_dir that only catch FileNotFoundError and
  NotADirectoryError, level-parallel walk, find, fsspec-style glob, single-pass
  du, read_many, touch, copy/move with pathlib exact-target semantics and
  pre-flight conflict checks, recursive remove, get/put_file, grep, diff, open).
- streams.py: stream protocols, AsyncBufferedReader (block reads over
  read_bytes ranges, seek/readline/iteration), AsyncBufferedWriter (commits on
  close, discards when the async-with body raises; wb/xb/ab).
- MemoryFS: per-instance MemoryStore (optionally shared), one lock never held
  across an await, explicit directories, implicit parents on write, atomic
  native move of files and subtrees.
- tests/fs/contract.py: AsyncFSContract, the backend-independent suite (incl.
  fsspec's GLOB_EDGE_CASES_TESTS), run against MemoryFS; base tests with a
  read-only minimal backend, error propagation and cancellation.

Written by Gemini 4 Neon (agy), reviewed by Claude. Changed in review:
- capabilities lists only native primitives (write_bytes, mkdir, rmdir,
  remove_file, move, grep); derived helpers like copy or touch work everywhere
  and no longer count as a capability when a subclass overrides them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Step 3b of docs/design/core-fs-plan.md (review notes: no fs.sync property,
an explicit SyncFS(fs, runner=...)):
- LoopRunner: a private loop on a lazily started daemon thread, run() with
  Future.result(timeout) (FSTimeoutError, the coroutine is cancelled),
  KeyboardInterrupt cancels the future, a clear RuntimeError on re-entry from
  the runner's own loop, idempotent close(). Fork-safe: every runner and the
  module locks are reset in the child (fsspec's reset_after_fork resets the
  wrong global). get_default_runner() for scripts.
- SyncFS: a hand-written, typed 1:1 mirror of the AsyncFS methods (a test
  guards names, parameters and defaults against drift); open() returns
  SyncFileBridge (io.BufferedIOBase) or a TextIOWrapper for text modes.

Written by Gemini 4 Neon (agy), reviewed by Claude (no changes needed).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ol, UPath bridge

Step 4 of docs/design/core-fs-plan.md:
- to_fsspec / AsFsspecFileSystem: any AsyncFS as an fsspec AsyncFileSystem
  (cachable=False; the sync API runs on a LoopRunner, never on fsspec's
  global fsspecIO thread; glob/find delegate to the core; buffered _open).
  register_fsspec_bridge / register_upath_bridge make fsspec.open(),
  fsspec.filesystem() and plain UPath(...) resolve a core filesystem (an fsspec
  class plus a UPath subclass whose _fs_factory builds the adapter); nothing is
  registered at import time.
- from_fsspec / FsspecAdapter: any fsspec filesystem as an AsyncFS (awaits the
  coroutine hooks of asynchronous=True filesystems, threads for everything
  else, the backend's own path rules, core error semantics on top);
  ensure_async_fs caches one adapter per instance and unwraps to_fsspec.
- ProtocolRegistry (own factories, entry points "upathtools.filesystems",
  fsspec fallback with skip_instance_cache) and FilesystemPool (one instance
  per loop and options, closed and collected loops drop out, aclose_loop).
- fsspec's own abstract suite (copy/get/put/open/pipe incl. the glob edge
  cases) passes against to_fsspec(MemoryFS()) and the round trip
  to_fsspec(from_fsspec(fsspec memory)): 272 passed, no xfails. (fsspec
  2026.9.0 ships mv tests only as functions bound to the local fs.)
- The AsyncFSContract runs against from_fsspec(memory) and from_fsspec(local);
  3 strict xfails, all fsspec backend quirks (error types; mkdir without
  parents not checked by MemoryFileSystem).

Written by Gemini 4 Neon (agy), reviewed by Claude (no changes needed). Small
base changes: remove(recursive) tolerates implied directories that vanished,
copy() compares against root_marker instead of "/".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rest of Step 5 of docs/design/core-fs-plan.md:
- LocalFS (protocols file, local): LocalFSInfo (uid, gid, ino, nlink), all
  blocking calls in threads, lstat-based symlink metadata, ranged reads via
  seek, atomic overwrites (temp file + replace) and O_EXCL creates,
  per-instance auto_mkdir, native move (rename; base copy+remove across
  devices or when merging into an existing directory), ripgrep-rs fast paths
  for grep and for find with hidden/no_ignore filters (falling back to the
  base where ripgrep can't give identical results).
- DirFS: a root-jailed prefix over any AsyncFS[TInfo] (PathEscapeError
  before any I/O, TInfo preserved via dataclasses.replace, native move/find/
  glob/grep of the wrapped fs delegated, no asynchronous flag).
- walk() no longer descends into directory symlinks; remove() unlinks them.
- LocalFS registered as "file"/"local" in the core registry (not in fsspec's).
- fsspec's abstract suite now also passes against to_fsspec(LocalFS()) and
  to_fsspec(DirFS(MemoryFS(), "/root")): 4 x 136 passed, no xfails.

Written by Gemini 4 Neon (agy), reviewed by Claude. Changed in review:
- Atomic writes created the temp file with mkstemp (0600), so every written
  file ended up 0600 and overwrites dropped the file's permissions: the temp
  file is now created with 0666 & ~umask and takes the existing file's mode.
- Writing onto a symlink writes through to its target instead of replacing
  the link (like open("wb")); tests for both.
- DirFS documents that its jail is lexical (symlinks are not resolved).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ync-note gate

Rest of Step 6 of docs/design/core-fs-plan.md:
- tests/fs/conformance/DIVERGENCES.md: every fsspec behaviour upathtools.fs
  intentionally does not replicate, why, and the test pinning it;
  test_divergences.py fails when a referenced test disappears or an xfail of
  test_from_fsspec.py is undocumented.
- test_free_threading.py: 8 threads hammering MemoryFS, LocalFS, DirCache,
  ProtocolRegistry, FilesystemPool, LoopRunner and SyncFS at once (no torn
  files, only the documented races, no leaked threads); reports whether the
  GIL is enabled so a free-threaded run is visible.
- test_sync_notes.py + scripts/check_fsspec_sync.py: every ported module's
  __fsspec_sync__ matches FSSPEC_SYNC_VERSION == uv.lock == installed fsspec,
  and each upstream symbol still resolves in the installed fsspec; the script
  prints the compare URL and exits 1 on drift.

Written by Gemini 4 Neon (agy), reviewed by Claude (no changes needed).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant