Skip to content

fix: use relative import to fix Docker ModuleNotFoundError#342

Merged
hf-kklein merged 2 commits intomainfrom
fix/relative-import-for-docker
Apr 2, 2026
Merged

fix: use relative import to fix Docker ModuleNotFoundError#342
hf-kklein merged 2 commits intomainfrom
fix/relative-import-for-docker

Conversation

@hf-kklein
Copy link
Copy Markdown
Contributor

Summary

  • Fixes ModuleNotFoundError: No module named 'ebd_toolchain' when running in Docker
  • Changes from ebd_toolchain.ahb_pruefi import ... to from .ahb_pruefi import ...
  • Adds a CI guard test that prevents absolute intra-package imports from being reintroduced

Root cause

The Dockerfile runs python ebd_toolchain/main.py directly. Python adds the script's directory (/app/ebd_toolchain/) to sys.path, not its parent (/app/). So import ebd_toolchain fails because /app/ is not on the path.

Prevention

New test test_no_absolute_intra_imports.py scans all .py files in the package using ast and fails if any use from ebd_toolchain.* import ... instead of relative imports.

Test plan

  • Guard test passes locally
  • black/isort clean
  • CI green

🤖 Generated with Claude Code

hf-kklein and others added 2 commits April 2, 2026 18:27
The Dockerfile runs `python ebd_toolchain/main.py` directly, which adds
`/app/ebd_toolchain/` to sys.path but NOT `/app/`. This means absolute
intra-package imports like `from ebd_toolchain.ahb_pruefi import ...`
fail with:

  ModuleNotFoundError: No module named 'ebd_toolchain'

Fix: use relative import (`from .ahb_pruefi import ...`) which works
regardless of how the script is invoked.

Also adds a CI guard test that scans all .py files in the package for
absolute intra-package imports and fails if any are found.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reviewer found that bare `import ebd_toolchain.foo` would slip through
because ast.Import stores names in node.names, not node.module.
Also switched glob to rglob to catch future sub-packages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hf-kklein hf-kklein merged commit 8693e90 into main Apr 2, 2026
17 checks passed
@hf-kklein hf-kklein deleted the fix/relative-import-for-docker branch April 2, 2026 18:37
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