Skip to content

Commit

Permalink
Do not send empty fields in the upload form data
Browse files Browse the repository at this point in the history
No behavior changes intended. Just cleaning up some loose ends.
  • Loading branch information
dnicolodi authored and sigmavirus24 committed Dec 18, 2024
1 parent 0605ef0 commit 5a783b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
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

0 comments on commit 5a783b7

Please sign in to comment.