source: python/trunk/Doc/distutils/packageindex.rst

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 7.4 KB
RevLine 
[391]1.. index::
2 single: Python Package Index (PyPI)
3 single: PyPI; (see Python Package Index (PyPI))
4
[2]5.. _package-index:
6
[391]7*******************************
8The Python Package Index (PyPI)
9*******************************
[2]10
[391]11The `Python Package Index (PyPI)`_ holds :ref:`meta-data <meta-data>`
12describing distributions packaged with distutils, as well as package data like
13distribution files if the package author wishes.
[2]14
[391]15Distutils exposes two commands for submitting package data to PyPI: the
16:ref:`register <package-register>` command for submitting meta-data to PyPI
17and the :ref:`upload <package-upload>` command for submitting distribution
18files. 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``
21submitted by the :command:`register` command.
[2]22
[391]23
24.. _package-register:
25
26Registering Packages
27====================
28
29The distutils command :command:`register` is used to submit your distribution's
30meta-data to the index. It is invoked as follows::
31
32 python setup.py register
33
[2]34Distutils will respond with the following prompt::
35
[391]36 running register
37 We need to know who you are, so please choose either:
38 1. use your existing login,
39 2. register as a new user,
40 3. have the server generate a new password for you (and email it to you), or
41 4. quit
42 Your selection [default 1]:
[2]43
44Note: if your username and password are saved locally, you will not see this
45menu.
46
47If you have not registered with PyPI, then you will need to do so now. You
48should choose option 2, and enter your details as required. Soon after
49submitting your details, you will receive an email which will be used to confirm
50your registration.
51
52Once you are registered, you may choose option 1 from the menu. You will be
53prompted for your PyPI username and password, and :command:`register` will then
54submit your meta-data to the index.
55
56You may submit any number of versions of your distribution to the index. If you
57alter the meta-data for a particular version, you may submit it again and the
58index will be updated.
59
60PyPI holds a record for each (name, version) combination submitted. The first
61user to submit information for a given name is designated the Owner of that
62name. They may submit changes through the :command:`register` command or through
63the web interface. They may also designate other users as Owners or Maintainers.
64Maintainers may edit the package information, but not designate other Owners or
65Maintainers.
66
[391]67By default PyPI displays only the newest version of a given package. The web
68interface lets one change this default behavior and manually select which
69versions to display and hide.
[2]70
71
[391]72.. _package-upload:
73
74Uploading Packages
75==================
76
77.. versionadded:: 2.5
78
79The distutils command :command:`upload` pushes the distribution files to PyPI.
80
81The command is invoked immediately after building one or more distribution
82files. For example, the command ::
83
84 python setup.py sdist bdist_wininst upload
85
86will cause the source distribution and the Windows installer to be uploaded to
87PyPI. Note that these will be uploaded even if they are built using an earlier
88invocation of :file:`setup.py`, but that only distributions named on the command
89line for the invocation including the :command:`upload` command are uploaded.
90
91The :command:`upload` command uses the username, password, and repository URL
92from the :file:`$HOME/.pypirc` file (see section :ref:`pypirc` for more on this
93file). If a :command:`register` command was previously called in the same command,
94and if the password was entered in the prompt, :command:`upload` will reuse the
95entered password. This is useful if you do not want to store a clear text
96password in the :file:`$HOME/.pypirc` file.
97
98You can specify another PyPI server with the ``--repository=url`` option::
99
100 python setup.py sdist bdist_wininst upload -r http://example.com/pypi
101
102See section :ref:`pypirc` for more on defining several servers.
103
104You can use the ``--sign`` option to tell :command:`upload` to sign each
105uploaded file using GPG (GNU Privacy Guard). The :program:`gpg` program must
106be available for execution on the system :envvar:`PATH`. You can also specify
107which key to use for signing using the ``--identity=name`` option.
108
109Other :command:`upload` options include ``--repository=url`` or
110``--repository=section`` where *url* is the url of the server and
111*section* the name of the section in :file:`$HOME/.pypirc`, and
112``--show-response`` (which displays the full response text from the PyPI
113server for help in debugging upload problems).
114
115
116.. index::
117 single: .pypirc file
118 single: Python Package Index (PyPI); .pypirc file
119
[2]120.. _pypirc:
121
122The .pypirc file
123================
124
125The format of the :file:`.pypirc` file is as follows::
126
[391]127 [distutils]
128 index-servers =
129 pypi
[2]130
[391]131 [pypi]
132 repository: <repository-url>
133 username: <username>
134 password: <password>
[2]135
[391]136The *distutils* section defines a *index-servers* variable that lists the
137name of all sections describing a repository.
[2]138
[391]139Each section describing a repository defines three variables:
[2]140
[391]141- *repository*, that defines the url of the PyPI server. Defaults to
142 ``http://www.python.org/pypi``.
143- *username*, which is the registered username on the PyPI server.
144- *password*, that will be used to authenticate. If omitted the user
145 will be prompt to type it when needed.
[2]146
[391]147If you want to define another server a new section can be created and
148listed in the *index-servers* variable::
[2]149
[391]150 [distutils]
151 index-servers =
152 pypi
153 other
[2]154
[391]155 [pypi]
156 repository: <repository-url>
157 username: <username>
158 password: <password>
[2]159
[391]160 [other]
161 repository: http://example.com/pypi
162 username: <username>
163 password: <password>
[2]164
[391]165:command:`register` can then be called with the -r option to point the
166repository to work with::
[2]167
[391]168 python setup.py register -r http://example.com/pypi
[2]169
[391]170For convenience, the name of the section that describes the repository
171may also be used::
172
173 python setup.py register -r other
174
175
176.. _package-display:
177
178PyPI package display
179====================
180
181The ``long_description`` field plays a special role at PyPI. It is used by
182the server to display a home page for the registered package.
183
184If you use the `reStructuredText <http://docutils.sourceforge.net/rst.html>`_
185syntax for this field, PyPI will parse it and display an HTML output for
186the package home page.
187
188The ``long_description`` field can be attached to a text file located
189in the package::
190
191 from distutils.core import setup
192
193 with open('README.txt') as file:
194 long_description = file.read()
195
196 setup(name='Distutils',
197 long_description=long_description)
198
199In that case, :file:`README.txt` is a regular reStructuredText text file located
200in the root of the package besides :file:`setup.py`.
201
202To prevent registering broken reStructuredText content, you can use the
203:program:`rst2html` program that is provided by the :mod:`docutils` package and
204check the ``long_description`` from the command line::
205
206 $ python setup.py --long-description | rst2html.py > output.html
207
208:mod:`docutils` will display a warning if there's something wrong with your
209syntax. Because PyPI applies additional checks (e.g. by passing ``--no-raw``
210to ``rst2html.py`` in the command above), being able to run the command above
211without warnings does not guarantee that PyPI will convert the content
212successfully.
213
214
215.. _Python Package Index (PyPI): http://pypi.python.org/
Note: See TracBrowser for help on using the repository browser.