Skip to content

Commit 6454a06

Browse files
authored
Merge pull request #1450 from jeanas/distributing-guide
Start updating distributing-packages-using-setuptools guide
2 parents 9f7c6ae + ad43be9 commit 6454a06

File tree

3 files changed

+78
-280
lines changed

3 files changed

+78
-280
lines changed

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

Lines changed: 8 additions & 268 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
Packaging and distributing projects
55
===================================
66

7+
:Page Status: Outdated
8+
:Last Reviewed: 2023-12-14
9+
710
This section covers some additional details on configuring, packaging and
811
distributing Python projects with ``setuptools`` that aren't covered by the
912
introductory tutorial in :doc:`/tutorials/packaging-projects`. It still assumes
@@ -153,206 +156,21 @@ As mentioned above, the primary feature of :file:`setup.py` is that it contains
153156
a global ``setup()`` function. The keyword arguments to this function are how
154157
specific details of your project are defined.
155158

156-
The most relevant arguments are explained below. Most of the snippets given are
159+
Some are temporarily explained below until their information is moved elsewhere.
160+
The full list can be found :doc:`in the setuptools documentation
161+
<setuptools:references/keywords>`.
162+
163+
Most of the snippets given are
157164
taken from the `setup.py
158165
<https://github.com/pypa/sampleproject/blob/db5806e0a3204034c51b1c00dde7d5eb3fa2532e/setup.py>`_ contained in the
159166
`PyPA sample project <https://github.com/pypa/sampleproject>`_.
160167

161168

162-
.. _`setup() name`:
163-
164-
``name``
165-
~~~~~~~~
166-
167-
::
168-
169-
name='sample',
170-
171-
This is the name of your project, determining how your project is listed on
172-
:term:`PyPI <Python Package Index (PyPI)>`. Per :pep:`508`, valid project
173-
names must:
174-
175-
- Consist only of ASCII letters, digits, underscores (``_``), hyphens (``-``),
176-
and/or periods (``.``), and
177-
- Start & end with an ASCII letter or digit.
178-
179-
Comparison of project names is case insensitive and treats arbitrarily-long
180-
runs of underscores, hyphens, and/or periods as equal. For example, if you
181-
register a project named ``cool-stuff``, users will be able to download it or
182-
declare a dependency on it using any of the following spellings::
183-
184-
Cool-Stuff
185-
cool.stuff
186-
COOL_STUFF
187-
CoOl__-.-__sTuFF
188-
189-
190-
``version``
191-
~~~~~~~~~~~
192-
193-
::
194-
195-
version='1.2.0',
196-
197-
This is the current version of your project, allowing your users to determine whether or not
198-
they have the latest version, and to indicate which specific versions they've tested their own
199-
software against.
200-
201-
Versions are displayed on :term:`PyPI <Python Package Index (PyPI)>` for each release if you
202-
publish your project.
203169

204170
See :ref:`Choosing a versioning scheme` for more information on ways to use versions to convey
205171
compatibility information to your users.
206172

207-
If the project code itself needs run-time access to the version, the simplest
208-
way is to keep the version in both :file:`setup.py` and your code. If you'd
209-
rather not duplicate the value, there are a few ways to manage this. See the
210-
":ref:`Single sourcing the version`" Advanced Topics section.
211-
212-
.. _`description`:
213-
214-
``description``
215-
~~~~~~~~~~~~~~~
216-
217-
::
218-
219-
description='A sample Python project',
220-
long_description=long_description,
221-
long_description_content_type='text/x-rst',
222-
223-
Give a short and long description for your project.
224-
225-
These values will be displayed on :term:`PyPI <Python Package Index (PyPI)>`
226-
if you publish your project. On ``pypi.org``, the user interface displays
227-
``description`` in the grey banner and ``long_description`` in the section
228-
named "Project Description".
229-
230-
``description`` is also displayed in lists of projects. For example, it's
231-
visible in the search results pages such as https://pypi.org/search/?q=jupyter,
232-
the front-page lists of trending projects and new releases, and the list of
233-
projects you maintain within your account profile (such as
234-
https://pypi.org/user/jaraco/).
235-
236-
A :ref:`content type <core-metadata-description-content-type>`
237-
can be specified with the ``long_description_content_type`` argument, which can
238-
be one of ``text/plain``, ``text/x-rst``, or ``text/markdown``, corresponding
239-
to no formatting, `reStructuredText (reST)
240-
<https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#reference-names>`_,
241-
and the GitHub-flavored Markdown dialect of `Markdown
242-
<https://daringfireball.net/projects/markdown/>`_ respectively.
243-
244-
``url``
245-
~~~~~~~
246-
247-
::
248-
249-
url='https://github.com/pypa/sampleproject',
250-
251-
252-
Give a homepage URL for your project.
253-
254-
255-
``author``
256-
~~~~~~~~~~
257-
258-
::
259-
260-
author='A. Random Developer',
261-
author_email='[email protected]',
262-
263-
Provide details about the author.
264-
265-
266-
``license``
267-
~~~~~~~~~~~
268-
269-
::
270-
271-
license='MIT',
272-
273-
The ``license`` argument doesn't have to indicate the license under
274-
which your package is being released, although you may optionally do
275-
so if you want. If you're using a standard, well-known license, then
276-
your main indication can and should be via the ``classifiers``
277-
argument. Classifiers exist for all major open-source licenses.
278-
279-
The ``license`` argument is more typically used to indicate differences
280-
from well-known licenses, or to include your own, unique license. As a
281-
general rule, it's a good idea to use a standard, well-known license,
282-
both to avoid confusion and because some organizations avoid software
283-
whose license is unapproved.
284-
285-
286-
``classifiers``
287-
~~~~~~~~~~~~~~~
288-
289-
::
290-
291-
classifiers=[
292-
# How mature is this project? Common values are
293-
# 3 - Alpha
294-
# 4 - Beta
295-
# 5 - Production/Stable
296-
'Development Status :: 3 - Alpha',
297-
298-
# Indicate who your project is intended for
299-
'Intended Audience :: Developers',
300-
'Topic :: Software Development :: Build Tools',
301-
302-
# Pick your license as you wish (should match "license" above)
303-
'License :: OSI Approved :: MIT License',
304-
305-
# Specify the Python versions you support here. In particular, ensure
306-
# that you indicate whether you support Python 2, Python 3 or both.
307-
'Programming Language :: Python :: 2',
308-
'Programming Language :: Python :: 2.7',
309-
'Programming Language :: Python :: 3',
310-
'Programming Language :: Python :: 3.6',
311-
'Programming Language :: Python :: 3.7',
312-
'Programming Language :: Python :: 3.8',
313-
'Programming Language :: Python :: 3.9',
314-
],
315-
316-
Provide a list of classifiers that categorize your project. For a full listing,
317-
see https://pypi.org/classifiers/.
318-
319-
Although the list of classifiers is often used to declare what Python versions
320-
a project supports, this information is only used for searching & browsing
321-
projects on PyPI, not for installing projects. To actually restrict what
322-
Python versions a project can be installed on, use the :ref:`python_requires`
323-
argument.
324-
325-
To prevent a package from being uploaded to PyPI, use the special
326-
``'Private :: Do Not Upload'`` classifier. PyPI will always reject packages with
327-
classifiers beginning with ``"Private ::'``.
328-
329-
330-
``keywords``
331-
~~~~~~~~~~~~
332-
333-
::
334173

335-
keywords='sample setuptools development',
336-
337-
List keywords that describe your project.
338-
339-
340-
``project_urls``
341-
~~~~~~~~~~~~~~~~
342-
343-
::
344-
345-
project_urls={
346-
'Documentation': 'https://packaging.python.org/tutorials/distributing-packages/',
347-
'Funding': 'https://donate.pypi.org',
348-
'Say Thanks!': 'http://saythanks.io/to/example',
349-
'Source': 'https://github.com/pypa/sampleproject/',
350-
'Tracker': 'https://github.com/pypa/sampleproject/issues',
351-
},
352-
353-
List additional relevant URLs about your project. This is the place to link to
354-
bug trackers, source repositories, or where to support package development.
355-
The string of the key is the exact text that will be displayed on PyPI.
356174

357175

358176
``packages``
@@ -396,38 +214,6 @@ specification that is used to install its dependencies.
396214
For more on using "install_requires" see :ref:`install_requires vs Requirements files`.
397215

398216

399-
.. _python_requires:
400-
401-
``python_requires``
402-
~~~~~~~~~~~~~~~~~~~
403-
404-
If your project only runs on certain Python versions, setting the
405-
``python_requires`` argument to the appropriate :pep:`440` version specifier
406-
string will prevent :ref:`pip` from installing the project on other Python
407-
versions. For example, if your package is for Python 3+ only, write::
408-
409-
python_requires='>=3',
410-
411-
If your package is for Python 2.6, 2.7, and all versions of Python 3 starting
412-
with 3.3, write::
413-
414-
python_requires='>=2.6, !=3.0.*, !=3.1.*, !=3.2.*',
415-
416-
And so on.
417-
418-
.. note::
419-
420-
Support for this feature is relatively recent. Your project's source
421-
distributions and wheels (see :ref:`Packaging Your Project`) must be built
422-
using at least version 24.2.0 of :ref:`setuptools` in order for the
423-
``python_requires`` argument to be recognized and the appropriate metadata
424-
generated.
425-
426-
In addition, only versions 9.0.0 and higher of :ref:`pip` recognize the
427-
``python_requires`` metadata. Users with earlier versions of pip will be
428-
able to download & install projects on any Python version regardless of the
429-
projects' ``python_requires`` values.
430-
431217

432218
.. _`Package Data`:
433219

@@ -500,47 +286,8 @@ keyword for pointing to pre-made scripts to install, the recommended approach to
500286
achieve cross-platform compatibility is to use :ref:`console_scripts` entry
501287
points (see below).
502288

503-
``entry_points``
504-
~~~~~~~~~~~~~~~~
505-
506-
::
507-
508-
entry_points={
509-
...
510-
},
511289

512290

513-
Use this keyword to specify any plugins that your project provides for any named
514-
entry points that may be defined by your project or others that you depend on.
515-
516-
For more information, see the section on
517-
:ref:`Advertising Behavior <setuptools:dynamic discovery of services and plugins>`
518-
from the :ref:`setuptools` docs.
519-
520-
The most commonly used entry point is "console_scripts" (see below).
521-
522-
.. _`console_scripts`:
523-
524-
``console_scripts``
525-
*******************
526-
527-
::
528-
529-
entry_points={
530-
'console_scripts': [
531-
'sample=sample:main',
532-
],
533-
},
534-
535-
Use ``console_script``
536-
:ref:`entry points <setuptools:dynamic discovery of services and plugins>`
537-
to register your script interfaces. You can then let the toolchain handle the
538-
work of turning these interfaces into actual scripts [2]_. The scripts will be
539-
generated during the install of your :term:`distribution <Distribution
540-
Package>`.
541-
542-
For more information, see :doc:`Entry Points <setuptools:userguide/entry_point>`
543-
from the :doc:`setuptools docs <setuptools:index>`.
544291

545292
.. _`Choosing a versioning scheme`:
546293

@@ -956,10 +703,3 @@ your project to appear on the site.
956703
access. :ref:`pip` is currently considering changing this by `making user
957704
installs the default behavior
958705
<https://github.com/pypa/pip/issues/1668>`_.
959-
960-
961-
.. [2] Specifically, the "console_script" approach generates ``.exe`` files on
962-
Windows, which are necessary because the OS special-cases ``.exe`` files.
963-
Script-execution features like ``PATHEXT`` and the :pep:`Python Launcher for
964-
Windows <397>` allow scripts to
965-
be used in many cases, but not all.

source/guides/single-sourcing-package-version.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Single-sourcing the package version
55
===================================
66

7+
.. todo:: Update this page for build backends other than setuptools.
78

89
There are many techniques to maintain a single source of truth for the version
910
number of your project:

0 commit comments

Comments
 (0)