Skip to content

Commit 0f513c1

Browse files
authored
Merge pull request #3709 from abravalheri/issue-3707
Replace condition to patch `distutils.dist.log`
2 parents e515641 + a4db65f commit 0f513c1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

changelog.d/3709.misc.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix condition to patch ``distutils.dist.log`` to only apply when using
2+
``distutils`` from the stdlib.

setuptools/logging.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import inspect
23
import logging
34
import distutils.log
45
from . import monkey
@@ -22,7 +23,7 @@ def configure():
2223
handlers = err_handler, out_handler
2324
logging.basicConfig(
2425
format="{message}", style='{', handlers=handlers, level=logging.DEBUG)
25-
if hasattr(distutils.log, 'Log'):
26+
if inspect.ismodule(distutils.dist.log):
2627
monkey.patch_func(set_threshold, distutils.log, 'set_threshold')
2728
# For some reason `distutils.log` module is getting cached in `distutils.dist`
2829
# and then loaded again when patched,

setuptools/tests/test_logging.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import inspect
12
import logging
3+
import os
24

35
import pytest
46

@@ -34,3 +36,18 @@ def test_verbosity_level(tmp_path, monkeypatch, flag, expected_level):
3436
log_level = logger.getEffectiveLevel()
3537
log_level_name = logging.getLevelName(log_level)
3638
assert log_level_name == expected_level
39+
40+
41+
def test_patching_does_not_cause_problems():
42+
# Ensure `dist.log` is only patched if necessary
43+
44+
import setuptools.logging
45+
from distutils import dist
46+
47+
setuptools.logging.configure()
48+
49+
if os.getenv("SETUPTOOLS_USE_DISTUTILS", "local").lower() == "local":
50+
# Modern logging infra, no problematic patching.
51+
assert isinstance(dist.log, logging.Logger)
52+
else:
53+
assert inspect.ismodule(dist.log)

0 commit comments

Comments
 (0)