Skip to content

Refactor: unify PTO-ISA resolve + auto-clone#555

Merged
ChaoZheng109 merged 1 commit intohw-native-sys:mainfrom
ChaoWao:refactor/unify-pto-isa-auto-clone
Apr 14, 2026
Merged

Refactor: unify PTO-ISA resolve + auto-clone#555
ChaoZheng109 merged 1 commit intohw-native-sys:mainfrom
ChaoWao:refactor/unify-pto-isa-auto-clone

Conversation

@ChaoWao
Copy link
Copy Markdown
Collaborator

@ChaoWao ChaoWao commented Apr 14, 2026

Summary

Single source of truth for locating / cloning / pinning the PTO-ISA repo. Before: two parallel implementations disagreed on whether to auto-clone, so pytest and python test_*.py failed on fresh checkouts with a hostile error message ("run ci.py first"). After: all four user entry points (pytest, standalone, ci.py, run_example.py) auto-clone on first use.

  • Merge `simpler_setup/pto_isa.py::ensure_pto_isa_root` (lookup-only) and `simpler_setup/code_runner.py::_ensure_pto_isa_root` (full clone+pin) into one function in `pto_isa.py`.
  • Move default clone target: `examples/scripts/_deps/pto-isa` → `PROJECT_ROOT/build/pto-isa`. `build/` is already the repo's canonical artifact dir (gitignored; houses `build/lib/`, `build/cache/`). `PROJECT_ROOT` anchors per-repo/worktree/venv so concurrent worktrees with different commit pins don't race.
  • Scene_test defaults to `update_if_exists=False` so repeated pytest runs don't hit the network.
  • ci.py / CodeRunner pass `update_if_exists=True + verbose=True` to preserve the existing "always ensure latest" behaviour.
  • `code_runner.py` loses ~280 lines of duplicated PTO-ISA handling and the `fcntl` import; `ci.py` updates two import sites to reach `simpler_setup.pto_isa` directly.

Test plan

  • `pytest tests/ut/py` — 121 passed, 5 skipped (unchanged from main)
  • `bash tools/verify_packaging.sh` — all 5 install modes × 4 entry points green on macOS
  • CI `packaging-matrix` green on Ubuntu + macOS
  • CI self-hosted `ut-py-a2a3` / `st-onboard-*` green (verifies auto-clone works end-to-end with a real PTO-ISA clone on the hardware runner)

One-time migration cost

Existing dev machines and self-hosted runners have `examples/scripts/_deps/pto-isa/` from the old path. First run after this merge will auto-clone to `build/pto-isa/` — ~1 minute, one-time. Old location can be manually deleted (it's gitignored already).

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the pto-isa dependency management logic, moving it from code_runner.py to a dedicated pto_isa.py module. The changes centralize repository cloning, commit pinning, and path resolution, while introducing file locking to handle concurrent access and an update_if_exists flag for CI environments. Review feedback suggests removing an unused verbose parameter and unifying git command execution in pto_isa.py, as well as using an existing helper function to replace a redundant directory check.

@ChaoWao ChaoWao force-pushed the refactor/unify-pto-isa-auto-clone branch 3 times, most recently from 1fdb46c to ffdbc28 Compare April 14, 2026 12:46
…helper

PTO-ISA unification
-------------------

Before this change there were two parallel implementations of
"ensure PTO-ISA is available":

  simpler_setup/pto_isa.py::ensure_pto_isa_root()
    - Only looked up (env var -> default path), raised OSError if missing.
    - Called by scene_test.py, so `pytest` and standalone `python test_*.py`
      hit OSError on a fresh checkout, with an error message that literally
      told the user to go run ci.py or run_example.py first. A real
      onboarding papercut.

  simpler_setup/code_runner.py::_ensure_pto_isa_root()
    - Full clone + commit pin + lock + fetch-latest logic (~280 lines).
    - Called by ci.py and run_example.py (via CodeRunner).

Unify both behind a single API in simpler_setup/pto_isa.py. All four user
entry points (pytest, standalone test_*.py, ci.py, run_example.py) now
auto-clone on first use.

Move default clone target
  examples/scripts/_deps/pto-isa  ->  PROJECT_ROOT/build/pto-isa

  - `build/` is the repo's canonical artifact directory (already gitignored,
    already hosts `build/lib/` and `build/cache/`).
  - Per-repo/worktree/venv isolation via PROJECT_ROOT means concurrent
    worktrees each get their own clone and don't race on commit pins.
  - One-time re-clone for existing dev machines; acceptable.

New signature:

  ensure_pto_isa_root(
      commit: Optional[str] = None,
      clone_protocol: str = "ssh",
      update_if_exists: bool = False,   # fetch origin/HEAD when True + no commit
      verbose: bool = False,
  ) -> str

- scene_test calls with defaults  -> auto-clone on first run, never touch
  an existing clone (no network on every pytest run).
- ci.py / CodeRunner pass update_if_exists=True + verbose=True to preserve
  "always ensure latest" behaviour; commit pin still wins when provided.

code_runner.py loses ~280 lines of PTO-ISA code and the fcntl import;
ci.py updates its two import sites to reach pto_isa directly
(ensure_pto_isa_root, checkout_pto_isa_commit, get_pto_isa_clone_path).

The "Cloning pto-isa to X ..." heads-up is emitted at WARNING level so it
surfaces even in pytest / standalone paths that have no basicConfig —
otherwise users would see a 30-60s silent hang on first run.

Shared --log-level helper
-------------------------

Add simpler_setup/log_config.py exposing LOG_LEVEL_CHOICES,
DEFAULT_LOG_LEVEL ("info"), and configure_logging(log_level).

All three CLI entry points now share one spelling of the flag, all default
to INFO:

  ci.py                           --log-level error|warn|info|debug
  examples/scripts/run_example.py --log-level ...  (plus -v / --silent shortcuts)
  python test_*.py (run_module)   --log-level ...

The helper also propagates PTO_LOG_LEVEL env so ci.py's runtime-isolation
subprocesses inherit the level.

pytest is untouched — it has its own --log-cli-level / pyproject log_cli_level
and doesn't need a layered flag.

Verification
------------

- pytest tests/ut/py: 121 passed, 5 skipped (unchanged from main)
- tools/verify_packaging.sh: all 5 install modes × 4 entry points green
- All 3 CLI entry points expose --log-level choices with default info
@ChaoWao ChaoWao force-pushed the refactor/unify-pto-isa-auto-clone branch from ffdbc28 to 4a75503 Compare April 14, 2026 13:00
@ChaoZheng109 ChaoZheng109 merged commit db1bcc3 into hw-native-sys:main Apr 14, 2026
15 checks passed
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