Skip to content

Commit 86c0641

Browse files
authored
Add .pypirc specification (#734)
* Add initial draft of .pypirc specification * Incorporate review feedback * Link to spec from other docs * Add subsections
1 parent c7c7a40 commit 86c0641

6 files changed

Lines changed: 157 additions & 22 deletions

File tree

source/guides/distributing-packages-using-setuptools.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ are creating a new project.
907907
won't see that token again.**
908908

909909
.. Note:: To avoid having to copy and paste the token every time you
910-
upload, you can create a ``$HOME/.pypirc`` file:
910+
upload, you can create a :file:`$HOME/.pypirc` file:
911911

912912
.. code-block:: text
913913
@@ -917,6 +917,8 @@ won't see that token again.**
917917
918918
**Be aware that this stores your token in plaintext.**
919919

920+
For more details, see the :ref:`specification <pypirc>` for :file:`.pypirc`.
921+
920922
.. _register-your-project:
921923
.. _API token: https://pypi.org/help/#apitoken
922924

source/guides/migrating-to-pypi-org.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The default upload settings switched to ``pypi.org`` in the following versions:
3131
In addition to ensuring you're on a new enough version of the tool for the
3232
tool's default to have switched, you must also make sure that you have not
3333
configured the tool to override its default upload URL. Typically this is
34-
configured in a file located at ``$HOME/.pypirc``. If you see a file like:
34+
configured in a file located at :file:`$HOME/.pypirc`. If you see a file like:
3535

3636
.. code::
3737
@@ -40,17 +40,17 @@ configured in a file located at ``$HOME/.pypirc``. If you see a file like:
4040
pypi
4141
4242
[pypi]
43-
repository:https://pypi.python.org/pypi
44-
username:yourusername
45-
password:yourpassword
43+
repository = https://pypi.python.org/pypi
44+
username = <your PyPI username>
45+
password = <your PyPI username>
4646
4747
4848
Then simply delete the line starting with ``repository`` and you will use
4949
your upload tool's default URL.
5050

5151
If for some reason you're unable to upgrade the version of your tool
5252
to a version that defaults to using PyPI.org, then you may edit
53-
``$HOME/.pypirc`` and include the ``repository:`` line, but use the
53+
:file:`$HOME/.pypirc` and include the ``repository:`` line, but use the
5454
value ``https://upload.pypi.org/legacy/`` instead:
5555

5656
.. code::
@@ -60,13 +60,14 @@ value ``https://upload.pypi.org/legacy/`` instead:
6060
pypi
6161
6262
[pypi]
63-
repository: https://upload.pypi.org/legacy/
64-
username: your username
65-
password: your password
63+
repository = https://upload.pypi.org/legacy/
64+
username = <your PyPI username>
65+
password = <your PyPI password>
6666
6767
(``legacy`` in this URL refers to the fact that this is the new server
6868
implementation's emulation of the legacy server implementation's upload API.)
6969

70+
For more details, see the :ref:`specification <pypirc>` for :file:`.pypirc`.
7071

7172
Registering package names & metadata
7273
------------------------------------
@@ -89,7 +90,7 @@ Using TestPyPI
8990

9091
Legacy TestPyPI (testpypi.python.org) is no longer available; use
9192
`test.pypi.org <https://test.pypi.org>`_ instead. If you use TestPyPI,
92-
you must update your ``$HOME/.pypirc`` to handle TestPyPI's new
93+
you must update your :file:`$HOME/.pypirc` to handle TestPyPI's new
9394
location, by replacing ``https://testpypi.python.org/pypi`` with
9495
``https://test.pypi.org/legacy/``, for example:
9596

@@ -101,9 +102,11 @@ location, by replacing ``https://testpypi.python.org/pypi`` with
101102
testpypi
102103
103104
[testpypi]
104-
repository: https://test.pypi.org/legacy/
105-
username: your testpypi username
106-
password: your testpypi password
105+
repository = https://test.pypi.org/legacy/
106+
username = <your TestPyPI username>
107+
password = <your TestPyPI password>
108+
109+
For more details, see the :ref:`specification <pypirc>` for :file:`.pypirc`.
107110

108111

109112
Registering new user accounts

source/guides/using-testpypi.rst

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,15 @@ you're testing has dependencies:
5353
5454
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple your-package
5555
56-
Setting up TestPyPI in pypirc
57-
-----------------------------
56+
Setting up TestPyPI in :file:`.pypirc`
57+
--------------------------------------
5858

5959
If you want to avoid entering your username, you can configure TestPyPI in
60-
your ``$HOME/.pypirc``.
61-
62-
Create or modify ``$HOME/.pypirc`` with the following:
60+
your :file:`$HOME/.pypirc`:
6361

6462
.. code::
6563
6664
[testpypi]
67-
username: your testpypi username
68-
65+
username = <your TestPyPI username>
6966
70-
.. Warning:: Do not store passwords in the pypirc file.
71-
Storing passwords in plain text is never a good idea.
67+
For more details, see the :ref:`specification <pypirc>` for :file:`.pypirc`.

source/key_projects.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ classifiers.
229229
twine
230230
=====
231231

232+
`Docs <https://twine.readthedocs.io/en/latest/>`__ |
232233
`Mailing list <http://mail.python.org/mailman/listinfo/distutils-sig>`__ [2]_ |
233234
`Issues <https://github.com/pypa/twine/issues>`__ |
234235
`GitHub <https://github.com/pypa/twine>`__ |

source/specifications/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ Package Index Interfaces
3131
.. toctree::
3232
:maxdepth: 1
3333

34+
pypirc
3435
simple-repository-api

source/specifications/pypirc.rst

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
.. _pypirc:
3+
4+
========================
5+
The :file:`.pypirc` file
6+
========================
7+
8+
A :file:`.pypirc` file allows you to define the configuration for :term:`package
9+
indexes <Package Index>` (referred to here as "repositories"), so that you don't
10+
have to enter the URL, username, or password whenever you upload a package with
11+
:ref:`twine` or :ref:`flit`.
12+
13+
The format (originally defined by the :ref:`distutils` package) is:
14+
15+
.. code-block:: ini
16+
17+
[distutils]
18+
index-servers =
19+
first-repository
20+
second-repository
21+
22+
[first-repository]
23+
repository = <first-repository URL>
24+
username = <first-repository username>
25+
password = <first-repository password>
26+
27+
[second-repository]
28+
repository = <second-repository URL>
29+
username = <second-repository username>
30+
password = <second-repository password>
31+
32+
The ``distutils`` section defines an ``index-servers`` field that lists the
33+
name of all sections describing a repository.
34+
35+
Each section describing a repository defines three fields:
36+
37+
- ``repository``: The URL of the repository.
38+
- ``username``: The registered username on the repository.
39+
- ``password``: The password that will used to authenticate the username.
40+
41+
.. warning::
42+
43+
Be aware that this stores your password in plain text. For better security,
44+
consider an alternative like `keyring`_, setting environment variables, or
45+
providing the password on the command line.
46+
47+
.. _keyring: https://pypi.org/project/keyring/
48+
49+
Common configurations
50+
=====================
51+
52+
.. note::
53+
54+
These examples apply to :ref:`twine`, and projects like :ref:`hatch` that
55+
use it under the hood. Other projects (e.g. :ref:`flit`) also use
56+
:file:`.pypirc`, but with different defaults. Please refer to each project's
57+
documentation for more details and usage instructions.
58+
59+
Twine's default configuration mimics a :file:`.pypirc` with repository sections
60+
for PyPI and TestPyPI:
61+
62+
.. code-block:: ini
63+
64+
[distutils]
65+
index-servers =
66+
pypi
67+
testpypi
68+
69+
[pypi]
70+
repository = https://upload.pypi.org/legacy/
71+
72+
[testpypi]
73+
repository = https://test.pypi.org/legacy/
74+
75+
Twine will add additional configuration from :file:`$HOME/.pypirc`, the command
76+
line, and environment variables to this default configuration.
77+
78+
Using a PyPI token
79+
------------------
80+
81+
To set your `API token`_ for PyPI, you can create a :file:`$HOME/.pypirc`
82+
similar to:
83+
84+
.. code-block:: ini
85+
86+
[pypi]
87+
username = __token__
88+
password = <PyPI token>
89+
90+
For :ref:`TestPyPI <using-test-pypi>`, add a ``[testpypi]`` section, using the
91+
API token from your TestPyPI account.
92+
93+
.. _API token: https://pypi.org/help/#apitoken
94+
95+
Using another package index
96+
---------------------------
97+
98+
To configure an additional repository, you'll need to redefine the
99+
``index-servers`` field to include the repository name. Here is a complete
100+
example of a :file:`$HOME/.pypirc` for PyPI, TestPyPI, and a private repository:
101+
102+
.. code-block:: ini
103+
104+
[distutils]
105+
index-servers =
106+
pypi
107+
testpypi
108+
private-repository
109+
110+
[pypi]
111+
username = __token__
112+
password = <PyPI token>
113+
114+
[testpypi]
115+
username = __token__
116+
password = <TestPyPI token>
117+
118+
[private-repository]
119+
repository = <private-repository URL>
120+
username = <private-repository username>
121+
password = <private-repository password>
122+
123+
.. warning::
124+
125+
Instead of using the ``password`` field, consider saving your API tokens
126+
and passwords securely using `keyring`_ (which is installed by Twine):
127+
128+
.. code-block:: bash
129+
130+
keyring set https://upload.pypi.org/legacy/ __token__
131+
keyring set https://test.pypi.org/legacy/ __token__
132+
keyring set <private-repository URL> <private-repository username>

0 commit comments

Comments
 (0)