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

Replace condition to patch distutils.dist.log #3709

Merged
merged 4 commits into from Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)