Skip to content

Commit 279b5ec

Browse files
committed
upload: turn attestation error into a warning
Signed-off-by: William Woodruff <[email protected]>
1 parent 5d17a43 commit 279b5ec

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

tests/test_upload.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,20 @@ def test_check_status_code_for_wrong_repo_url(repo_url, upload_settings, stub_re
672672
)
673673

674674

675-
def test_upload_rejects_attestations_non_pypi(upload_settings):
675+
def test_upload_warns_attestations_non_pypi(upload_settings, caplog, stub_response):
676676
upload_settings.repository_config["repository"] = "https://notpypi.example.com"
677677
upload_settings.attestations = True
678678

679-
with pytest.raises(
680-
exceptions.InvalidConfiguration, match="may only be used with PyPI and TestPyPI"
681-
):
679+
# This fails because the attestation isn't a real file, which is fine
680+
# since our functionality under test happens before the failure.
681+
with pytest.raises(exceptions.InvalidDistribution):
682682
upload.upload(
683683
upload_settings,
684684
[helpers.WHEEL_FIXTURE, helpers.WHEEL_FIXTURE + ".foo.attestation"],
685685
)
686+
687+
assert (
688+
"Only PyPI and TestPyPI support attestations; if you experience "
689+
"failures, remove the --attestations flag and re-try this command"
690+
in caplog.messages
691+
)

twine/commands/upload.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,15 @@ def upload(upload_settings: settings.Settings, dists: List[str]) -> None:
174174
repository_url = cast(str, upload_settings.repository_config["repository"])
175175

176176
# Attestations are only supported on PyPI and TestPyPI at the moment.
177-
# We fail early here if the user requests any other index, to prevent
178-
# users from attempting to use `--attestations` on other indices and
179-
# failing bugs when upload fails.
177+
# We warn instead of failing to allow twine to be used in local testing
178+
# setups (where the PyPI deployment doesn't have a well-known domain).
180179
if upload_settings.attestations and not repository_url.startswith(
181180
(utils.DEFAULT_REPOSITORY, utils.TEST_REPOSITORY)
182181
):
183-
raise exceptions.InvalidConfiguration(
184-
"The --attestations flag may only be used with PyPI and TestPyPI"
182+
logger.warning(
183+
"Only PyPI and TestPyPI support attestations; "
184+
"if you experience failures, remove the --attestations flag and "
185+
"re-try this command"
185186
)
186187

187188
dists = commands._find_dists(dists)

0 commit comments

Comments
 (0)