You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: package-structure-code/python-package-distribution-files-sdist-wheel.md
+27-13Lines changed: 27 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
# Learn about Building a Python Package
2
2
3
-
:::{figure-md} build-workflow
4
-
<imgsrc="../images/python-package-development-process.png"alt="Alt tag to be added when image is final"width="700px">
3
+
:::{figure-md} build_workflow
4
+
<imgsrc="../images/python-package-development-process.png"alt="Graphic showing the high level packaging workflow. On the left you see a graphic with code, metadata and tests in it. those items all go into your package. Documentation and data are below that box because they aren't normally published in your packaging wheel distribution. an arrow to the right takes you to a build distribution files box. that box leads you to either publishing to testpypi or the real pypi. from pypi you can then connect to conda forge for an automated build that sends distributions from pypi to conda-forge. "width="700px">
5
5
6
-
You need to build your Python package in order to publish it to PyPI (or Conda). The build process organizes your code and metadata into a distribution format that can be uploaded to PyPI and subsequently downloaded and installed by users.
6
+
You need to build your Python package in order to publish it to PyPI (or Conda). The build process organizes your code and metadata into a distribution format that can be uploaded to PyPI and subsequently downloaded and installed by users. NOTE: you need to publish a sdist to PyPI in order for conda-forge to properly build your package automatically.
7
7
:::
8
8
9
9
## What is building a Python package?
10
10
11
-
To [publish your Python package](build-workflow) and make it easy for anyone to install, you first need to build it.
11
+
To [publish your Python package](build_workflow) and make it easy for anyone to install, you first need to build it.
12
12
13
13
But, what does it mean to build a Python package?
14
14
15
-
[As shown in the figure above](build-workflow), when you build your Python package, you convert the source files into something called a distribution package. A distribution package contains your source code and metadata about the package, in the format required by the Python Package Index, so that it can be installed by tools like pip.
15
+
[As shown in the figure above](build_workflow), when you build your Python package, you convert the source files into something called a distribution package. A distribution package contains your source code and metadata about the package, in the format required by the Python Package Index, so that it can be installed by tools like pip.
16
16
17
17
:::{note}
18
18
The term package used to mean many different things in Python and other languages. On this page, we adapt the convention of the [Python Packaging Authority](https://www.pypa.io/en/latest/) and refer to the product of the
@@ -29,7 +29,7 @@ The metadata that both build tools and PyPI uses to describe and understand your
29
29
30
30
1. It helps whatever tool you use to build your package (pip, [pypa's Build](https://pypi.org/project/build/) or an end-to-end tool such as poetry, PDM or Hatch) understand how to build your package. Information it provides to your build tool includes:
31
31
32
-
- The [build-system] table in your pyproject.toml file tells pip what [build backend tool](python-package-build-tools.html#build-back-ends) you wish to use for creating your sdist and wheel distributions.
32
+
- The `[build-system]` table in your pyproject.toml file tells pip what [build backend tool](build_backends) you wish to use for creating your sdist and wheel distributions.
33
33
34
34
```toml
35
35
[build-system]
@@ -65,8 +65,10 @@ classifiers = [
65
65
]
66
66
```
67
67
68
-
```{admonition}
69
-
project metadata used to be stored in either a setup.py file or a setup.cfg file. The current recommended practice for storing package metadata is to use a pyproject.toml file. [Learn more about the pyproject.toml file here.](pyproject-toml-python-package-metadata)
68
+
```{admonition} What happened to setup.py and setup.cfg for metadata?
69
+
:class: note
70
+
71
+
Project metadata used to be stored in either a setup.py fileor a setup.cfg file. The current recommended practice for storing package metadata is to use a pyproject.toml file. [Learn more about the pyproject.toml file here.](pyproject-toml-python-package-metadata)
70
72
```
71
73
72
74
### An example - xclim
@@ -80,17 +82,29 @@ When you publish to PyPI, you will notice that each package has metadata listed.
80
82
81
83
When you add the classifier section to your pyproject.toml
82
84
and your package is built, the build tool organizes the metadata into a format that PyPI can understand and
83
-
represent on your pypi landing page. These classifiers also allow users to sort through packages by version of python they support, categories and more.
85
+
represent on your PyPI landing page. These classifiers also allow users to sort through packages by version of python they support, categories and more.
<img src="../images/python-package-development-process.png" alt="Graphic showing the high level packaging workflow. On the left you see a graphic with code, metadata and tests in it. those items all go into your package. Documentation and data are below that box because they aren't normally published in your packaging wheel distribution. an arrow to the right takes you to a build distribution files box. that box leads you to either publishing to testpypi or the real pypi. from pypi you can then connect to conda forge for an automated build that sends distributions from pypi to conda-forge. " width="700px">
88
90
91
+
You need to build your Python package in order to publish it to PyPI (or Conda). The build process organizes your code and metadata into a distribution format that can be uploaded to PyPI and subsequently downloaded and installed by users. NOTE: you need to publish a sdist to PyPI in order for conda-forge to properly build your package automatically.
<img src="../images/python-build-package/pypi-metadata-keywords-license.png" alt="This screenshot shows the metadata on pypi for the xclim package. on it you can see the name of the license, the author and maintainer names keywords associated with the package and the base python version it requires which is 3.8." width="400px">
97
+
98
+
PyPI screenshot showing metadata for the xclim package.
99
+
:::
100
+
101
+
---
102
+
103
+
:::{figure-md} pypi-metadata-maintainers
104
+
105
+
<img src="../images/python-build-package/pypi-metadata-maintainers.png" alt="Here you see the maintinaer metadata as it is displayed on PyPI. for xclim there are three maintainers listed with their profile pictures and github user names to the right. " width="300px">
93
106
107
+
Maintainer names and GitHub usernames for the xclim package as they are displayed on PyPI. This information is recorded in your pyproject.toml and then processed by your build tool and stored in your packages sdist and wheel distributions.
94
108
:::
95
109
96
110
## How to create the distribution format that PyPI and Pip expects?
0 commit comments