pypa / pypa/setuptools

[BUG] `_distutils_hack` sometimes breaks in `virtualenv`s

Open
#3,706 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Needs Triage
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

setuptools version

e5156411d97a683db3365e2b778c0936b5fb620a

Python version

cpython 3.9

OS

Ubuntu 21.10 Impish

Additional environment information
Package                   Version
------------------------- -------------------
asttokens                 2.1.0
build                     0.9.0
certifi                   2022.9.24
colorama                  0.4.7.dev1
editables                 0.3
executing                 0.1.dev1+g32c2388
flit_core                 3.8.0
hatch-fancy-pypi-readme   22.8.0
hatch-vcs                 0.2.0
hatchling                 1.11.1
httpcore                  0.16.1
httpx                     0.23.1
icecream                  2.1.3
installer                 0.6.0.dev0
ipi                       0.1.dev1+g58bf835
packaging                 21.4.dev0
pathspec                  0.10.2
peval                     0.1.dev1+g2f68c8c
pip                       23.0.dev0
pluggy                    0.1.dev1+gd0c0cac
plumbum                   0.1.dev1+g4ea4a2c
Pygments                  2.13.0
pyproject_hooks           1.0.0
requests                  2.28.1
requests-file             0.1.dev1+g675c7a6
rfc3986                   2.0.0
RichConsole               0.1.dev1+g954197c
securesystemslib          0.1.dev1+gfccaee8
securesystemslib-KOLANICH 0.1.dev1+g49c432c
setuptools                65.6.2.post20221123
setuptools-scm            0.1.dev1+ga70d44b
sh                        1.14.3
sniffio                   1.3.0+dev
tomli                     2.0.1
transformerz              0.1.dev1+g607eef8
tuf                       2.0.0
tuft                      0.1.dev1+g1a99478
typing_extensions         4.4.0
wheel                     0.38.4
Description

It seems that setuptools breaks when the check sees a path from a venv. It is strange. It started happening only after installation of the bunch of packages into the venv.

Expected behavior

No assertion

How to Reproduce

I have encountered it when debugging ipi (my new package manager, replacement for pip) self-bootstrapping within a venv. I'm not sure you should try

Output
File "~/ipi.py/ipi/utils/metadataExtractor.py", line 24, in <module>
  from setuptools.config import read_configuration as parseSetupCfg
File "~/ipi.py/test_venv/lib/python3.9/site-packages/setuptools/__init__.py", line 8, in <module>
  import _distutils_hack.override  # noqa: F401
File "~/ipi.py/test_venv/lib/python3.9/site-packages/_distutils_hack/override.py", line 1, in <module>
  __import__('_distutils_hack').do_override()
File "~/ipi.py/test_venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 77, in do_override
  ensure_local_distutils()
File "~/ipi.py/test_venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 64, in ensure_local_distutils
  assert '_distutils' in core.__file__, core.__file__
AssertionError: /usr/lib/python3.9/distutils/core.py

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the traceback in a Python 3.9 virtualenv on Ubuntu, focusing on setuptools.config and the _distutils_hack override path shown in the report. Check why ensure_local_distutils sees /usr/lib/python3.9/distutils/core.py instead of the expected local module. Done means the reported import completes without the assertion in the affected virtualenv scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.