Skip to content

Commit

Permalink
Display error when uploading signed file with no distribution
Browse files Browse the repository at this point in the history
Related to pypa#931.

If a user only uploads a signed .asc file without any distribution
files, this now throws an error to make it more clear why Twine
doesn't do anything.
  • Loading branch information
jmwoliver committed Oct 20, 2022
1 parent bb51e46 commit eec4d5a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ Yesha Maggi <yesha.maggic@gmail.com>
Cyril de Catheu <cdecatheu@gmail.com> (https://catheu.tech/)
Thomas Miedema <thomasmiedema@gmail.com>
Hugo van Kemenade (https://github.com/hugovk)
Jacob Woliver <jacob@jmw.sh> (jmw.sh)
1 change: 1 addition & 0 deletions changelog/931.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Throws an error when uploading signed files without any distribution files.
12 changes: 12 additions & 0 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ def test_success_with_pre_signed_distribution(upload_settings, stub_repository):
)


def test_exception_with_only_pre_signed_file(upload_settings, stub_repository):
"""Raise an exception when only a signed file is uploaded."""
# Upload only pre-signed file
with pytest.raises(exceptions.InvalidDistribution) as err:
upload.upload(upload_settings, [helpers.WHEEL_FIXTURE + ".asc"])

assert (
"Cannot upload signed files by themselves, must upload with a "
"corresponding distribution." in err.value.args[0]
)


def test_success_when_gpg_is_run(upload_settings, stub_repository, monkeypatch):
"""Add GPG signature generated by gpg command to uploaded package."""
# Indicate that upload() should run_gpg() to generate the signature, which
Expand Down
8 changes: 8 additions & 0 deletions twine/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def upload(upload_settings: settings.Settings, dists: List[str]) -> None:
repository = upload_settings.create_repository()
uploaded_packages = []

# If a user tries to upload signature files with no actual distributions,
# then throw an error.
if len(packages_to_upload) == 0 and len(signatures) > 0:
raise exceptions.InvalidDistribution(
"Cannot upload signed files by themselves, must upload with a "
"corresponding distribution."
)

for package in packages_to_upload:
skip_message = (
f"Skipping {package.basefilename} because it appears to already exist"
Expand Down

0 comments on commit eec4d5a

Please sign in to comment.