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

Do not send empty fields in the upload form data #1203

Merged
merged 1 commit into from
Dec 18, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions twine/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ class PackageMetadata(TypedDict, total=False):
license_file: List[str]

# Additional metadata
comment: Optional[str]
comment: str
pyversion: str
filetype: str
gpg_signature: Tuple[str, bytes]
attestations: str
md5_digest: str
sha256_digest: Optional[str]
sha256_digest: str
blake2_256_digest: str


Expand Down Expand Up @@ -256,24 +256,30 @@ def metadata_dictionary(self) -> PackageMetadata:
# names are computed but they can only be valid key names.
data[field] = value # type: ignore[literal-required]

# override name with safe name
# Override name with safe name.
data["name"] = self.safe_name
# file content

# File content.
data["pyversion"] = self.python_version
data["filetype"] = self.filetype
# additional meta-data
data["comment"] = self.comment
data["sha256_digest"] = self.sha2_digest

# Additional meta-data: some of these fileds may not be set. Some
# package repositories do not allow null values, so this only sends
# non-null values. In particular, FIPS disables MD5 and Blake2, making
# the digest values null. See https://github.com/pypa/twine/issues/775

if self.comment is not None:
data["comment"] = self.comment

if self.sha2_digest is not None:
data["sha256_digest"] = self.sha2_digest

if self.gpg_signature is not None:
data["gpg_signature"] = self.gpg_signature

if self.attestations is not None:
data["attestations"] = json.dumps(self.attestations)

# FIPS disables MD5 and Blake2, making the digest values None. Some package
# repositories don't allow null values, so this only sends non-null values.
# See also: https://github.com/pypa/twine/issues/775
if self.md5_digest:
data["md5_digest"] = self.md5_digest

Expand Down
2 changes: 1 addition & 1 deletion twine/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _convert_metadata_to_list_of_tuples(
elif isinstance(value, (list, tuple)):
data_to_send.extend((key, item) for item in value)
else:
assert isinstance(value, str) or value is None
assert isinstance(value, str)
data_to_send.append((key, value))
return data_to_send

Expand Down
Loading