Repository navigation
fix: stop the repository root from shadowing the deepcode entry point - #236
Merged
Zongwei9888 merged 1 commit intoSep 15, 2026
Merged
Conversation
`import deepcode` must bind to `deepcode.py` (setup.py declares
`py_modules=["deepcode"]` and the `deepcode=deepcode:main` console script), but the
repository root also carried a tracked `__init__.py`, making the checkout directory a
package of the same name. pytest's default prepend import mode resolves the package
root by walking up while `__init__.py` exists (`tests/__init__.py` -> repo root), and
then inserts that root into `sys.path`; with the repo checked out into a directory
literally named `deepcode` (as on this machine) the earlier `sys.path` entry wins and
`import deepcode` yields the directory package instead of `deepcode.py`:
AttributeError: module 'deepcode' has no attribute 'main'
That broke 6 tests locally (tests/test_cli_logging_bootstrap.py, 5 cases;
tests/test_version_metadata.py, 1 case) and would break any source checkout on a
case-insensitive filesystem whose directory name matches the module. Upstream CI is
unaffected only by accident: it checks out `DeepCode`, which does not match the
module name on a case-sensitive filesystem.
Delete the root `__init__.py` and the matching `include __init__.py` from
MANIFEST.in (pre-commit's check-manifest keeps the two in sync). Nothing imports the
root package and the sdist no longer ships a file that turns the unpacked checkout
into a shadowing package.
Verified: tests/test_cli_logging_bootstrap.py + tests/test_version_metadata.py ->
7 passed (6 failed before); `python -c "import deepcode"` resolves to deepcode.py.
Collaborator
|
Merged into |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The repository root contains a tracked
__init__.py. On a case-insensitive filesystem (Windows) that makes the checkout directory itself a package whose name matches thedeepcodemodule:pytest's default
--import-mode=prependinserts the package root onsys.path, soimport deepcodebinds to the checkout directory instead ofdeepcode.pyanddeepcode.main()does not exist:Any checkout literally named
deepcodehits this — including a plaingit cloneon Windows. Upstream CI never sees it because it checks out asDeepCode(capital D), which does not matchdeepcodeon a case-sensitive filesystem.Reproduction
With the tree checked out at HEAD and the directory named
deepcode:Fix
Delete the root
__init__.pyand mirror that inMANIFEST.in(it previously shippedinclude __init__.py); a comment records why the root is deliberately not a package. The package metadata lives insetup.py(py_modules = ["deepcode"]plus thedeepcode=deepcode:mainconsole script), so nothing depends on the root__init__.py.After
check-manifeststays consistent becauseMANIFEST.inis updated in the same commit.I did not take the alternative route of re-exporting
main/_bootstrap_loggingfrom the root__init__.py:tests/test_cli_logging_bootstrap.pymonkeypatchesdeepcode._bootstrap_logging, and under package binding that patch would no longer reach the module global thatmain()reads — the test would pass while testing nothing.