Skip to content

Reorganize into top-level packages, drop dynamic sys.path inserts#13

Merged
mcroomp merged 3 commits into
mainfrom
refactor/package-layout
Jul 18, 2026
Merged

Reorganize into top-level packages, drop dynamic sys.path inserts#13
mcroomp merged 3 commits into
mainfrom
refactor/package-layout

Conversation

@mcroomp

@mcroomp mcroomp commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

Promotes simulation/{arduloop,calibrate,envelope,analysis,viz3d,scripts,tests} to top-level packages, each installed via a root pyproject.toml editable install, replacing the scattered ad-hoc sys.path.insert() dynamic path hacks with normal Python package imports.

Changes

  • Add root pyproject.toml (setuptools, packages.find over the 8 top-level packages, pytest markers/timeout config).
  • Rewrite bare same-directory imports to dotted package imports (e.g. from controller import Xfrom simulation.controller import X) across ~225 files via a one-off migration script (tmp/migrate_imports.py).
  • Fix Path(__file__).resolve().parents[N] path arithmetic broken by the new directory depths; anchor via Path(<pkg>.__file__).resolve().parent on an actual package import instead of counting parents, which is immune to future depth changes.
  • Fix migration-script blind spots: whitespace-padded imports, dangling guarded-insert for-loops, semicolon-joined one-liners, dynamic __import__() calls.
  • Fix two pre-existing (unrelated) syntax corruptions in analysis/compare_pumping.py and tests/oneoff/analyze_replay_aero_failure.py, found via a full py_compile sweep.
  • Update test.sh Docker sync to tar all 8 top-level packages from the repo root into the container (previously only synced simulation/), and fix the SITL test-file discovery/dispatch paths.
  • Update .github/workflows/ci.yml stack-matrix discovery and unit/simtest invocations for the new tests/ location.
  • Sweep design/*.md, AGENTS.md, README.md, and docstring/comment usage examples for stale simulation/-prefixed paths.

Validation

  • Full py_compile sweep: clean across all 8 packages.
  • pytest tests/unit -q: 467 passed.
  • pytest tests/simtests -q: 14 passed, 5 skipped.
  • SITL stack test (bash test.sh stack -n 1 -k test_lua_flight_steady_sitl): passed end-to-end in Docker.

mcroomp added 3 commits July 18, 2026 10:37
Promote simulation/{arduloop,calibrate,envelope,analysis,viz3d,scripts,tests}
to top-level packages, each installed via a root pyproject.toml editable
install instead of ad-hoc sys.path.insert() calls scattered across the
codebase.

- Add root pyproject.toml (setuptools, packages.find over the 8 top-level
  packages, pytest markers/timeout config).
- Rewrite bare same-directory imports to dotted package imports
  (e.g. from controller import X -> from simulation.controller import X)
  across ~225 files via a one-off migration script (tmp/migrate_imports.py).
- Fix Path(__file__).resolve().parents[N] path arithmetic broken by the new
  depths; anchor via Path(<pkg>.__file__).resolve().parent on an actual
  package import instead of counting parents, which is immune to future
  depth changes.
- Fix migration-script blind spots: whitespace-padded imports, dangling
  guarded-insert for-loops, semicolon-joined one-liners, dynamic
  __import__() calls.
- Fix two pre-existing (unrelated) syntax corruptions in
  analysis/compare_pumping.py and tests/oneoff/analyze_replay_aero_failure.py,
  found via a full py_compile sweep.
- Update test.sh Docker sync to tar all 8 top-level packages from the repo
  root into the container (was only syncing simulation/), and fix the SITL
  test-file discovery/dispatch paths.
- Update .github/workflows/ci.yml stack-matrix discovery and unit/simtest
  invocations for the new tests/ location.
- Sweep design/*.md, AGENTS.md, README.md, and docstring/comment usage
  examples for stale simulation/-prefixed paths.

Validated: full py_compile sweep clean; pytest tests/unit 467 passed;
pytest tests/simtests 14 passed, 5 skipped; SITL stack test
(test_lua_flight_steady_sitl) passed end-to-end in Docker.
…yout

- AGENTS.md: add a Repository Layout section describing the 8 top-level
  packages (simulation, arduloop, calibrate, envelope, analysis, viz3d,
  scripts, tests) and non-package top-level dirs; fix stale
  simulation/pytest.ini reference (pytest config now lives in
  pyproject.toml [tool.pytest.ini_options]).
- design/testing.md: fix the same stale pytest.ini reference.
- design/simulation.md: rewrite the Module Map tree -- arduloop/, scripts/,
  analysis/, viz3d/, and tests/ were shown nested under simulation/ but are
  now top-level sibling packages; split into separate trees with a note
  pointing to AGENTS.md's Repository Layout section.

Left archive/ (out-of-scope archived code) and design/history.md (historical
changelog documenting past state) untouched by design.

Validated: pytest tests/unit -q -> 467 passed.
_sync_code() never synced the root pyproject.toml into the SITL Docker
containers, so pytest-timeout's global 600s config and simtest/sitl
marker registrations were never picked up inside the container. Worse,
a separate block synced the sibling ../aero workspace's own
pyproject.toml (timeout=10, no rawes markers) to the same
/rawes/pyproject.toml path, silently clobbering rawes's config -- this
caused 5/7 SITL stack tests to fail with a false 10s pytest-timeout.

Fix: add pyproject.toml to the main repo tar sync, and remove the
entire ../aero source-tree sync block. It was vestigial: dynbem (the
only aero-workspace package rawes imports) is already installed from a
pinned PyPI wheel by the script right below it, and the aero/ directory
referenced in the old tar list doesn't even exist in the sibling repo
anymore.

Validated: full stack suite (bash test.sh stack -n 4) now passes 6/7,
with the 1 apparent failure (test_yaw_regulation_sitl) confirmed to be
CPU-contention flakiness from parallel workers, not a regression --
passes cleanly in isolation (-n 1 -k test_yaw_regulation_sitl).
@mcroomp
mcroomp merged commit 08d6699 into main Jul 18, 2026
19 of 20 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.

1 participant