Skip to content

Commit

Permalink
Display error when uploading signed file with no distribution (#932)
Browse files Browse the repository at this point in the history
* Display error when uploading signed file with no distribution

Related to #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.

* Simplify logic

* Clarify error message

Co-authored-by: Jacob Woliver <[email protected]>
  • Loading branch information
jmwoliver and jmwoliver authored Dec 5, 2022
1 parent 75c3d86 commit a43f6ea
Show file tree
Hide file tree
Showing 4 changed files with 20 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 <[email protected]>
Cyril de Catheu <[email protected]> (https://catheu.tech/)
Thomas Miedema <[email protected]>
Hugo van Kemenade (https://github.com/hugovk)
Jacob Woliver <[email protected]> (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 file." 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
6 changes: 6 additions & 0 deletions twine/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ def upload(upload_settings: settings.Settings, dists: List[str]) -> None:
repository = upload_settings.create_repository()
uploaded_packages = []

if signatures and not packages_to_upload:
raise exceptions.InvalidDistribution(
"Cannot upload signed files by themselves, must upload with a "
"corresponding distribution file."
)

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

0 comments on commit a43f6ea

Please sign in to comment.