Skip to content

Commit 010c24d

Browse files
committed
Take .dist-info dir directly in wheel_metadata
Since retrieval of the .dist-info dir already ensures that a distribution is found, this reduces responsibility on wheel_metadata and lets us remove a few tests already covered by the tests for test_wheel_dist_info_dir_*.
1 parent fc48a17 commit 010c24d

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

src/pip/_internal/operations/install/wheel.py

+4-18
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def install_unpacked_wheel(
315315

316316
try:
317317
info_dir = wheel_dist_info_dir(source, name)
318-
metadata = wheel_metadata(wheeldir)
318+
metadata = wheel_metadata(source, info_dir)
319319
version = wheel_version(metadata)
320320
except UnsupportedWheel as e:
321321
raise UnsupportedWheel(
@@ -658,27 +658,13 @@ def wheel_dist_info_dir(source, name):
658658
return info_dir
659659

660660

661-
def wheel_metadata(source_dir):
662-
# type: (Optional[str]) -> Message
661+
def wheel_metadata(source, dist_info_dir):
662+
# type: (str, str) -> Message
663663
"""Return the WHEEL metadata of an extracted wheel, if possible.
664664
Otherwise, raise UnsupportedWheel.
665665
"""
666666
try:
667-
dists = [d for d in pkg_resources.find_on_path(None, source_dir)]
668-
except Exception as e:
669-
raise UnsupportedWheel(
670-
"could not find a contained distribution due to: {!r}".format(e)
671-
)
672-
673-
if not dists:
674-
raise UnsupportedWheel("no contained distribution found")
675-
676-
dist = dists[0]
677-
678-
dist_info_dir = os.path.basename(dist.egg_info)
679-
680-
try:
681-
with open(os.path.join(source_dir, dist_info_dir, "WHEEL"), "rb") as f:
667+
with open(os.path.join(source, dist_info_dir, "WHEEL"), "rb") as f:
682668
wheel_text = ensure_str(f.read())
683669
except (IOError, OSError) as e:
684670
raise UnsupportedWheel("could not read WHEEL file: {!r}".format(e))

tests/unit/test_wheel.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from email import message_from_string
77

88
import pytest
9-
from mock import Mock, patch
10-
from pip._vendor import pkg_resources
9+
from mock import patch
1110
from pip._vendor.packaging.requirements import Requirement
1211

1312
from pip._internal.exceptions import UnsupportedWheel
@@ -224,27 +223,13 @@ def test_wheel_version_ok(tmpdir, data):
224223
) == (1, 9)
225224

226225

227-
def test_wheel_metadata_fails_on_error(monkeypatch):
228-
err = RuntimeError("example")
229-
monkeypatch.setattr(pkg_resources, "find_on_path", Mock(side_effect=err))
230-
with pytest.raises(UnsupportedWheel) as e:
231-
wheel.wheel_metadata(".")
232-
assert repr(err) in str(e.value)
233-
234-
235-
def test_wheel_metadata_fails_no_dists(tmpdir):
236-
with pytest.raises(UnsupportedWheel) as e:
237-
wheel.wheel_metadata(str(tmpdir))
238-
assert "no contained distribution found" in str(e.value)
239-
240-
241226
def test_wheel_metadata_fails_missing_wheel(tmpdir):
242227
dist_info_dir = tmpdir / "simple-0.1.0.dist-info"
243228
dist_info_dir.mkdir()
244229
dist_info_dir.joinpath("METADATA").touch()
245230

246231
with pytest.raises(UnsupportedWheel) as e:
247-
wheel.wheel_metadata(str(tmpdir))
232+
wheel.wheel_metadata(str(tmpdir), dist_info_dir.name)
248233
assert "could not read WHEEL file" in str(e.value)
249234

250235

@@ -256,7 +241,7 @@ def test_wheel_metadata_fails_on_bad_encoding(tmpdir):
256241
dist_info_dir.joinpath("WHEEL").write_bytes(b"\xff")
257242

258243
with pytest.raises(UnsupportedWheel) as e:
259-
wheel.wheel_metadata(str(tmpdir))
244+
wheel.wheel_metadata(str(tmpdir), dist_info_dir.name)
260245
assert "error decoding WHEEL" in str(e.value)
261246

262247

0 commit comments

Comments
 (0)