|
| 1 | +.. index:: |
| 2 | + single: Python Package Index (PyPI) |
| 3 | + single: PyPI; (see Python Package Index (PyPI)) |
| 4 | + |
1 | 5 | .. _package-index: |
2 | 6 |
|
3 | | -********************************** |
4 | | -Registering with the Package Index |
5 | | -********************************** |
| 7 | +******************************* |
| 8 | +The Python Package Index (PyPI) |
| 9 | +******************************* |
| 10 | + |
| 11 | +The `Python Package Index (PyPI)`_ holds :ref:`meta-data <meta-data>` |
| 12 | +describing distributions packaged with distutils, as well as package data like |
| 13 | +distribution files if the package author wishes. |
| 14 | + |
| 15 | +Distutils exposes two commands for submitting package data to PyPI: the |
| 16 | +:ref:`register <package-register>` command for submitting meta-data to PyPI |
| 17 | +and the :ref:`upload <package-upload>` command for submitting distribution |
| 18 | +files. Both commands read configuration data from a special file called the |
| 19 | +:ref:`.pypirc file <pypirc>`. PyPI :ref:`displays a home page |
| 20 | +<package-display>` for each package created from the ``long_description`` |
| 21 | +submitted by the :command:`register` command. |
| 22 | + |
| 23 | + |
| 24 | +.. _package-register: |
6 | 25 |
|
7 | | -The Python Package Index (PyPI) holds meta-data describing distributions |
8 | | -packaged with distutils. The distutils command :command:`register` is used to |
9 | | -submit your distribution's meta-data to the index. It is invoked as follows:: |
| 26 | +Registering Packages |
| 27 | +==================== |
| 28 | + |
| 29 | +The distutils command :command:`register` is used to submit your distribution's |
| 30 | +meta-data to the index. It is invoked as follows:: |
10 | 31 |
|
11 | 32 | python setup.py register |
12 | 33 |
|
@@ -48,6 +69,52 @@ interface lets one change this default behavior and manually select which |
48 | 69 | versions to display and hide. |
49 | 70 |
|
50 | 71 |
|
| 72 | +.. _package-upload: |
| 73 | + |
| 74 | +Uploading Packages |
| 75 | +================== |
| 76 | + |
| 77 | +The distutils command :command:`upload` pushes the distribution files to PyPI. |
| 78 | + |
| 79 | +The command is invoked immediately after building one or more distribution |
| 80 | +files. For example, the command :: |
| 81 | + |
| 82 | + python setup.py sdist bdist_wininst upload |
| 83 | + |
| 84 | +will cause the source distribution and the Windows installer to be uploaded to |
| 85 | +PyPI. Note that these will be uploaded even if they are built using an earlier |
| 86 | +invocation of :file:`setup.py`, but that only distributions named on the command |
| 87 | +line for the invocation including the :command:`upload` command are uploaded. |
| 88 | + |
| 89 | +The :command:`upload` command uses the username, password, and repository URL |
| 90 | +from the :file:`$HOME/.pypirc` file (see section :ref:`pypirc` for more on this |
| 91 | +file). If a :command:`register` command was previously called in the same command, |
| 92 | +and if the password was entered in the prompt, :command:`upload` will reuse the |
| 93 | +entered password. This is useful if you do not want to store a clear text |
| 94 | +password in the :file:`$HOME/.pypirc` file. |
| 95 | + |
| 96 | +You can specify another PyPI server with the ``--repository=url`` option:: |
| 97 | + |
| 98 | + python setup.py sdist bdist_wininst upload -r http://example.com/pypi |
| 99 | + |
| 100 | +See section :ref:`pypirc` for more on defining several servers. |
| 101 | + |
| 102 | +You can use the ``--sign`` option to tell :command:`upload` to sign each |
| 103 | +uploaded file using GPG (GNU Privacy Guard). The :program:`gpg` program must |
| 104 | +be available for execution on the system :envvar:`PATH`. You can also specify |
| 105 | +which key to use for signing using the ``--identity=name`` option. |
| 106 | + |
| 107 | +Other :command:`upload` options include ``--repository=url`` or |
| 108 | +``--repository=section`` where *url* is the url of the server and |
| 109 | +*section* the name of the section in :file:`$HOME/.pypirc`, and |
| 110 | +``--show-response`` (which displays the full response text from the PyPI |
| 111 | +server for help in debugging upload problems). |
| 112 | + |
| 113 | + |
| 114 | +.. index:: |
| 115 | + single: .pypirc file |
| 116 | + single: Python Package Index (PyPI); .pypirc file |
| 117 | + |
51 | 118 | .. _pypirc: |
52 | 119 |
|
53 | 120 | The .pypirc file |
@@ -102,3 +169,45 @@ For convenience, the name of the section that describes the repository |
102 | 169 | may also be used:: |
103 | 170 |
|
104 | 171 | python setup.py register -r other |
| 172 | + |
| 173 | + |
| 174 | +.. _package-display: |
| 175 | + |
| 176 | +PyPI package display |
| 177 | +==================== |
| 178 | + |
| 179 | +The ``long_description`` field plays a special role at PyPI. It is used by |
| 180 | +the server to display a home page for the registered package. |
| 181 | + |
| 182 | +If you use the `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ |
| 183 | +syntax for this field, PyPI will parse it and display an HTML output for |
| 184 | +the package home page. |
| 185 | + |
| 186 | +The ``long_description`` field can be attached to a text file located |
| 187 | +in the package:: |
| 188 | + |
| 189 | + from distutils.core import setup |
| 190 | + |
| 191 | + with open('README.txt') as file: |
| 192 | + long_description = file.read() |
| 193 | + |
| 194 | + setup(name='Distutils', |
| 195 | + long_description=long_description) |
| 196 | + |
| 197 | +In that case, :file:`README.txt` is a regular reStructuredText text file located |
| 198 | +in the root of the package besides :file:`setup.py`. |
| 199 | + |
| 200 | +To prevent registering broken reStructuredText content, you can use the |
| 201 | +:program:`rst2html` program that is provided by the :mod:`docutils` package and |
| 202 | +check the ``long_description`` from the command line:: |
| 203 | + |
| 204 | + $ python setup.py --long-description | rst2html.py > output.html |
| 205 | + |
| 206 | +:mod:`docutils` will display a warning if there's something wrong with your |
| 207 | +syntax. Because PyPI applies additional checks (e.g. by passing ``--no-raw`` |
| 208 | +to ``rst2html.py`` in the command above), being able to run the command above |
| 209 | +without warnings does not guarantee that PyPI will convert the content |
| 210 | +successfully. |
| 211 | + |
| 212 | + |
| 213 | +.. _Python Package Index (PyPI): http://pypi.python.org/ |
0 commit comments