diff --git a/AUTHORS b/AUTHORS index 1c12eb8c..d8034db5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -32,3 +32,4 @@ Yesha Maggi Cyril de Catheu (https://catheu.tech/) Thomas Miedema Hugo van Kemenade (https://github.com/hugovk) +Jacob Woliver (jmw.sh) diff --git a/changelog/931.misc.rst b/changelog/931.misc.rst new file mode 100644 index 00000000..5be844d5 --- /dev/null +++ b/changelog/931.misc.rst @@ -0,0 +1 @@ +Throws an error when uploading signed files without any distribution files. \ No newline at end of file diff --git a/tests/test_upload.py b/tests/test_upload.py index 29e39e02..438dbac0 100644 --- a/tests/test_upload.py +++ b/tests/test_upload.py @@ -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 diff --git a/twine/commands/upload.py b/twine/commands/upload.py index d3e4b92d..34d3c8c6 100644 --- a/twine/commands/upload.py +++ b/twine/commands/upload.py @@ -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"