-
Notifications
You must be signed in to change notification settings - Fork 310
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
Recommended workflow for switching between multiple API tokens? #496
Comments
That looks accurate. I'd say that it's a hack but it's the first thing I thought of when I saw your question. It would probably be good to have another way of managing these though instead of forcing folks to use |
Ok, thanks @sigmavirus24. I will go ahead and get these instructions merged into Warehouse. |
@sigmavirus24 and @nlhkabu is it okay to close this? And/or should we open an issue for improving the UX for using Twine with API tokens? |
FYI @sigmavirus24 and @nlhkabu (and @di for good measure): After trying this out for myself, I think the instructions might not be sufficient. Given this [pypi]
username = __token__
[testpypi]
username = __token__
[example-pkg]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-... I get this output: $ twine upload --repository example-pkg dist/*
InvalidConfiguration: Missing 'example-pkg' section from the configuration file
or not a complete URL in --repository-url.
Maybe you have a out-dated '~/.pypirc' format?
more info: https://docs.python.org/distutils/packageindex.html#pypirc It works if add I this to the top of [distutils]
index-servers =
pypi
testpypi
example-pkg I discovered that Lines 78 to 85 in 330c0a2
A quick search didn't uncover any issues on Warehouse, which surprised me. It seems like a quick addition to the relevant Warehouse docs, but seems to add to the case for improving Twine's handling of tokens. |
Per my comment in pypa/twine#496 (comment), it seems a "project" repository must be defined in `index-servers` in order to be usable by twine.
Related: #565 - Not obvious how to use multiple project API tokens with keyring |
* Fix example .pypirc for project tokens Per my comment in pypa/twine#496 (comment), it seems a "project" repository must be defined in `index-servers` in order to be usable by twine. * Add missing repository option
While this works, I agree with @sigmavirus24 that it's a bit of a hack. I think it's probably worthwhile for us to think of a new and better way to do this in the Maybe something like this for repo-wide tokens: [distutils]
index-servers =
pypi
other
[pypi]
token = pypi-ABC...
[other]
repository = http://example.com/pypi
token = pypi-DEF... And this for project-specific tokens: [distutils]
index-servers =
pypi
other
[other]
repository = http://example.com/pypi
[pypi:example-pkg]
token = pypi-ABC...
[other:example-pkg]
token = pypi-DEF... |
Thanks, @di. I wondered how much freedom we might have with the FYI, there's an evolving discussion that started at pypa/packaging.python.org#297 (comment), where @jaraco and @takluyver have proposed some ideas on how to make this work with keyring and flit. |
I could be wrong, but I think these extra fields/sections would be ignored by any tool that doesn't know about them, so it should be fully backwards-compatible. |
Marked this and #565 as blocked until the discussion started at pypa/packaging.python.org#297 (comment) is resolved. |
The other thing to keep in mind is that the ini format is fairly flexible and projects like pytest and flake8 are able to do things like: option =
something: value
something-else: another-value So we could keep this super simple and have a: tokens =
*: pypi<general token>
twine: pypi<project-token>
... That keeps us from proliferating sections into the file, keeps the implementation simple, and is farily explicit without trying to hack around things. Then we can select the tokens out of there as necessary without doing "repository" based nonsense. Getting this to work with Keyring will be harder, as the discussion Brian linked indicates |
@sigmavirus24 How would that handle the same project name with different tokens across multiple repos? |
@di A more fully fledged example would be: [distutils]
index-servers =
pypi
other
another
[pypi]
tokens =
*: pypi-ABC...
twine: pypi-BCD...
etc: pypi-CDE...
[another]
repository = http://example.com/pypi
tokens =
*: pypi-DEF...
twine: pypi-EFG...
etc: pypi-FGH...
[other]
repository = http://test.example.com/pypi
tokens =
*: pypi-GHI...
etc: pypi-HIJ... |
Gotcha, so with that example, if the user just wanted to specify repo-wide tokens (which is probably the most common use case? maybe?) they'd have to write a minimum of: [distutils]
index-servers =
pypi
other
[pypi]
tokens =
*: pypi-ABC...
[other]
repository = http://test.example.com/pypi
tokens =
*: pypi-GHI... which feels clunky compared to: [distutils]
index-servers =
pypi
other
[pypi]
token = pypi-ABC...
[other]
repository = http://example.com/pypi
token = pypi-DEF... |
From pypa/packaging.python.org#297, it seems like the ideal scenario is that tokens are not stored in |
I think you're always going to have people who would prefer not to use keyring. And we'd have to go through a lengthy deprecation period to kill that off which isn't worth the effort frankly.
The fact that we don't know what the most common use-case is suggests that we don't know enough to continue pushing forward on making the right choice |
As of right now, 60% of PyPI users who own/maintain at least package only have one package:
|
Related (I think): I just put up a draft PR that documents the current spec of Also, we're talking a lot about I'm wondering if it might be simpler to keep the current convention, but mitigate the hack by defaulting I think that would also require fewer updates to the docs in Twine, PPUG, and Warehouse. |
Is there a way to tell what % of that 60% use tokens at all? Here's the point: If we go with We should be meeting folks where they are today, certainly, but we should also be striving to push the community forward with the gentlest nudges we can think of. |
@sigmavirus24 I think @di's original suggestion handles project-scoped tokens via additional sections that inherit from the "base" section: [pypi]
token = pypi-ABC...
[pypi:example-pkg]
token = pypi-DEF... Another idea: [pypi]
token = pypi-ABC...
project_tokens =
example-pkg: pypi-DEF... That said, I'd still like to consider sticking with the current [distutils]
index-servers =
pypi
testpypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = __token__
[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__ which I think leans more towards something like this: [pypi]
password = pypi-ABC...
[pypi:example-pkg]
password = pypi-DEF... |
Building on my last suggestion, combined with my second proposal in #565 and pypa/packaging.python.org#297 (comment), I think this would allow CLI commands like:
Aside: looking over those other issues makes me wonder if this is conversation should be moved to https://discuss.python.org/c/packaging/. |
A few things on the password/token "hack":
|
I faced the similar issue today To reproduceOS: Ubuntu 22.04
Twine command
What worked
|
@shon Can you try adding
I think that will allow you to run:
|
Thanks @bhrutledge that worked! |
@shon Me neither, which led to the discussion starting at #496 (comment). |
Agree with @shon. I like @bhrutledge and @di's comments on a path forward. |
This comment has been minimized.
This comment has been minimized.
Chiming in briefly to inquire if there's appetite for removing the need for the entire
Is there still a benefit to preserving usage of this indirection, vs setting sections and looking for those? (Potentially replace |
Hi folks
I am working on adding instructions to the 'Add API token' page on PyPI (see pypi/warehouse#6615). Currently, the instructions look like this:
API token for an entire PyPI account
We suggest that users create a
.pypirc
file in their home directory with the token details:Token scoped to a PyPI project
We suggest that users can switch between multiple tokens with
<code>twine --repository PROJECT_NAME</code>
Questions
Thanks :)
The text was updated successfully, but these errors were encountered: