Skip to content

Commit ad1c1e9

Browse files
committed
upload: warn about potential PGP deprecation
Signed-off-by: William Woodruff <william@yossarian.net>
1 parent 96674db commit ad1c1e9

File tree

2 files changed

+58
-17
lines changed

2 files changed

+58
-17
lines changed

tests/test_upload.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
import pytest
1818
import requests
1919

20-
from twine import cli
21-
from twine import exceptions
20+
from twine import cli, exceptions
2221
from twine import package as package_file
2322
from twine.commands import upload
2423

@@ -184,6 +183,43 @@ def test_success_with_pre_signed_distribution(upload_settings, stub_repository,
184183
)
185184

186185

186+
def test_warns_potential_pgp_removal_on_3p_index(
187+
make_settings, stub_repository, caplog
188+
):
189+
"""Warn when a PGP signature is specified for upload to a third-party index."""
190+
191+
upload_settings = make_settings(
192+
"""
193+
[pypi]
194+
repository: https://example.com/not-a-real-index/
195+
username:foo
196+
password:bar
197+
"""
198+
)
199+
upload_settings.create_repository = lambda: stub_repository
200+
201+
# Upload a pre-signed distribution
202+
result = upload.upload(
203+
upload_settings, [helpers.WHEEL_FIXTURE, helpers.WHEEL_FIXTURE + ".asc"]
204+
)
205+
assert result is None
206+
207+
# The signature should be added via package.add_gpg_signature()
208+
package = stub_repository.upload.calls[0].args[0]
209+
assert package.gpg_signature == (
210+
"twine-1.5.0-py2.py3-none-any.whl.asc",
211+
b"signature",
212+
)
213+
214+
# Ensure that a warning is emitted.
215+
assert (
216+
"One or more packages has an associated PGP signature; a future "
217+
"version of twine may silently ignore these. See "
218+
"https://github.com/pypa/twine/issues/1009 for more information"
219+
in caplog.messages
220+
)
221+
222+
187223
def test_exception_with_only_pre_signed_file(upload_settings, stub_repository):
188224
"""Raise an exception when only a signed file is uploaded."""
189225
# Upload only pre-signed file

twine/commands/upload.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
import requests
2121
from rich import print
2222

23-
from twine import commands
24-
from twine import exceptions
23+
from twine import commands, exceptions, settings, utils
2524
from twine import package as package_file
26-
from twine import settings
27-
from twine import utils
2825

2926
logger = logging.getLogger(__name__)
3027

@@ -124,17 +121,25 @@ def upload(upload_settings: settings.Settings, dists: List[str]) -> None:
124121
_make_package(filename, signatures, upload_settings) for filename in uploads
125122
]
126123

127-
# Warn the user if they're trying to upload a PGP signature to PyPI
128-
# or TestPyPI, which will (as of May 2023) ignore it.
129-
# This check is currently limited to just those indices, since other
130-
# indices may still support PGP signatures.
131-
if any(p.gpg_signature for p in packages_to_upload) and repository_url.startswith(
132-
(utils.DEFAULT_REPOSITORY, utils.TEST_REPOSITORY)
133-
):
134-
logger.warning(
135-
"One or more packages has an associated PGP signature; "
136-
"these will be silently ignored by the index"
137-
)
124+
if any(p.gpg_signature for p in packages_to_upload):
125+
if repository_url.startswith((utils.DEFAULT_REPOSITORY, utils.TEST_REPOSITORY)):
126+
# Warn the user if they're trying to upload a PGP signature to PyPI
127+
# or TestPyPI, which will (as of May 2023) ignore it.
128+
# This warning is currently limited to just those indices, since other
129+
# indices may still support PGP signatures.
130+
logger.warning(
131+
"One or more packages has an associated PGP signature; "
132+
"these will be silently ignored by the index"
133+
)
134+
else:
135+
# On other indices, warn the user that twine is considering
136+
# removing PGP support outright.
137+
logger.warning(
138+
"One or more packages has an associated PGP signature; "
139+
"a future version of twine may silently ignore these. "
140+
"See https://github.com/pypa/twine/issues/1009 for more "
141+
"information"
142+
)
138143

139144
repository = upload_settings.create_repository()
140145
uploaded_packages = []

0 commit comments

Comments
 (0)