From 68387afcd33cb514a4da811d2fc5de73c8797e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Fri, 8 Nov 2024 17:27:03 +0200 Subject: [PATCH] Only configure setuptools logging if bdist_wheel is imported (#641) Also fix the output of `wheel convert` to add the final "OK" on the same line as the source file name. Fixes #632. --- docs/news.rst | 1 + src/wheel/_bdist_wheel.py | 9 +++++++++ src/wheel/cli/convert.py | 2 +- src/wheel/util.py | 9 --------- tests/cli/test_convert.py | 27 ++++++++++++++++++--------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index cd319be3..9acf9186 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -4,6 +4,7 @@ Release Notes **UNRELEASED** - Refactored the ``convert`` command to not need setuptools to be installed +- Don't configure setuptools logging unless running ``bdist_wheel`` - Added a redirection from ``wheel.bdist_wheel.bdist_wheel`` to ``setuptools.command.bdist_wheel.bdist_wheel`` to improve compatibility with ``setuptools``' latest fixes. diff --git a/src/wheel/_bdist_wheel.py b/src/wheel/_bdist_wheel.py index 3cc7165e..88973ebf 100644 --- a/src/wheel/_bdist_wheel.py +++ b/src/wheel/_bdist_wheel.py @@ -34,6 +34,15 @@ if TYPE_CHECKING: import types +# ensure Python logging is configured +try: + __import__("setuptools.logging") +except ImportError: + # setuptools < ?? + from . import _setuptools_logging + + _setuptools_logging.configure() + def safe_name(name: str) -> str: """Convert an arbitrary string to a standard distribution name diff --git a/src/wheel/cli/convert.py b/src/wheel/cli/convert.py index 3361fd4f..ec5ecf3a 100644 --- a/src/wheel/cli/convert.py +++ b/src/wheel/cli/convert.py @@ -293,7 +293,7 @@ def convert(files: list[str], dest_dir: str, verbose: bool) -> None: source = WininstFileSource(path) if verbose: - print(f"{archive}... ", flush=True) + print(f"{archive}...", flush=True, end="") dest_path = Path(dest_dir) / ( f"{source.name}-{source.version}-{source.pyver}-{source.abi}" diff --git a/src/wheel/util.py b/src/wheel/util.py index d98d98cb..c928aa40 100644 --- a/src/wheel/util.py +++ b/src/wheel/util.py @@ -5,15 +5,6 @@ log = logging.getLogger("wheel") -# ensure Python logging is configured -try: - __import__("setuptools.logging") -except ImportError: - # setuptools < ?? - from . import _setuptools_logging - - _setuptools_logging.configure() - def urlsafe_b64encode(data: bytes) -> bytes: """urlsafe_b64encode without padding""" diff --git a/tests/cli/test_convert.py b/tests/cli/test_convert.py index e8da2adb..a1bfd5d1 100644 --- a/tests/cli/test_convert.py +++ b/tests/cli/test_convert.py @@ -7,11 +7,11 @@ import pytest from _pytest.fixtures import SubRequest -from pytest import TempPathFactory +from pytest import CaptureFixture, TempPathFactory import wheel from wheel.cli.convert import convert, egg_filename_re -from wheel.wheelfile import WHEEL_INFO_RE, WheelFile +from wheel.wheelfile import WheelFile PKG_INFO = """\ Metadata-Version: 2.1 @@ -187,16 +187,21 @@ def test_egg_re() -> None: def test_convert_egg_file( - egg_path: str, tmp_path: Path, arch: str, expected_wheelfile: bytes + egg_path: str, + tmp_path: Path, + arch: str, + expected_wheelfile: bytes, + capsys: CaptureFixture, ) -> None: - convert([egg_path], str(tmp_path), verbose=False) + convert([egg_path], str(tmp_path), verbose=True) wheel_path = next(path for path in tmp_path.iterdir() if path.suffix == ".whl") - assert WHEEL_INFO_RE.match(wheel_path.name) with WheelFile(wheel_path) as wf: assert wf.read("sampledist-1.0.0.dist-info/METADATA") == EXPECTED_METADATA assert wf.read("sampledist-1.0.0.dist-info/WHEEL") == expected_wheelfile assert wf.read("sampledist-1.0.0.dist-info/entry_points.txt") == b"" + assert capsys.readouterr().out == f"{egg_path}...OK\n" + def test_convert_egg_directory( egg_path: str, @@ -204,30 +209,32 @@ def test_convert_egg_directory( tmp_path_factory: TempPathFactory, arch: str, expected_wheelfile: bytes, + capsys: CaptureFixture, ) -> None: with zipfile.ZipFile(egg_path) as egg_file: egg_dir_path = tmp_path_factory.mktemp("eggdir") / Path(egg_path).name egg_dir_path.mkdir() egg_file.extractall(egg_dir_path) - convert([str(egg_dir_path)], str(tmp_path), verbose=False) + convert([str(egg_dir_path)], str(tmp_path), verbose=True) wheel_path = next(path for path in tmp_path.iterdir() if path.suffix == ".whl") - assert WHEEL_INFO_RE.match(wheel_path.name) with WheelFile(wheel_path) as wf: assert wf.read("sampledist-1.0.0.dist-info/METADATA") == EXPECTED_METADATA assert wf.read("sampledist-1.0.0.dist-info/WHEEL") == expected_wheelfile assert wf.read("sampledist-1.0.0.dist-info/entry_points.txt") == b"" + assert capsys.readouterr().out == f"{egg_dir_path}...OK\n" + def test_convert_bdist_wininst( bdist_wininst_path: str, tmp_path: Path, arch: str, expected_wheelfile: bytes, + capsys: CaptureFixture, ) -> None: - convert([bdist_wininst_path], str(tmp_path), verbose=False) + convert([bdist_wininst_path], str(tmp_path), verbose=True) wheel_path = next(path for path in tmp_path.iterdir() if path.suffix == ".whl") - assert WHEEL_INFO_RE.match(wheel_path.name) with WheelFile(wheel_path) as wf: assert ( wf.read("sampledist-1.0.0.data/scripts/somecommand") @@ -236,3 +243,5 @@ def test_convert_bdist_wininst( assert wf.read("sampledist-1.0.0.dist-info/METADATA") == EXPECTED_METADATA assert wf.read("sampledist-1.0.0.dist-info/WHEEL") == expected_wheelfile assert wf.read("sampledist-1.0.0.dist-info/entry_points.txt") == b"" + + assert capsys.readouterr().out == f"{bdist_wininst_path}...OK\n"