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

upload: turn attestation error into a warning #1101

Merged
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
14 changes: 10 additions & 4 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,14 +672,20 @@ def test_check_status_code_for_wrong_repo_url(repo_url, upload_settings, stub_re
)


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

with pytest.raises(
exceptions.InvalidConfiguration, match="may only be used with PyPI and TestPyPI"
):
# This fails because the attestation isn't a real file, which is fine
# since our functionality under test happens before the failure.
with pytest.raises(exceptions.InvalidDistribution):
upload.upload(
upload_settings,
[helpers.WHEEL_FIXTURE, helpers.WHEEL_FIXTURE + ".foo.attestation"],
)

assert (
"Only PyPI and TestPyPI support attestations; if you experience "
"failures, remove the --attestations flag and re-try this command"
in caplog.messages
)
11 changes: 6 additions & 5 deletions twine/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ def upload(upload_settings: settings.Settings, dists: List[str]) -> None:
repository_url = cast(str, upload_settings.repository_config["repository"])

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

dists = commands._find_dists(dists)
Expand Down
Loading