Skip to content

Commit 40e3caf

Browse files
committed
Fix: clarification of pyproj toml metadata
1 parent b5cb005 commit 40e3caf

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

package-structure-code/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ src layout, flat layout and where should tests folders live? No matter what your
2828

2929
✨ 2. Learn about building your package ✨
3030
^^^
31-
Building a Python package is a great way to share your code with scientists to support open science workflow. The act of "building" refers to the process of placing your package code and
31+
Publishing a Python package is a great way to share your code with scientists to support open science workflow. In order to publish a package, you will need to first build it. The act of "building" refers to the process of placing your package code and
3232
metadata into a format that can be published on PyPI. Once published on PyPI, your users can easily install it locally using pip. Learn more about building a Python package here.
3333
:::
3434

package-structure-code/python-package-distribution-files-sdist-wheel.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,58 @@ and PyPI can use, is called a build step.
2525

2626
### Project metadata and PyPI
2727

28-
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.
28+
The metadata that both build tools and PyPI uses to describe and understand your package is generally stored in a [pyproject.toml file](pyproject-toml-python-package-metadata). This metadata is used for several purposes:
29+
30+
1. It helps whatever tool you use to build your package (pip, pypa's 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+
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.
33+
34+
```toml
35+
[build-system]
36+
requires = ["hatchling"]
37+
build-backend = "hatchling"
38+
```
39+
40+
- And the dependencies section of your project table tells the build tool and PyPI what dependencies your project requires.
41+
42+
```
43+
dependencies = [
44+
"numpy",
45+
"geopandas",
46+
]
47+
```
48+
49+
2. When the build tool creates your package distribution file (the file that you publish on PyPI), it also creates a METADATA file which PyPI can read and use to help users find your package. For example:
50+
51+
- The `classifiers = ` section of your `[project]` table in the pyproject.toml file provides information that users on PyPI can use to filter for packages that contain specific licenses or that support specific versions of python.
52+
53+
```toml
54+
classifiers = [
55+
# How mature is this project? Common values are
56+
"Development Status :: 4 - Beta",
57+
58+
# Indicate who your project is intended for
59+
"Intended Audience :: Developers",
60+
"Topic :: Software Development :: Build Tools",
61+
"License :: OSI Approved :: MIT License",
62+
"Programming Language :: Python :: 3 :: Only",
63+
"Programming Language :: Python :: 3.10",
64+
"Programming Language :: Python :: 3.11",
65+
]
66+
```
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)
70+
```
71+
72+
### An example - xclim
73+
74+
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.
2975

3076
```{figure} ../images/python-build-package/pypi-metadata-classifiers.png
3177
:scale: 50 %
3278
:align: center
33-
: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">
79+
:alt: Image showing the left side bar of PyPI 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">
3480
3581
When you add the classifier section to your pyproject.toml
3682
and your package is built, the build tool organizes the metadata into a format that PyPI can understand and

0 commit comments

Comments
 (0)