-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Realtive import of nonexistent package with same name throws RecursionError #3550
Comments
Hi @0x2b3bfa0, thank you very much for bringing this issue for discussion. In your I can demonstrate an error with setuptools v63.4.3, which was the last version of setuptools without PEP 660 support: FROM python:3
RUN mkdir test\
&& echo 'build-system.requires = ["setuptools==63.4.3"]' >pyproject.toml\
&& echo 'from distutils.core import setup; setup(packages=["test"])' >setup.py\
&& echo 'from .test import nonexistent' >test/__init__.py
RUN pip install -e .\
&& python -c 'import test' [+] Building 4.9s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 343B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/python:3 0.7s
=> [1/3] FROM docker.io/library/python:3@sha256:cbf49327fae903d64ab28251912fc00faea2c1baee493d347a07973a2cb50f98 0.0s
=> CACHED [2/3] RUN mkdir test && echo 'build-system.requires = ["setuptools==63.4.3"]' >pyproject.toml && echo 0.0s
=> ERROR [3/3] RUN pip install -e . && python -c 'import test' 4.1s
------
> [3/3] RUN pip install -e . && python -c 'import test':
#6 1.317 Obtaining file:///
#6 1.320 Installing build dependencies: started
#6 2.738 Installing build dependencies: finished with status 'done'
#6 2.740 WARNING: Missing build requirements in pyproject.toml for file:///.
#6 2.740 WARNING: The project does not specify a build backend, and pip cannot fall back to setuptools without 'wheel'.
#6 2.741 Checking if build backend supports build_editable: started
#6 2.893 Checking if build backend supports build_editable: finished with status 'done'
#6 2.894 Getting requirements to build wheel: started
#6 3.041 Getting requirements to build wheel: finished with status 'done'
#6 3.043 Installing backend dependencies: started
#6 3.587 Installing backend dependencies: finished with status 'done'
#6 3.588 Preparing metadata (pyproject.toml): started
#6 3.760 Preparing metadata (pyproject.toml): finished with status 'done'
#6 3.794 Installing collected packages: test
#6 3.795 Running setup.py develop for test
#6 3.979 Successfully installed test-0.0.0
#6 3.980 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#6 3.983
#6 3.983 [notice] A new release of pip available: 22.2.1 -> 22.2.2
#6 3.983 [notice] To update, run: pip install --upgrade pip
#6 4.042 Traceback (most recent call last):
#6 4.042 File "<string>", line 1, in <module>
#6 4.042 File "/test/__init__.py", line 1, in <module>
#6 4.042 from .test import nonexistent
#6 4.042 ModuleNotFoundError: No module named 'test.test'
------
executor failed running [/bin/sh -c pip install -e . && python -c 'import test']: exit code: 1 On the other hand, I can verify version 65.1.0 working normally (the latest version of setuptools, which includes PEP 660 support), by tweaking a little bit the Dockerfile: FROM python:3
WORKDIR /tmp
# Let's avoid naming the package `test`,
# because there is a `test` in Python's stdlib...
RUN mkdir -p /tmp/pkg_root/pkg \
&& echo 'build-system.requires = ["setuptools==65.1.0"]' > /tmp/pkg_root/pyproject.toml \
&& echo 'from distutils.core import setup; setup(packages=["pkg"])' > /tmp/pkg_root/setup.py \
&& echo 'from . import othermodule' > /tmp/pkg_root/pkg/__init__.py \
&& echo 'print("hello world")' > /tmp/pkg_root/pkg/othermodule.py
RUN pip install -e /tmp/pkg_root
WORKDIR /var
# We change directories here to avoid the side-effect
# of CWD being accidentally added to `sys.path`...
RUN python -c 'import pkg; print(pkg.__path__)' This Dockerfile is able to build normally. I can also see the import statement working normally by doing the following: docker build -t testcase .
docker run --rm -it testcase /bin/bash $ docker build -t testcase .
[+] Building 8.6s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 731B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/python:3 2.9s
=> [1/6] FROM docker.io/library/python:3@sha256:cbf49327fae903d64ab28251912fc00faea2c1baee493d347a07973a2cb50f98 0.0s
=> CACHED [2/6] WORKDIR /tmp 0.0s
=> [3/6] RUN mkdir -p /tmp/pkg_root/pkg && echo 'build-system.requires = ["setuptools==65.1.0"]' > /tmp/pkg_roo 0.4s
=> [4/6] RUN pip install -e /tmp/pkg_root 4.5s
=> [5/6] WORKDIR /var 0.0s
=> [6/6] RUN python -c 'import pkg; print(pkg.__path__)' 0.5s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:e463267a33fffafbb2c1ec432744b934a8e16e50a2f1166032e251729628c0a4 0.0s
=> => naming to docker.io/library/testcase 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
$ docker run --rm -it testcase /bin/bash
root@6f9db6fe1c05:/var# python -c 'import pkg; print(pkg.__path__)'
hello world
['/tmp/pkg_root/pkg'] |
Hi @abravalheri! Thank you ver much for the detailed response.
As pointed out in the “expected behavior” section of the issue, the error is very similar, but is not the same: the Still, this issue turned out to be an x-y problem; I tried to demonstrate that packages with native code were causing this issue, and realized that it wasn't the case. 🙈
|
Note: feel free to reopen if throwing |
Thank you very much @0x2b3bfa0, I think I have captured the recursion problem in a test case and I am working on a fix. This issue report was very helpful. Thank you very much! |
@0x2b3bfa0 is there any error happening with the second version of the Dockerfile in #3550 (comment)? I tried to build it in my machine and it builds correctly. But I have not tried to run anything in the container... |
No, the example in #3550 (comment) works as intended: I tried to prove the opposite, and failed to do so. I'll have to keep searching for the cause of the “Y” issue. 😅 |
Reopening so it's automatically closed when merging #3551 🎉 |
Unfortunately #3551 still doesn't fix editable installs. https://github.com/AMYPAD/CuVec/runs/7937211204?check_suite_focus=true fails on
However the "error" is not actually accurate - there is indeed a module called |
Ah, perhaps the "real" issue is an upstream package not supporting PEP-660 and therefore |
setuptools version
setuptools 64.0.0
Python version
Python 3.10
OS
Ubuntu 22.04
Additional environment information
Seen in the wild at https://github.com/AMYPAD/CuVec, had to pin
setuptools
in AMYPAD/CuVec#25 to fix this issue.Description
Introduced with #3488, throws
RecursionError
instead ofModuleNotFoundError
when importing an editable package with an__init__.py
containing an import in the formfrom .example import anything
whereexample
is also the package name.Expected behavior
In this specific case, the expected outcome is
ModuleNotFoundError: No module named 'test.test'
like when pinningsetuptools
in the minimal reproducible example below to any versions lower than 64.How to Reproduce
Create a file named
Dockerfile
with the contents below and rundocker build .
to reproduce the issue.Dockerfile
Output
The text was updated successfully, but these errors were encountered: