Parameterize wheel file path for metadata extraction

This commit is contained in:
Chris Hunt 2020-01-01 19:22:41 -05:00
parent 20706eb93f
commit ae34781826
2 changed files with 9 additions and 6 deletions

View File

@ -93,18 +93,21 @@ def wheel_metadata(source, dist_info_dir):
"""Return the WHEEL metadata of an extracted wheel, if possible.
Otherwise, raise UnsupportedWheel.
"""
# Zip file path separators must be /
path = "{}/WHEEL".format(dist_info_dir)
try:
# Zip file path separators must be /
wheel_contents = source.read("{}/WHEEL".format(dist_info_dir))
wheel_contents = source.read(path)
# BadZipFile for general corruption, KeyError for missing entry,
# and RuntimeError for password-protected files
except (BadZipFile, KeyError, RuntimeError) as e:
raise UnsupportedWheel("could not read WHEEL file: {!r}".format(e))
raise UnsupportedWheel(
"could not read {!r} file: {!r}".format(path, e)
)
try:
wheel_text = ensure_str(wheel_contents)
except UnicodeDecodeError as e:
raise UnsupportedWheel("error decoding WHEEL: {!r}".format(e))
raise UnsupportedWheel("error decoding {!r}: {!r}".format(path, e))
# FeedParser (used by Parser) does not raise any exceptions. The returned
# message may have .defects populated, but for backwards-compatibility we

View File

@ -85,7 +85,7 @@ def test_wheel_metadata_fails_missing_wheel(tmpdir, zip_dir):
with pytest.raises(UnsupportedWheel) as e:
wheel.wheel_metadata(zip_dir(tmpdir), dist_info_dir.name)
assert "could not read WHEEL file" in str(e.value)
assert "could not read" in str(e.value)
@skip_if_python2
@ -97,7 +97,7 @@ def test_wheel_metadata_fails_on_bad_encoding(tmpdir, zip_dir):
with pytest.raises(UnsupportedWheel) as e:
wheel.wheel_metadata(zip_dir(tmpdir), dist_info_dir.name)
assert "error decoding WHEEL" in str(e.value)
assert "error decoding" in str(e.value)
def test_wheel_version_fails_on_no_wheel_version():