2014-03-16 01:13:56 -03:00
|
|
|
.. _distributing-index:
|
|
|
|
|
|
|
|
###############################
|
|
|
|
Distributing Python Modules
|
|
|
|
###############################
|
|
|
|
|
|
|
|
:Email: distutils-sig@python.org
|
|
|
|
|
|
|
|
|
|
|
|
As a popular open source development project, Python has an active
|
|
|
|
supporting community of contributors and users that also make their software
|
|
|
|
available for other Python developers to use under open source license terms.
|
|
|
|
|
|
|
|
This allows Python users to share and collaborate effectively, benefiting
|
|
|
|
from the solutions others have already created to common (and sometimes
|
|
|
|
even rare!) problems, as well as potentially contributing their own
|
|
|
|
solutions to the common pool.
|
|
|
|
|
|
|
|
This guide covers the distribution part of the process. For a guide to
|
|
|
|
installing other Python projects, refer to the
|
|
|
|
:ref:`installation guide <installing-index>`.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
For corporate and other institutional users, be aware that many
|
|
|
|
organisations have their own policies around using and contributing to
|
|
|
|
open source software. Please take such policies into account when making
|
|
|
|
use of the distribution and installation tools provided with Python.
|
|
|
|
|
|
|
|
|
|
|
|
Key terms
|
|
|
|
=========
|
|
|
|
|
2014-10-04 08:11:25 -03:00
|
|
|
* the `Python Packaging Index <https://pypi.python.org/pypi>`__ is a public
|
2014-03-16 01:13:56 -03:00
|
|
|
repository of open source licensed packages made available for use by
|
|
|
|
other Python users
|
|
|
|
* the `Python Packaging Authority
|
2016-02-26 14:37:12 -04:00
|
|
|
<https://www.pypa.io/>`__ are the group of
|
2014-03-16 01:13:56 -03:00
|
|
|
developers and documentation authors responsible for the maintenance and
|
|
|
|
evolution of the standard packaging tools and the associated metadata and
|
|
|
|
file format standards. They maintain a variety of tools, documentation
|
|
|
|
and issue trackers on both `GitHub <https://github.com/pypa>`__ and
|
|
|
|
`BitBucket <https://bitbucket.org/pypa/>`__.
|
2014-10-25 11:00:04 -03:00
|
|
|
* :mod:`distutils` is the original build and distribution system first added
|
|
|
|
to the Python standard library in 1998. While direct use of :mod:`distutils`
|
|
|
|
is being phased out, it still laid the foundation for the current packaging
|
2014-03-16 01:13:56 -03:00
|
|
|
and distribution infrastructure, and it not only remains part of the
|
|
|
|
standard library, but its name lives on in other ways (such as the name
|
|
|
|
of the mailing list used to coordinate Python packaging standards
|
|
|
|
development).
|
2014-10-25 11:00:04 -03:00
|
|
|
* `setuptools`_ is a (largely) drop-in replacement for :mod:`distutils` first
|
2014-06-05 15:41:06 -03:00
|
|
|
published in 2004. Its most notable addition over the unmodified
|
2014-10-25 11:00:04 -03:00
|
|
|
:mod:`distutils` tools was the ability to declare dependencies on other
|
2014-05-25 11:50:11 -03:00
|
|
|
packages. It is currently recommended as a more regularly updated
|
2014-10-25 11:00:04 -03:00
|
|
|
alternative to :mod:`distutils` that offers consistent support for more
|
2014-05-25 11:50:11 -03:00
|
|
|
recent packaging standards across a wide range of Python versions.
|
2014-10-25 11:00:04 -03:00
|
|
|
* `wheel`_ (in this context) is a project that adds the ``bdist_wheel``
|
|
|
|
command to :mod:`distutils`/`setuptools`_. This produces a cross platform
|
2014-05-25 11:50:11 -03:00
|
|
|
binary packaging format (called "wheels" or "wheel files" and defined in
|
|
|
|
:pep:`427`) that allows Python libraries, even those including binary
|
|
|
|
extensions, to be installed on a system without needing to be built
|
|
|
|
locally.
|
2014-03-16 01:13:56 -03:00
|
|
|
|
2016-06-05 21:38:48 -03:00
|
|
|
.. _setuptools: https://setuptools.readthedocs.io/en/latest/
|
2016-02-26 14:37:12 -04:00
|
|
|
.. _wheel: https://wheel.readthedocs.org
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
Open source licensing and collaboration
|
|
|
|
=======================================
|
|
|
|
|
|
|
|
In most parts of the world, software is automatically covered by copyright.
|
|
|
|
This means that other developers require explicit permission to copy, use,
|
|
|
|
modify and redistribute the software.
|
|
|
|
|
|
|
|
Open source licensing is a way of explicitly granting such permission in a
|
|
|
|
relatively consistent way, allowing developers to share and collaborate
|
|
|
|
efficiently by making common solutions to various problems freely available.
|
|
|
|
This leaves many developers free to spend more time focusing on the problems
|
|
|
|
that are relatively unique to their specific situation.
|
|
|
|
|
|
|
|
The distribution tools provided with Python are designed to make it
|
|
|
|
reasonably straightforward for developers to make their own contributions
|
|
|
|
back to that common pool of software if they choose to do so.
|
|
|
|
|
|
|
|
The same distribution tools can also be used to distribute software within
|
|
|
|
an organisation, regardless of whether that software is published as open
|
|
|
|
source software or not.
|
|
|
|
|
|
|
|
|
|
|
|
Installing the tools
|
|
|
|
====================
|
|
|
|
|
|
|
|
The standard library does not include build tools that support modern
|
|
|
|
Python packaging standards, as the core development team has found that it
|
|
|
|
is important to have standard tools that work consistently, even on older
|
|
|
|
versions of Python.
|
|
|
|
|
|
|
|
The currently recommended build and distribution tools can be installed
|
2014-09-06 07:38:23 -03:00
|
|
|
by invoking the ``pip`` module at the command line::
|
2014-03-16 01:13:56 -03:00
|
|
|
|
2014-09-06 07:38:23 -03:00
|
|
|
python -m pip install setuptools wheel twine
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
For POSIX users (including Mac OS X and Linux users), these instructions
|
|
|
|
assume the use of a :term:`virtual environment`.
|
|
|
|
|
|
|
|
For Windows users, these instructions assume that the option to
|
|
|
|
adjust the system PATH environment variable was selected when installing
|
|
|
|
Python.
|
2014-03-16 01:13:56 -03:00
|
|
|
|
2014-05-25 11:50:11 -03:00
|
|
|
The Python Packaging User Guide includes more details on the `currently
|
|
|
|
recommended tools`_.
|
|
|
|
|
2016-02-26 14:37:12 -04:00
|
|
|
.. _currently recommended tools: https://packaging.python.org/en/latest/current/#packaging-tool-recommendations
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
Reading the guide
|
|
|
|
=================
|
|
|
|
|
|
|
|
The Python Packaging User Guide covers the various key steps and elements
|
2014-05-25 11:50:11 -03:00
|
|
|
involved in creating a project:
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
* `Project structure`_
|
|
|
|
* `Building and packaging the project`_
|
2014-10-04 08:11:25 -03:00
|
|
|
* `Uploading the project to the Python Packaging Index`_
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
.. _Project structure: \
|
2016-02-26 14:37:12 -04:00
|
|
|
https://packaging.python.org/en/latest/distributing/
|
2014-03-16 01:13:56 -03:00
|
|
|
.. _Building and packaging the project: \
|
2016-02-26 14:37:12 -04:00
|
|
|
https://packaging.python.org/en/latest/distributing/#packaging-your-project
|
2014-10-04 08:11:25 -03:00
|
|
|
.. _Uploading the project to the Python Packaging Index: \
|
2016-02-26 14:37:12 -04:00
|
|
|
https://packaging.python.org/en/latest/distributing/#uploading-your-project-to-pypi
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
|
|
|
|
How do I...?
|
|
|
|
============
|
|
|
|
|
|
|
|
These are quick answers or links for some common tasks.
|
|
|
|
|
|
|
|
... choose a name for my project?
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
This isn't an easy topic, but here are a few tips:
|
|
|
|
|
2014-10-04 08:11:25 -03:00
|
|
|
* check the Python Packaging Index to see if the name is already in use
|
2014-03-16 01:13:56 -03:00
|
|
|
* check popular hosting sites like GitHub, BitBucket, etc to see if there
|
|
|
|
is already a project with that name
|
|
|
|
* check what comes up in a web search for the name you're considering
|
|
|
|
* avoid particularly common words, especially ones with multiple meanings,
|
|
|
|
as they can make it difficult for users to find your software when
|
|
|
|
searching for it
|
|
|
|
|
|
|
|
|
|
|
|
... create and distribute binary extensions?
|
|
|
|
--------------------------------------------
|
|
|
|
|
|
|
|
This is actually quite a complex topic, with a variety of alternatives
|
|
|
|
available depending on exactly what you're aiming to achieve. See the
|
|
|
|
Python Packaging User Guide for more information and recommendations.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
`Python Packaging User Guide: Binary Extensions
|
2016-02-26 14:37:12 -04:00
|
|
|
<https://packaging.python.org/en/latest/extensions>`__
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
.. other topics:
|
|
|
|
|
|
|
|
Once the Development & Deployment part of PPUG is fleshed out, some of
|
|
|
|
those sections should be linked from new questions here (most notably,
|
|
|
|
we should have a question about avoiding depending on PyPI that links to
|
2016-02-26 14:37:12 -04:00
|
|
|
https://packaging.python.org/en/latest/mirrors/)
|