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

Improve error message for unsupported metadata #755

Merged
merged 2 commits into from May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/755.bugfix.rst
@@ -0,0 +1 @@
Improve error message for unsupported metadata.
1 change: 1 addition & 0 deletions tests/test_package.py
Expand Up @@ -278,6 +278,7 @@ def EmptyDist(filename):
package_file.PackageFile.from_filename(filename, comment=None)

assert "Invalid distribution metadata" in err.value.args[0]
assert "1.0, 1.1, 1.2, 2.0, and 2.1" in err.value.args[0]


def test_malformed_from_file(monkeypatch):
Expand Down
5 changes: 4 additions & 1 deletion twine/package.py
Expand Up @@ -105,8 +105,11 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
# give us back empty metadata. At the very least, we should have a name
# and version
if not (meta.name and meta.version):
supported_metadata = list(pkginfo.distribution.HEADER_ATTRS)
raise exceptions.InvalidDistribution(
"Invalid distribution metadata. Try upgrading twine if possible."
"Invalid distribution metadata. "
"This version of twine supports Metadata-Version "
f"{', '.join(supported_metadata[:-1])}, and {supported_metadata[-1]}"
)

py_version: Optional[str]
Expand Down