Skip to content

Set trusted publishing logging to INFO/WARN #1247

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pnacht
Copy link

@pnacht pnacht commented May 30, 2025

Trusted publishing is the only part of the codebase using logger.debug(), which can't be easily accessed from the CLI. This PR changes most to logger.info – therefore always printing them – and one to logger.warning() (visible with --verbose).

Trusted publishing is the only part of the codebase using
`logger.debug()`, which can't be easily accessed from the CLI.
This PR changes these to either `logger.info` or `logger.warning()`,
such that all are visible with `--verbose`.

Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
@woodruffw
Copy link
Member

Hi @pnacht, thanks for opening a PR!

I have no strong feelings either way, but maybe these should all be WARN, i.e. only visible with --verbose? That feels like a slight misuse of the WARN level but OTOH it would be consistent with the other credential sources (which generally don't spit out much via the logger by default).

Curious what you think.

@pnacht
Copy link
Author

pnacht commented May 30, 2025

I'd initially written it like that (everything as WARN) for that precise reason, but couldn't find anywhere else in the codebase "misusing" the log level like that (everywhere else really is warning about something), so moved most of them to INFO to be consistent with the rest of the codebase.

I'd be totally fine setting everything to WARN, though I'd actually be partial to leaving the "first" instance (Trying to use trusted publishing (no token was explicitly provided)) as INFO just to make it clear what's happening.

Currently, twine's output using TP looks like this:

Uploading distributions to https://test.pypi.org/legacy/
INFO     ... artifact names ...
INFO     username set by command options
INFO     Querying keyring for password
INFO     username: __token__
INFO     password: <hidden>

Reading this, it looks like the password was fetched from the keyring, which isn't the case. By keeping at least that "first" instance as INFO, the output will be

Uploading distributions to https://test.pypi.org/legacy/
INFO     ... artifact names ...
INFO     username set by command options
INFO     Querying keyring for password
INFO     Trying to use trusted publishing (no token was explicitly provided)
INFO     username: __token__
INFO     password: <hidden>

This makes it clear that the keyring was queried (silently found nothing) and twine then tried TP.

Indeed, this PR came about because I was having some trouble configuring TP for a package, saw the current logs and thought I'd somehow mysteriously added something to the keyring. I only managed to confirm twine was actually attempting TP when I looked at the source code and noticed that twine actually logs when it gets something from the keyring (which didn't happen in this case):

twine/twine/auth.py

Lines 175 to 184 in 4b6c50b

def password_from_keyring_or_trusted_publishing_or_prompt(self) -> str:
password = self.get_password_from_keyring()
if password:
logger.info("password set from keyring")
return password
if self.is_pypi() and self.username == "__token__":
logger.debug(
"Trying to use trusted publishing (no token was explicitly provided)"
)

@woodruffw
Copy link
Member

Gotcha, thanks! That's really helpful context, and this change makes a lot of sense to me given that.

Would you mind adding a quick changelog entry too? The docs should point you the right way: https://twine.readthedocs.io/en/stable/contributing.html#changelog-entries

Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
@pnacht
Copy link
Author

pnacht commented Jun 2, 2025

Would you mind adding a quick changelog entry too? The docs should point you the right way: https://twine.readthedocs.io/en/stable/contributing.html#changelog-entries

Done.

As per our previous comments, I've also gone ahead and set all but one of the messages to warning(), leaving just the first message as info().

Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pnacht!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants