Skip to content

Make offline/CI use robust: fetch timeout + JANELIA_PATHLIB_NO_FETCH - #2

Merged
cmalinmayor merged 2 commits into
mainfrom
ci-offline-robustness
Jun 24, 2026
Merged

cmalinmayor merged 2 commits into
mainfrom
ci-offline-robustness

Conversation

@msschwartz21

Copy link
Copy Markdown
Collaborator

Motivation

Downstream projects that construct JaneliaPath in their test suites hit two rough edges when running on a host without access to the Janelia network (e.g. GitHub-hosted CI runners):

  1. _load_shares() raises RuntimeError when there's no cached shares.json and the auto-fetch fails — so any JaneliaPath use crashes offline, with no opt-out short of pre-seeding JANELIA_PATHLIB_SHARES_PATH with a real file.
  2. The fetch has no timeout (urllib.request.urlopen(API_URL)), so on a network that routes to but can't reach the host it can hang the first import.

(Context: adopting janelia-pathlib in a data-conversion project, we had to wrap every call in a try/except + availability probe to keep CI green. These changes would let downstream code use JaneliaPath directly.)

Changes

  • Fetch timeout — urlopen(API_URL, timeout=fetch_timeout()), default 10s, override via JANELIA_PATHLIB_FETCH_TIMEOUT. Pure robustness; no behavior change on a reachable network.
  • JANELIA_PATHLIB_NO_FETCH opt-out — when set and no cache is present, _load_shares() returns [] (no known shares) so paths pass through untranslated instead of raising. Non-share paths already behave exactly like pathlib.Path, so offline code keeps working.

Default behavior is unchanged: a missing cache with no opt-out still raises — the message now also mentions the new flag.

Tests

Added (44 passed, 3 skipped locally):

  • fetch_shares passes a positive timeout to urlopen
  • JANELIA_PATHLIB_FETCH_TIMEOUT override (incl. invalid value → default)
  • NO_FETCH + missing cache → _load_shares() == [] and a share path is left untranslated
  • missing cache without the opt-out still raises RuntimeError (behavior preserved)

README documents both env vars under a new "Running offline (CI)" section.

🤖 Generated with Claude Code

Two changes so the library can be used where the Janelia network is unreachable
(e.g. CI on cloud runners), where the share-data auto-fetch otherwise raises or
could hang:

- Add a timeout to the Fileglancer fetch (default 10s, override via
  JANELIA_PATHLIB_FETCH_TIMEOUT) so an unreachable network can't hang the first
  import indefinitely.
- Add JANELIA_PATHLIB_NO_FETCH: when set and no cache is present, _load_shares
  returns no shares and paths pass through untranslated instead of raising, so
  downstream code that constructs JaneliaPath runs offline (non-share paths
  behave exactly like pathlib.Path). Default behavior is unchanged: a missing
  cache with no opt-out still raises, now with a hint about the new flag.

Adds tests for the timeout, the env override, the NO_FETCH degrade path, and that
the raise-without-opt-out behavior is preserved. Documents both env vars.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@msschwartz21
msschwartz21 requested a review from cmalinmayor June 11, 2026 18:52
@cmalinmayor
cmalinmayor merged commit bc1ee48 into main Jun 24, 2026
9 checks passed
@cmalinmayor
cmalinmayor deleted the ci-offline-robustness branch October 18, 2026 23:24
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.

2 participants