Skip to content

Commit

Permalink
Merge pull request #3709 from abravalheri/issue-3707
Browse files Browse the repository at this point in the history
Replace condition to patch `distutils.dist.log`
  • Loading branch information
jaraco committed Nov 24, 2022
2 parents e515641 + a4db65f commit 0f513c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog.d/3709.misc.rst
@@ -0,0 +1,2 @@
Fix condition to patch ``distutils.dist.log`` to only apply when using
``distutils`` from the stdlib.
3 changes: 2 additions & 1 deletion setuptools/logging.py
@@ -1,4 +1,5 @@
import sys
import inspect
import logging
import distutils.log
from . import monkey
Expand All @@ -22,7 +23,7 @@ def configure():
handlers = err_handler, out_handler
logging.basicConfig(
format="{message}", style='{', handlers=handlers, level=logging.DEBUG)
if hasattr(distutils.log, 'Log'):
if inspect.ismodule(distutils.dist.log):
monkey.patch_func(set_threshold, distutils.log, 'set_threshold')
# For some reason `distutils.log` module is getting cached in `distutils.dist`
# and then loaded again when patched,
Expand Down
17 changes: 17 additions & 0 deletions setuptools/tests/test_logging.py
@@ -1,4 +1,6 @@
import inspect
import logging
import os

import pytest

Expand Down Expand Up @@ -34,3 +36,18 @@ def test_verbosity_level(tmp_path, monkeypatch, flag, expected_level):
log_level = logger.getEffectiveLevel()
log_level_name = logging.getLevelName(log_level)
assert log_level_name == expected_level


def test_patching_does_not_cause_problems():
# Ensure `dist.log` is only patched if necessary

import setuptools.logging
from distutils import dist

setuptools.logging.configure()

if os.getenv("SETUPTOOLS_USE_DISTUTILS", "local").lower() == "local":
# Modern logging infra, no problematic patching.
assert isinstance(dist.log, logging.Logger)
else:
assert inspect.ismodule(dist.log)

0 comments on commit 0f513c1

Please sign in to comment.