diff --git a/tests/test_wheel.py b/tests/test_wheel.py index 485c89f0..eae3bd95 100644 --- a/tests/test_wheel.py +++ b/tests/test_wheel.py @@ -96,6 +96,8 @@ def test_read_wheel_empty_metadata(tmpdir): with pytest.raises( exceptions.InvalidDistribution, - match=re.escape(f"No METADATA in archive: {whl_file}"), + match=re.escape( + f"No METADATA in archive or METADATA missing 'Metadata-Version': {whl_file}" + ), ): wheel.Wheel(whl_file) diff --git a/twine/wheel.py b/twine/wheel.py index 7af1d804..a2a8ba8a 100644 --- a/twine/wheel.py +++ b/twine/wheel.py @@ -73,16 +73,21 @@ def read_file(name: str) -> bytes: "Not a known archive format for file: %s" % fqn ) + searched_files: List[str] = [] try: for path in self.find_candidate_metadata_files(names): candidate = "/".join(path) data = read_file(candidate) if b"Metadata-Version" in data: return data + searched_files.append(candidate) finally: archive.close() - raise exceptions.InvalidDistribution("No METADATA in archive: %s" % fqn) + raise exceptions.InvalidDistribution( + "No METADATA in archive or METADATA missing 'Metadata-Version': " + "%s (searched %s)" % (fqn, ",".join(searched_files)) + ) def parse(self, data: bytes) -> None: super().parse(data)