[PR #1419] [MERGED] fix(tests): make mlsysim.core importable from CI without pip install #8185

Closed
opened 2026-04-27 17:29:22 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/harvard-edge/cs249r_book/pull/1419
Author: @profvjreddi
Created: 4/20/2026
Status: Merged
Merged: 4/20/2026
Merged by: @profvjreddi

Base: devHead: fix/test-units-mlsysim-path


📝 Commits (1)

  • 7022d88 fix(tests): make mlsysim.core importable from CI without pip install

📊 Changes

1 file changed (+15 additions, -4 deletions)

View changed files

📝 book/tests/test_units.py (+15 -4)

📄 Description

Summary

Fixes the book-mlsys-test-units pre-commit hook, which has been red on
every book-validate-dev run since 2026-04-18 (last green: 2026-04-17, sha 532eed35).
The fix is one line of corrected sys.path math, with a comment explaining the layout
trap so it doesn't recur.

Why it failed

book/tests/test_units.py did:

sys.path.insert(0, _repo_root)         # cs249r_book/
from mlsysim.core.constants import *

But mlsysim package layout is two levels deep:

<repo_root>/mlsysim/                    ← project dir, NOT a Python package
<repo_root>/mlsysim/mlsysim/__init__.py ← actual package
<repo_root>/mlsysim/mlsysim/core/       ← submodule we want
  • In dev: mlsysim is pip install -e'd, so Python found it via site-packages.
    The path hack was inert. The import worked. Tests passed locally.
  • In CI: no editable install. Python 3.3+ saw <repo_root>/mlsysim/ (no __init__.py)
    as an implicit namespace package, and mlsysim.core resolved nowhere → ModuleNotFoundError.

Fix

Point sys.path at <repo_root>/mlsysim/ (the directory containing the package),
not <repo_root>/:

_mlsysim_project = os.path.join(_repo_root, "mlsysim")
sys.path.insert(0, _mlsysim_project)

Comment block above the change documents the layout so the next person to touch it
doesn't reintroduce the bug.

Verification

  • pre-commit run book-mlsys-test-units --files book/quarto/contents/vol1/benchmarking/benchmarking.qmdPassed locally.
  • All transitive deps (pint, pydantic, numpy, pyyaml, rich) are already
    in book/tools/dependencies/requirements.txt, which book-validate-dev.yml installs.
  • Sandbox-emulated CI environment (no editable install, plain sys.path) resolves
    mlsysim.core correctly with this patch.

What this unblocks

The book publish guard (infra-publish-guard.ymlbook-validate-dev.yml) requires
the most recent dev validate run to be green. With this fix, book-publish-live can
be triggered for vol1 v0.6.0 / vol2 v0.1.0 once the next dev run goes green.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1419 **Author:** [@profvjreddi](https://github.com/profvjreddi) **Created:** 4/20/2026 **Status:** ✅ Merged **Merged:** 4/20/2026 **Merged by:** [@profvjreddi](https://github.com/profvjreddi) **Base:** `dev` ← **Head:** `fix/test-units-mlsysim-path` --- ### 📝 Commits (1) - [`7022d88`](https://github.com/harvard-edge/cs249r_book/commit/7022d88dbb844238bf9f66e2c7b0dbe4ecd63c1b) fix(tests): make mlsysim.core importable from CI without pip install ### 📊 Changes **1 file changed** (+15 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `book/tests/test_units.py` (+15 -4) </details> ### 📄 Description ## Summary Fixes the `book-mlsys-test-units` pre-commit hook, which has been red on **every** `book-validate-dev` run since 2026-04-18 (last green: 2026-04-17, sha `532eed35`). The fix is one line of corrected `sys.path` math, with a comment explaining the layout trap so it doesn't recur. ## Why it failed `book/tests/test_units.py` did: ```python sys.path.insert(0, _repo_root) # cs249r_book/ from mlsysim.core.constants import * ``` But `mlsysim` package layout is two levels deep: ``` <repo_root>/mlsysim/ ← project dir, NOT a Python package <repo_root>/mlsysim/mlsysim/__init__.py ← actual package <repo_root>/mlsysim/mlsysim/core/ ← submodule we want ``` - **In dev:** `mlsysim` is `pip install -e`'d, so Python found it via site-packages. The path hack was inert. The import worked. Tests passed locally. - **In CI:** no editable install. Python 3.3+ saw `<repo_root>/mlsysim/` (no `__init__.py`) as an implicit namespace package, and `mlsysim.core` resolved nowhere → `ModuleNotFoundError`. ## Fix Point `sys.path` at `<repo_root>/mlsysim/` (the directory containing the package), not `<repo_root>/`: ```python _mlsysim_project = os.path.join(_repo_root, "mlsysim") sys.path.insert(0, _mlsysim_project) ``` Comment block above the change documents the layout so the next person to touch it doesn't reintroduce the bug. ## Verification - `pre-commit run book-mlsys-test-units --files book/quarto/contents/vol1/benchmarking/benchmarking.qmd` → **Passed** locally. - All transitive deps (`pint`, `pydantic`, `numpy`, `pyyaml`, `rich`) are already in `book/tools/dependencies/requirements.txt`, which `book-validate-dev.yml` installs. - Sandbox-emulated CI environment (no editable install, plain `sys.path`) resolves `mlsysim.core` correctly with this patch. ## What this unblocks The book publish guard (`infra-publish-guard.yml` → `book-validate-dev.yml`) requires the most recent dev validate run to be green. With this fix, `book-publish-live` can be triggered for vol1 v0.6.0 / vol2 v0.1.0 once the next dev run goes green. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-27 17:29:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#8185