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] Issue with local distutils override, duplicate module entries #3035

Closed
1 task done
dalcinl opened this issue Jan 19, 2022 · 3 comments
Closed
1 task done

[BUG] Issue with local distutils override, duplicate module entries #3035

dalcinl opened this issue Jan 19, 2022 · 3 comments

Comments

@dalcinl
Copy link
Contributor

dalcinl commented Jan 19, 2022

setuptools version

60.5.0

Python version

3.9.9

OS

macOS

Additional environment information

edit(jaraco): I explicitly state that I DO NOT AGREE with being forced to agree with the PSF Code of Conduct to submit this issue. I ticked the box just because I cannot continue otherwise. I hope this requirement for issue submission is an oversight. If not, please close this issue and ignore my report.

Description

There are issues with the local distutils override leading to duplicated distutils.log module entries in sys.modules. As a side effect, the verbose flag (-v) to setup.py does not work (i.e passing -v DOES NOT increase verbosity).

Expected behavior

  1. After import setuptools, there should be no entries in sys.modules referring to setuptools._distutils.
  2. Running python setup.py -vv <command> should increase verbosity.

How to Reproduce

Run the following Python code:

import setuptools
import sys
for k in sys.modules.keys():
    if 'distutils.log' in k:
        print(k)

Output

setuptools._distutils.log
distutils.log

Obviously, the first entry is bogus and should not be printed.

Adding print(log) after the from distutils import log import statement in setuptools/_distutils/dist.py will help with debugging the problem. You should get the bogus setuptools._distutils.log module.

I believe this module duplication issue happens with other distutils submodules, you can check with:

import setuptools
import sys
for k in sys.modules.keys():
    if '_distutils' in k:
        print(k)

which produces

_distutils_hack
setuptools._distutils
setuptools._distutils.log
setuptools._distutils.dir_util
setuptools._distutils.file_util
setuptools._distutils.archive_util
_distutils_hack.override

Code of Conduct

  • I agree to follow the PSF Code of Conduct
@jaraco

This comment was marked as outdated.

@jaraco jaraco closed this as completed Jan 22, 2022
@jaraco jaraco added invalid and removed bug Needs Triage Issues that need to be evaluated for severity and status. labels Jan 22, 2022
@pradyunsg

This comment was marked as outdated.

@jaraco
Copy link
Member

jaraco commented Feb 16, 2022

I've confirmed the issue and localized where the module appears:

diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
index c6f7de606..95c12d8a1 100644
--- a/_distutils_hack/__init__.py
+++ b/_distutils_hack/__init__.py
@@ -54,10 +54,14 @@ def ensure_local_distutils():
     with shim():
         importlib.import_module('distutils')
 
+    assert not any('_distutils.log' in mod for mod in sys.modules)
+
     # check that submodules load as expected
     core = importlib.import_module('distutils.core')
     assert '_distutils' in core.__file__, core.__file__
 
+    assert not any('_distutils.log' in mod for mod in sys.modules)
+
 
 def do_override():
     """

With those two asserts, the first one passes and the second one doesn't. It's interesting and a little surprising that import distutils.core triggers the creation of setuptools._distutils.log. Interestingly, at that stage distutils.log is not in sys.modules. And an additional import distutils.log causes a new import of log under the new name.

@jaraco jaraco closed this as completed in 2b40489 Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants