Skip to content

publish: token auth difficulty with .pypirc #1979

@thatch

Description

@thatch

Following the docs at https://hatch.pypa.io/1.13/how-to/publish/auth/ I encountered three minor issues.

  1. The prompt for username seemed like it would default to __token__ but wouldn't use that when pressing Enter, I had to type it in
Username for 'https://upload.pypi.org/legacy/' [__token__]: <Enter>
Username for 'https://upload.pypi.org/legacy/' [__token__]: __token__
# Continues
  1. Plaintext password in ~/.pypirc was not found. I'm wondering if repo is something other than pypi, as my config is very simple
[pypi]
username = __token__
password = pypi-...
  1. Missing keyring was fatal, it never got to the last step of prompting.
Details ``` (.venv) [tim@wednesday squatter]$ export HATCH_INDEX_USER=__token__ (.venv) [tim@wednesday squatter]$ squatter generate malo --upload ─────────────────────────────────────────────────────────── sdist ──────────────────────────────────────────────────────────── dist/malo-0.0.0a1.tar.gz ─────────────────────────────────────────────────────────── wheel ──────────────────────────────────────────────────────────── dist/malo-0.0.0a1-py2.py3-none-any.whl ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/hatch/cli/__init__.py:221 in main │ │ │ │ 218 │ │ 219 def main(): # no cov │ │ 220 │ try: │ │ ❱ 221 │ │ hatch(prog_name='hatch', windows_expand_args=False) │ │ 222 │ except Exception: # noqa: BLE001 │ │ 223 │ │ import sys │ │ 224 │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/click/core.py:1442 in __call__ │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/click/core.py:1363 in main │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/click/core.py:1830 in invoke │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/click/core.py:1226 in invoke │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/click/core.py:794 in invoke │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/click/decorators.py:46 in new_func │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/hatch/cli/publish/__init__.py:115 in │ │ publish │ │ │ │ 112 │ if publisher.disable and not (yes or (not no_prompt and app.confirm(f'Confirm `{publ │ │ 113 │ │ app.abort(f'Publisher is disabled: {publisher_name}') │ │ 114 │ │ │ ❱ 115 │ publisher.publish(list(artifacts), option_map) │ │ 116 │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/hatch/publish/index.py:74 in publish │ │ │ │ 71 │ │ index = PackageIndex( │ │ 72 │ │ │ repo_config['url'], │ │ 73 │ │ │ user=credentials.username, │ │ ❱ 74 │ │ │ auth=credentials.password, │ │ 75 │ │ │ ca_cert=options.get('ca_cert', repo_config.get('ca-cert')), │ │ 76 │ │ │ client_cert=options.get('client_cert', repo_config.get('client-cert')), │ │ 77 │ │ │ client_key=options.get('client_key', repo_config.get('client-key')), │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/hatch/publish/auth.py:30 in password │ │ │ │ 27 │ @Property │ │ 28 │ def password(self) -> str: │ │ 29 │ │ if self.__password is None: │ │ ❱ 30 │ │ │ self.__password = self.__get_password() │ │ 31 │ │ return self.__password │ │ 32 │ │ │ 33 │ @Property │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/hatch/publish/auth.py:49 in │ │ __get_password │ │ │ │ 46 │ │ │ │ 47 │ │ import keyring │ │ 48 │ │ │ │ ❱ 49 │ │ password = keyring.get_password(self._repo, self.username) │ │ 50 │ │ if password is not None: │ │ 51 │ │ │ return password │ │ 52 │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/keyring/core.py:63 in get_password │ │ │ │ 60 │ │ 61 def get_password(service_name: str, username: str) -> typing.Optional[str]: │ │ 62 │ """Get password from the specified service.""" │ │ ❱ 63 │ return get_keyring().get_password(service_name, username) │ │ 64 │ │ 65 │ │ 66 def set_password(service_name: str, username: str, password: str) -> None: │ │ │ │ /home/tim/code/squatter/.venv/lib/python3.13/site-packages/keyring/backends/fail.py:28 in │ │ get_password │ │ │ │ 25 │ │ │ "you want to use the non-recommended backends. See " │ │ 26 │ │ │ "https://pypi.org/project/keyring for details." │ │ 27 │ │ ) │ │ ❱ 28 │ │ raise NoKeyringError(msg) │ │ 29 │ │ │ 30 │ set_password = delete_password = get_password │ │ 31 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ NoKeyringError: No recommended backend was available. Install a recommended 3rd party backend package; or, install the keyrings.alt package if you want to use the non-recommended backends. See https://pypi.org/project/keyring for details. ```

I'm happy to gather more debug logs shortly, this was discovered inside some automation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions