Description
Your Environment
-
Your operating system: macOS
-
Version of python you are running: 3.7.6
-
How did you install twine? pipx
-
Version of twine you have installed (include complete output of):
twine version 3.1.1 (pkginfo: 1.5.0.1, requests: 2.22.0, setuptools: 45.1.0,
requests-toolbelt: 0.9.1, tqdm: 4.42.0)
- Which package repository are you targeting? pypi and testpypi
The Issue
Twine only uses the repository URL and username to retrieve the credentials, so the standard use of keyring doesn't seem support multiple project API tokens.
$ keyring set https://upload.pypi.org/legacy/ __token__
Password for '__token__' in 'https://upload.pypi.org/legacy/':
Possible Workaround
Adding the package name as a query parameter seems to work, but feels like a hack:
$ keyring set https://upload.pypi.org/legacy/?example-pkg __token__
Password for '__token__' in 'https://upload.pypi.org/legacy/?example-pkg':
$ twine upload \
--repository-url https://upload.pypi.org/legacy/?example-pkg \
--username __token__ \
dist/*
Or:
$ cat ~/.pypirc
[distutils]
index-servers =
pypi
example-pkg
[pypi]
username = __token__
[example-pkg]
repository = https://upload.pypi.org/legacy/?example-pkg
username = __token__
$ twine upload --repository example-pkg dist/*
Possible Solutions
Off the top of my head, without adding an additional argument to keyring:
-
Add the repository name to be part of the keyring
USERNAME
argument, e.g.:keyring set https://upload.pypi.org/legacy/ __token__:example-pkg
I think this might be relatively quick to implement, but feels clunky to document and use.
-
Use the repository name as the keyring
SERVICE
argument e.g.:keyring set example-pkg __token__ keyring set pypi __token__
This feels friendlier to users. However, I'm guessing it requires more substantial changes in twine's configuration handling.