Skip to content

maintenance: derive the demo dataset and canonical-output paths, never name them - #75

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/workspace-resolver-fanout
Sep 18, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/workspace-resolver-fanout

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Part of PyAutoLabs/PyAutoBrain#393 (phase 2). Changes no directory layout. Companions: PyAutoLabs/PyAutoMind#415, PyAutoArray (same branch name).

What was wrong

scripts/reduce_cosmos_web_ring.py:34 hardcoded:

/home/jammy/Code/PyAutoLabs/autolens_assistant/dataset/imaging/cosmos_web_ring/wavebands

A cross-repo reference that breaks when autolens_assistant moves under lens/ — and already machine-specific: nobody else's checkout is at /home/jammy.

Four prototypes/starred_*.py files carried Path.home()/"Code/PyAutoLabs/PyAutoReduce/scripts/output" as a fallback candidate.

Why this does not use PyAutoBrain's resolver

Phase 1a shipped a workspace-root resolver, and reaching for it here would be wrong:

  1. PyAutoReduce is a released PyPI distribution. Someone who pip install pyautoreduces and clones this repo to run scripts/ has no Brain checkout, no .pyauto-root marker, and no workspace at all. An import-by-file-path of a developer-box organ would be dead code on every machine but one — precisely the failure class that resolver's own docstring exists to kill.
  2. It answers a question one level up from the one asked. The script needs one sibling's dataset subtree, not the workspace root; with the root in hand it would still have to guess autolens_assistant vs lens/autolens_assistant.
  3. Dependency direction. Organs may know about libraries; a science library reaching back into the orchestration layer inverts that, and would be the first such edge in this repo.

What it does instead

$AUTOREDUCE_DEMO_ROOT → a bounded sibling probe → an unverified guess.

The probe checks one and two levels above the repo, each directly and one family subdirectory deeper — the full cross-product of "is this repo in a family folder" × "is autolens_assistant". No walk to /, no marker needed, stdlib only.

It calls only is_dir()/glob(), so it cannot raise at import; the not-found branch returns the flat-layout path so the eventual fits.getdata failure names something plausible. The pre-existing code was already import-safe and DEMO_ROOT is read only inside compare() — that property is preserved.

A --demo-root flag completes the set: env var for a shell, flag for a one-off, probe for everyone else.

The _CAND fallbacks: replace the guess with the fact

Their job is real — reduced outputs are gitignored, so a worktree has none and must read the canonical checkout's — but they guessed where canonical is. Git already knows: a worktree's .git is a file containing gitdir: <canonical>/.git/worktrees/<name>.

Stdlib only (no subprocess at import), .parent chaining rather than parents[2] so a short or odd gitdir degrades instead of raising IndexError. In an ordinary clone .git is a directory, MAIN == ROOT, and the two candidates collapse harmlessly. Verified the resulting candidate lists are byte-identical to the pre-edit ones.

Not factored into a shared prototypes/_paths.py: these run per-stage under different venvs with no PYTHONPATH=., where a package import would not resolve.

Verification

  • git grep -n "Code/PyAutoLabs" -- '*.py' → empty. Same for /home/jammy and Path.home().
  • 299 passed, 3 skipped. All four prototypes executed via runpy.run_path (numpy imports, MAIN/_CAND/FIELD all resolve); reduce_cosmos_web_ring.py --help runs end to end and prints the resolved default.
  • Dataset confirmed present (F115W/F150W/F277W/F444W). Resolution across six layouts, fixtures only — nothing was moved:
layout resolved found
flat workspace (today) <root>/autolens_assistant/… ✅
phase 3: assistant → lens/ <root>/lens/autolens_assistant/… ✅
both in families (reduce/PyAutoReduce) <root>/lens/autolens_assistant/… ✅
reduce moved, assistant flat <root>/autolens_assistant/… ✅
nothing present guess returned, no raise n/a
$AUTOREDUCE_DEMO_ROOT set honoured verbatim n/a

🤖 Generated with Claude Code

https://claude.ai/code/session_0161NLKVzbBMzhaBfjpGogor

…r name them

`scripts/reduce_cosmos_web_ring.py` hardcoded
/home/jammy/Code/PyAutoLabs/autolens_assistant/dataset/... — a cross-repo
reference that breaks when autolens_assistant moves under lens/, and that was
already machine-specific: nobody else's checkout is at /home/jammy.

It deliberately does NOT reach for PyAutoBrain's resolver. PyAutoReduce is a
released PyPI distribution: someone who `pip install pyautoreduce`s and clones
this repo to run scripts/ has no Brain checkout, no .pyauto-root marker and no
workspace at all, so an import-by-file-path of a developer-box organ would be
dead code on every machine but one — the exact failure class that resolver's own
docstring exists to kill. It would also invert the dependency direction, a science
library reaching back into the orchestration layer, and it answers a question one
level up from the one asked: the script needs one sibling's dataset subtree, not
the workspace root.

Instead: $AUTOREDUCE_DEMO_ROOT, then a bounded sibling probe, then an unverified
guess. The probe checks one and two levels above the repo, each directly and one
family subdirectory deeper — the full cross-product of "is THIS repo in a family
folder" x "is autolens_assistant". No walk to /, no marker, stdlib only. It calls
only is_dir()/glob() so it cannot raise at import, and the not-found branch returns
the flat-layout path so the eventual failure names something plausible. A
--demo-root flag completes the set: env var for a shell, flag for a one-off, probe
for everyone else.

The four prototypes' _CAND fallbacks guessed where the canonical checkout is, in
order to read reduced outputs that are gitignored and so absent from a worktree.
Git already knows: a worktree's .git is a FILE reading `gitdir: <canonical>/...`.
The guess is replaced by that fact — stdlib, no subprocess at import, .parent
chaining rather than parents[2] so a short gitdir degrades instead of raising.
In an ordinary clone .git is a directory, MAIN == ROOT and the candidates collapse
harmlessly; verified the resulting lists are byte-identical to the originals.

Resolution demonstrated across six layouts including the actual phase-3 one
(lens/autolens_assistant). 299 passed, 3 skipped.

Part of PyAutoBrain#393 (phase 2). No directory layout changes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161NLKVzbBMzhaBfjpGogor
@Jammy2211
Jammy2211 merged commit ac1ea32 into main Sep 18, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/workspace-resolver-fanout branch September 18, 2026 21:21
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