Skip to content

Commit 68387af

Browse files
authored
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.
1 parent c81f5c9 commit 68387af

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

docs/news.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Release Notes
44
**UNRELEASED**
55

66
- Refactored the ``convert`` command to not need setuptools to be installed
7+
- Don't configure setuptools logging unless running ``bdist_wheel``
78
- Added a redirection from ``wheel.bdist_wheel.bdist_wheel`` to
89
``setuptools.command.bdist_wheel.bdist_wheel`` to improve compatibility with
910
``setuptools``' latest fixes.

src/wheel/_bdist_wheel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
if TYPE_CHECKING:
3535
import types
3636

37+
# ensure Python logging is configured
38+
try:
39+
__import__("setuptools.logging")
40+
except ImportError:
41+
# setuptools < ??
42+
from . import _setuptools_logging
43+
44+
_setuptools_logging.configure()
45+
3746

3847
def safe_name(name: str) -> str:
3948
"""Convert an arbitrary string to a standard distribution name

src/wheel/cli/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def convert(files: list[str], dest_dir: str, verbose: bool) -> None:
293293
source = WininstFileSource(path)
294294

295295
if verbose:
296-
print(f"{archive}... ", flush=True)
296+
print(f"{archive}...", flush=True, end="")
297297

298298
dest_path = Path(dest_dir) / (
299299
f"{source.name}-{source.version}-{source.pyver}-{source.abi}"

src/wheel/util.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55

66
log = logging.getLogger("wheel")
77

8-
# ensure Python logging is configured
9-
try:
10-
__import__("setuptools.logging")
11-
except ImportError:
12-
# setuptools < ??
13-
from . import _setuptools_logging
14-
15-
_setuptools_logging.configure()
16-
178

189
def urlsafe_b64encode(data: bytes) -> bytes:
1910
"""urlsafe_b64encode without padding"""

tests/cli/test_convert.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import pytest
99
from _pytest.fixtures import SubRequest
10-
from pytest import TempPathFactory
10+
from pytest import CaptureFixture, TempPathFactory
1111

1212
import wheel
1313
from wheel.cli.convert import convert, egg_filename_re
14-
from wheel.wheelfile import WHEEL_INFO_RE, WheelFile
14+
from wheel.wheelfile import WheelFile
1515

1616
PKG_INFO = """\
1717
Metadata-Version: 2.1
@@ -187,47 +187,54 @@ def test_egg_re() -> None:
187187

188188

189189
def test_convert_egg_file(
190-
egg_path: str, tmp_path: Path, arch: str, expected_wheelfile: bytes
190+
egg_path: str,
191+
tmp_path: Path,
192+
arch: str,
193+
expected_wheelfile: bytes,
194+
capsys: CaptureFixture,
191195
) -> None:
192-
convert([egg_path], str(tmp_path), verbose=False)
196+
convert([egg_path], str(tmp_path), verbose=True)
193197
wheel_path = next(path for path in tmp_path.iterdir() if path.suffix == ".whl")
194-
assert WHEEL_INFO_RE.match(wheel_path.name)
195198
with WheelFile(wheel_path) as wf:
196199
assert wf.read("sampledist-1.0.0.dist-info/METADATA") == EXPECTED_METADATA
197200
assert wf.read("sampledist-1.0.0.dist-info/WHEEL") == expected_wheelfile
198201
assert wf.read("sampledist-1.0.0.dist-info/entry_points.txt") == b""
199202

203+
assert capsys.readouterr().out == f"{egg_path}...OK\n"
204+
200205

201206
def test_convert_egg_directory(
202207
egg_path: str,
203208
tmp_path: Path,
204209
tmp_path_factory: TempPathFactory,
205210
arch: str,
206211
expected_wheelfile: bytes,
212+
capsys: CaptureFixture,
207213
) -> None:
208214
with zipfile.ZipFile(egg_path) as egg_file:
209215
egg_dir_path = tmp_path_factory.mktemp("eggdir") / Path(egg_path).name
210216
egg_dir_path.mkdir()
211217
egg_file.extractall(egg_dir_path)
212218

213-
convert([str(egg_dir_path)], str(tmp_path), verbose=False)
219+
convert([str(egg_dir_path)], str(tmp_path), verbose=True)
214220
wheel_path = next(path for path in tmp_path.iterdir() if path.suffix == ".whl")
215-
assert WHEEL_INFO_RE.match(wheel_path.name)
216221
with WheelFile(wheel_path) as wf:
217222
assert wf.read("sampledist-1.0.0.dist-info/METADATA") == EXPECTED_METADATA
218223
assert wf.read("sampledist-1.0.0.dist-info/WHEEL") == expected_wheelfile
219224
assert wf.read("sampledist-1.0.0.dist-info/entry_points.txt") == b""
220225

226+
assert capsys.readouterr().out == f"{egg_dir_path}...OK\n"
227+
221228

222229
def test_convert_bdist_wininst(
223230
bdist_wininst_path: str,
224231
tmp_path: Path,
225232
arch: str,
226233
expected_wheelfile: bytes,
234+
capsys: CaptureFixture,
227235
) -> None:
228-
convert([bdist_wininst_path], str(tmp_path), verbose=False)
236+
convert([bdist_wininst_path], str(tmp_path), verbose=True)
229237
wheel_path = next(path for path in tmp_path.iterdir() if path.suffix == ".whl")
230-
assert WHEEL_INFO_RE.match(wheel_path.name)
231238
with WheelFile(wheel_path) as wf:
232239
assert (
233240
wf.read("sampledist-1.0.0.data/scripts/somecommand")
@@ -236,3 +243,5 @@ def test_convert_bdist_wininst(
236243
assert wf.read("sampledist-1.0.0.dist-info/METADATA") == EXPECTED_METADATA
237244
assert wf.read("sampledist-1.0.0.dist-info/WHEEL") == expected_wheelfile
238245
assert wf.read("sampledist-1.0.0.dist-info/entry_points.txt") == b""
246+
247+
assert capsys.readouterr().out == f"{bdist_wininst_path}...OK\n"

0 commit comments

Comments
 (0)