Skip to content

Commit 0a9ff9d

Browse files
uranusjrDos Moonen
authored and
Dos Moonen
committed
Revise documentation on keyring
1 parent 33cd541 commit 0a9ff9d

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

docs/html/topics/authentication.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,21 @@ man pages][netrc-docs].
6666
## Keyring Support
6767

6868
pip supports loading credentials stored in your keyring using the
69-
{pypi}`keyring` library which can be enabled py passing `--keyring-provider`
70-
with a value of `auto`, `disabled`, `import` or `subprocess`. The default value
71-
is `auto`. `auto` will respect `--no-input` and not query keyring at all if that
72-
option is used. The `auto` provider will use the `import` provider if the
73-
`keyring` module can be imported. If that is not the case it will use the
74-
`subprocess` provider if a `keyring` executable can be found. Otherwise, the
75-
`disabled` provider will be used.
76-
77-
### Configuring Pip
78-
Passing this as a command line argument will work, but is not how the majority
79-
of this feature's users will use it. They instead will want to overwrite the
80-
default of `disabled` in the global, user of site configuration file:
69+
{pypi}`keyring` library, which can be enabled py passing `--keyring-provider`
70+
with a value of `auto`, `disabled`, `import`, or `subprocess`. The default
71+
value `auto` respects `--no-input` and not query keyring at all if the option
72+
is used; otherwise it tries the `import`, `subprocess`, and `disabled`
73+
providers (in this order) and uses the first one that works.
74+
75+
### Configuring pip's keyring usage
76+
77+
Since the keyring configuration is likely system-wide, a more common way to
78+
configure its usage would be to use a configuration instead:
79+
80+
```{seealso}
81+
{doc}`./configuration` describes how pip configuration works.
82+
```
83+
8184
```bash
8285
$ pip config set --global global.keyring-provider subprocess
8386

@@ -95,10 +98,10 @@ $ pip config set --site global.keyring-provider disabled
9598
$ export PIP_KEYRING_PROVIDER=disabled
9699
```
97100

98-
### Installing and using the keyring python module
101+
### Using keyring's Python module
99102

100-
Setting it to `import` tries to communicate with `keyring` by importing it
101-
and using its Python api.
103+
Setting `keyring-provider` to `import` makes pip communicate with `keyring` via
104+
its Python interface.
102105

103106
```bash
104107
# install keyring from PyPI
@@ -107,29 +110,28 @@ $ echo "your-password" | keyring set pypi.company.com your-username
107110
$ pip install your-package --keyring-provider import --index-url https://pypi.company.com/
108111
```
109112

110-
### Installing and using the keyring cli application
113+
### Using keyring as a command line application
111114

112-
Setting it to `subprocess` will look for a `keyring` executable on the PATH
113-
if one can be found that is different from the `keyring` installation `import`
114-
would be using.
115+
Setting `keyring-provider` to `subprocess` makes pip look for and use the
116+
`keyring` command found on `PATH`.
115117

116-
The cli requires a username, therefore you MUST put a username in the url.
117-
See the example below or the basic HTTP authentication section at the top of
118-
this page.
118+
For this use case, a username *must* be included in the URL, since it is
119+
required by `keyring`'s command line interface. See the example below or the
120+
basic HTTP authentication section at the top of this page.
119121

120122
```bash
121-
# install keyring from PyPI using pipx, which we assume if installed properly
123+
# Install keyring from PyPI using pipx, which we assume if installed properly
122124
# you can also create a venv somewhere and add it to the PATH yourself instead
123125
$ pipx install keyring --index-url https://pypi.org/simple
124126

125-
# install the keyring backend for Azure DevOps for example
126-
# VssSessionToken is the username you MUST use for this backend
127+
# For Azure DevOps, also install its keyring backend.
127128
$ pipx inject keyring artifacts-keyring --index-url https://pypi.org/simple
128129

129-
# or the one for Google Artifact Registry
130+
# For Google Artifact Registry, also install and initialize its keyring backend.
130131
$ pipx inject keyring keyrings.google-artifactregistry-auth --index-url https://pypi.org/simple
131132
$ gcloud auth login
132133

134+
# Note that a username is required in the index URL.
133135
$ pip install your-package --keyring-provider subprocess --index-url https://[email protected]/
134136
```
135137

@@ -155,13 +157,13 @@ $ export PIP_KEYRING_PROVIDER=import
155157
```
156158

157159
```{warning}
158-
Be careful when doing this since it could cause tools such as Pipx and Pipenv
160+
Be careful when doing this since it could cause tools such as pipx and Pipenv
159161
to appear to hang. They show their own progress indicator while hiding output
160162
from the subprocess in which they run Pip. You won't know whether the keyring
161163
backend is waiting the user input or not in such situations.
162164
```
163165

164-
Pip is conservative and does not query keyring at all when `--no-input` is used
166+
pip is conservative and does not query keyring at all when `--no-input` is used
165167
because the keyring might require user interaction such as prompting the user
166168
on the console. You can force keyring usage by passing `--force-keyring` or one
167169
of the following:
@@ -174,7 +176,7 @@ $ export PIP_FORCE_KEYRING=1
174176
```
175177

176178
```{warning}
177-
Be careful when doing this since it could cause tools such as Pipx and Pipenv
179+
Be careful when doing this since it could cause tools such as pipx and Pipenv
178180
to appear to hang. They show their own progress indicator while hiding output
179181
from the subprocess in which they run Pip. You won't know whether the keyring
180182
backend is waiting the user input or not in such situations.

0 commit comments

Comments
 (0)