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

Display error when uploading signed file with no distribution #932

Merged
merged 3 commits into from
Dec 5, 2022
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
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