|
1 | 1 | # The Python Package Source and Wheel Distributions
|
2 | 2 |
|
| 3 | +```{figure} ../images/python-package-development-process.png |
| 4 | +:align: center |
| 5 | +:alt: Image showing the left side bar of PiPy for the package xclim. The section at the top says Classifier. Below there is a list of items including Development status, intended audience, License, natural language, operating system, programming language and topic. Below each of those sections are various classifier options." width="300px"> |
| 6 | +
|
| 7 | +Notice the metadata printed on the PyPI page for xclim. When you add the classifier section to your pyproject.toml |
| 8 | +and your package is built, the build tool organizes the metadata into a format that PyPI can understand and |
| 9 | +represent on your pypi landing page. These classifiers also allow users to sort through packages by version of python they support, categories and more. |
| 10 | +``` |
| 11 | + |
| 12 | +## What is building a Python package? |
| 13 | + |
| 14 | +In Python, if you want to publish your code in a way that can be |
| 15 | +installed by both yourself and others, your code, tests and associated |
| 16 | +metadata need to be organized in a specific way. This specific |
| 17 | +organization and structure is important because it's the structure |
| 18 | +that both `PyPI` and any installer that you use like `pip` can |
| 19 | +understand and parse. This process of organizing and formatting your |
| 20 | +code, documentation, tests and metadata into a format that both pip |
| 21 | +and PyPI can use, is called a build step. |
| 22 | + |
| 23 | +For instance, when you publish to PyPI, you will notice that each package has metadata listed. Let’s have a look at [xclim](https://pypi.org/project/xclim/), one of our [pyOpenSci packages](https://www.pyopensci.org/python-packages.html). Notice that on the PyPI landing page you see some metadata about the package including python, maintainer information and more. PyPI is able to populate this metadata because it was defined using correct syntax and classifiers by Xclim's maintainers, [pyproject.toml file](https://github.com/Ouranosinc/xclim/blob/master/pyproject.toml). This metadata when the xclim package is built, is translated into a distribution file that allows PyPI to read the metadata and print it out on their website. |
| 24 | + |
| 25 | +```{figure} ../images/python-build-package/pypi-metadata-classifiers.png |
| 26 | +:scale: 50 % |
| 27 | +:align: center |
| 28 | +:alt: Image showing the left side bar of PiPy for the package xclim. The section at the top says Classifier. Below there is a list of items including Development status, intended audience, License, natural language, operating system, programming language and topic. Below each of those sections are various classifier options." width="300px"> |
| 29 | +
|
| 30 | +When you add the classifier section to your pyproject.toml |
| 31 | +and your package is built, the build tool organizes the metadata into a format that PyPI can understand and |
| 32 | +represent on your pypi landing page. These classifiers also allow users to sort through packages by version of python they support, categories and more. |
| 33 | +``` |
| 34 | + |
| 35 | +:::{figure-md} fig-target |
| 36 | +<img src="../images/python-build-package/pypi-metadata-keywords-license.png" alt="t." width="700px"> |
| 37 | + |
| 38 | +::: |
| 39 | + |
| 40 | +:::{figure-md} fig-target |
| 41 | +<img src="../images/python-build-package/pypi-metadata-maintainers.png" alt="t." width="700px"> |
| 42 | + |
| 43 | +::: |
| 44 | + |
| 45 | +## How to create the distribution format that PyPI and Pip expects? |
| 46 | + |
| 47 | +You could in theory create your own scripts to organize your code the way PyPI wants it to be. However, just like there are packages that handle known structures such as Pandas for data frames and Numpy for arrays, there are packages and tools that help you create package build distribution files. |
| 48 | + |
| 49 | +```{note} |
| 50 | +
|
| 51 | +There are a suite of packaging tools that can either help you with |
| 52 | +the entire packaging process or just one step of the process. For instance |
| 53 | +setuptools is a commonly used build back end that can be used to create your |
| 54 | +SDist and wheel. Whereas tools like Hatch, PDM, Poetry and flit help with other |
| 55 | +parts of the packaging process. |
| 56 | +
|
| 57 | +While this can cause some confusion and |
| 58 | +complexity in the packaging ecosystem - for the most part, each tool provides |
| 59 | +the same distribution output (with minor differences that most users may not |
| 60 | +care about). Learn more about those tools on this page. |
| 61 | +``` |
| 62 | + |
| 63 | +Below, you will learn about the two distribution files that PyPI expects you to publish: SDist and Wheel. You will learn about |
| 64 | +their structure and what files belong in each. |
| 65 | + |
3 | 66 | There are two core distribution files
|
4 | 67 | that you need to create to publish your Python package to
|
5 | 68 | PyPI source distribution (often called an sdist) and wheel. The sdist contains the raw source
|
|
0 commit comments