Skip to content
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] stdlib test_distutils on python3.8 runs only with SETUPTOOLS_USE_DISTUTILS=stdlib #2965

Closed
1 task done
mattip opened this issue Dec 24, 2021 · 3 comments · Fixed by #3031
Closed
1 task done
Labels
Needs Discussion Issues where the implementation still needs to be discussed.

Comments

@mattip
Copy link
Contributor

mattip commented Dec 24, 2021

setuptools version

setuptools==60.0.0

Python version

Python 3.8

OS

Ubuntu 20.04

Additional environment information

No response

Description

Collecting the stdlib test_distutils.py test suite fails unless I use SETUPTOOLS_USE_DISTUTILS=stdlib with setuptools>60

Expected behavior

I can set SETUPTOOLS_USE_DISTUTILS=stdlib, but thought this should work without it?

How to Reproduce

$ sudo apt install libpython3.8-testsuite python3-venv
$ python3.8 -venv /tmp/venv_py3.8
$ /tmp/venv_py3.8/bin/python /usr/lib/python3.8/test/test_distutils.py
# tests run, 2 fail
$ /tmp/venv_py3.8/bin/python -m pip install "setuptools>59"
...
Successfully installed setuptools-60.1.0
$ /tmp/venv_py3.8/bin/python /usr/lib/python3.8/test/test_distutils.py
Traceback (most recent call last):
  File "/usr/lib/python3.8/test/test_distutils.py", line 8, in <module>
    import distutils.tests
ModuleNotFoundError: No module named 'distutils.tests'

Output

$ /tmp/venv_py3.8/bin/python /usr/lib/python3.8/test/test_distutils.py
Traceback (most recent call last):
  File "/usr/lib/python3.8/test/test_distutils.py", line 8, in <module>
    import distutils.tests
ModuleNotFoundError: No module named 'distutils.tests'

Code of Conduct

  • I agree to follow the PSF Code of Conduct
@mattip mattip added bug Needs Triage Issues that need to be evaluated for severity and status. labels Dec 24, 2021
@mattip mattip changed the title [BUG] something in 60.0 broke stdlib test_distutils on python3.8 [BUG] stdlib test_distutils on python3.8 runs only with SETUPTOOLS_USE_DISTUTILS=stdlib Dec 24, 2021
@jaraco
Copy link
Member

jaraco commented Dec 28, 2021

The way the distutils hack works, it makes Setuptools' own copy of distutils take precedence over the standard library, so causes import distutils to put sys.modules['distutils'] = <setuptools._distutils>. So it's not a big surprise to me that running the tests from the standard library against code not in the standard library will have problems.

What is something of a surprise is the error message you encountered. I don't encounter that error if I run .tox/python/bin/python -m test.test_distutils from the setuptools source.

I'm guessing that because packages.find excludes tests* and *.tests, that means that the tests get omitted on install, so that distutils.tests package simply isn't present.

My recommendation would be to continue to run tests with =stdlib or to avoid running those tests. I know some people have invested energy into ensuring that Setuptools doesn't install its tests, so it's not a mistake that the distutils tests aren't present either. And even if they were present, having them execute when running stdlib tests doesn't seem like the right or intended behavior.

Do you have any other recommendations in mind?

@jaraco jaraco added Needs Discussion Issues where the implementation still needs to be discussed. and removed bug Needs Triage Issues that need to be evaluated for severity and status. labels Dec 28, 2021
@frapa-az
Copy link

frapa-az commented Jan 10, 2022

Hi, I just got stuck in a similar error. On python 3.8 (which is the default on ubuntu 20.04 LTS), with setuptools 60.x, I am unable to install packages in editable mode without SETUPTOOLS_USE_DISTUTILS=stdlib. If I downgrade, install normally or add SETUPTOOLS_USE_DISTUTILS=stdlib the installation works as expected.

Here a reproducible example:

setuptools_60_issue.zip

To reproduce, perform the following steps in the unpacked folder:

$ docker build . -t setuptools_60_issue
$ docker run -it setuptools_60_issue
root@cfb245293780:/#

# As expected, if the module is not installed, it fails
root@cfb245293780:/# python3 -c "import example_mod"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'example_mod'

# But, it also fails when the module is installed in editable mode
# NOTE: pip reports successful install but then the module is unavailable
root@cfb245293780:/# pip install -e package/
Obtaining file:///package
Installing collected packages: setuptools-60-issue
  Running setup.py develop for setuptools-60-issue
Successfully installed setuptools-60-issue
root@cfb245293780:/# python3 -c "import example_mod"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'example_mod'

If works fine with the env var or with normal install. It also works with python 3.9.

@robertschweizer
Copy link

The issue described by @frapa-az has not been fixed and persists in all setuptools versions >=60. Main issue: #3301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Discussion Issues where the implementation still needs to be discussed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants