Skip to content

Commit

Permalink
Only configure setuptools logging if bdist_wheel is imported (#641)
Browse files Browse the repository at this point in the history
Also fix the output of `wheel convert` to add the final "OK" on the same line as the source file name.

Fixes #632.
  • Loading branch information
agronholm authored Nov 8, 2024
1 parent c81f5c9 commit 68387af
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/wheel/_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/wheel/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
9 changes: 0 additions & 9 deletions src/wheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
27 changes: 18 additions & 9 deletions tests/cli/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,47 +187,54 @@ 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,
tmp_path: Path,
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")
Expand All @@ -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"

0 comments on commit 68387af

Please sign in to comment.