Dystrybucja modułów Pythona¶
Python, jako popularny projekt open source, cieszy się aktywnym wsparciem społeczności współtwórców i użytkowników, którzy udostępniają tworzone przez siebie oprogramowanie innym deweloperom Pythona w ramach licencji open source.
Dzięki temu użytkownicy Pythona mogą efektywnie korzystać się i współpracować korzystając z rozwiązań stworzonych wcześniej w odpowiedzi na popularne problemy (a czasami bardzo rzadkie!), oraz udostępniać własne rozwiązania całej społeczności.
Ta część przewodnika dotyczy procesu dystrybucji. O instalacji innych projektów Pythona przeczytasz więcej w przewodniku instalacji.
Informacja
Użytkownicy związani z korporacjami i innymi instytucjami powinni zwrócić uwagę, że wiele organizacji ma własne zasady dotyczące korzystania z oprogramowania i udziału w projektach open source. Należy brać takie zasady pod uwagę korzystając z narzędzi instalacyjnych i dystrybucyjnych Pythona.
Główne pojęcia¶
Python Packaging Index jest publicznym repozytorium paczek z licencją open-source, udostępnionych do wykorzystania przez innych użytkowników Pythona
the Python Packaging Authority are the group of 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 and Bitbucket.
distutils
is the original build and distribution system first added to the Python standard library in 1998. While direct use ofdistutils
is being phased out, it still laid the foundation for the current packaging 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).setuptools is a (largely) drop-in replacement for
distutils
first published in 2004. Its most notable addition over the unmodifieddistutils
tools was the ability to declare dependencies on other packages. It is currently recommended as a more regularly updated alternative todistutils
that offers consistent support for more recent packaging standards across a wide range of Python versions.wheel (in this context) is a project that adds the
bdist_wheel
command todistutils
/setuptools. This produces a cross platform 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.
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
by invoking the pip
module at the command line:
python -m pip install setuptools wheel twine
Informacja
For POSIX users (including Mac OS X and Linux users), these instructions assume the use of a virtual environment.
For Windows users, these instructions assume that the option to adjust the system PATH environment variable was selected when installing Python.
The Python Packaging User Guide includes more details on the currently recommended tools.
Reading the Python Packaging User Guide¶
The Python Packaging User Guide covers the various key steps and elements involved in creating and publishing a project:
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:
check the Python Packaging Index to see if the name is already in use
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.
Zobacz także