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

Only configure setuptools logging if bdist_wheel is imported #641

Merged
merged 12 commits into from
Nov 8, 2024
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__import__("setuptools.logging")
import setuptools.logging

Why not this? They should be the same, right? Usually you use this form if you have a variable value to import.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Though now I see this is just moved...)

except ImportError:

Check warning on line 40 in src/wheel/_bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/_bdist_wheel.py#L40

Added line #L40 was not covered by tests
# setuptools < ??
from . import _setuptools_logging

Check warning on line 42 in src/wheel/_bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/_bdist_wheel.py#L42

Added line #L42 was not covered by tests

_setuptools_logging.configure()

Check warning on line 44 in src/wheel/_bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/_bdist_wheel.py#L44

Added line #L44 was not covered by tests


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="")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be to stderr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so...? There's no docs indicating either way, and wheel tags prints the file names to stdout.


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"
Loading