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
-What {term}`Build backend` to use to build your package (we are using
90
+
-what {term}`Build backend` to use to build your package (we are using
92
91
{term}`Hatchling` in this tutorial but there are
93
92
[many others to choose from](/package-structure-code/python-package-build-tools)).
94
-
-How and where to retrieve your package's version:
93
+
-how and where to retrieve your package's version:
95
94
-**statically** where you declare the version `version = "0.1.0"` or
96
95
-**dynamically** where the tool looks to the most recent tag in your history to determine the current version.
97
-
-What {term}`Dependencies` your package needs
98
-
-What versions of Pythonyour package supports (important for your users).
96
+
-what {term}`Dependencies` your package needs,
97
+
-it can also declare Python-version requirements if your package has them.
99
98
100
99
The `pyproject.toml` file also makes it easy for anyone browsing your GitHub
101
100
repository to quickly understand your package's structure such as:
@@ -315,52 +314,35 @@ If you have multiple licenses, or a custom license, you can also express these u
315
314
316
315
If you want to distribute license files, or other files containing legal information, with your package, you can include these using the [`license-files`](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license-files) entry, but this is not required.
317
316
318
-
### Step 3: Specify Python version with `requires-python`
319
-
320
-
Add the `requires-python` field to your `pyproject.toml``[project]` table.
321
-
The `requires-python` field helps pip identify which Python versions that your package supports.
322
-
It is set to a single value.
323
-
The [packaging specification](https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata-requires-python) defines`requires-python` as a string that uses version specifiers. Most projects will specify the oldest Python version supported by the package. In some advanced cases, an upper bound is set to indicate which future Python versions, if any, will be supported.
324
-
325
317
:::{admonition} But how do I figure out which Python versions I should support?
326
318
:class: tip
327
319
Good question. The Python developer guide provides a [status page](https://devguide.python.org/versions/) (and a handy visualization) that explains the status of each Python release. Python releases go through several different phases that are explained in [PEP 602](https://peps.python.org/pep-0602/).
328
320
329
321
We recommend that you use the latest Python release in the **bugfix** phase. If your Python release is in the **security** phase, we recommend migrating to a newer version of Python.
330
-
331
-
[SPEC 0](https://scientific-python.org/specs/spec-0000/) of the Scientific Python project suggests a common schedule for dependencies, including Python release versions, and is also worth considering for your project.
332
322
:::
333
323
334
-
{emphasize-lines="22"}
335
-
```toml
336
-
[build-system]
337
-
requires = ["hatchling"]
338
-
build-backend = "hatchling.build"
324
+
:::{admonition} When should I use `requires-python`?
325
+
:class: tip
326
+
You do not need to specify `requires-python` for every package. However, if you
327
+
know that your package will not work with older versions of Python, use `requires-python`
328
+
to prevent installers from installing it with those versions. For example, if your package
329
+
requires features introduced in Python 3.10:
339
330
331
+
```toml
340
332
[project]
341
-
name = "pyospackage"
342
-
version = "0.1.0"
343
-
description = """
344
-
Tools that update the pyOpenSci contributor and review metadata
345
-
that is posted on our website
346
-
"""
347
-
authors = [
348
-
{ name = "Firstname Lastname", email = "email@pyopensci.org"},
349
-
{ name = "Secondperson Fullname", email = "email2@pyopensci.org" }
350
-
]
351
-
maintainers = [
352
-
{ name = "Secondperson Fullname", email = "email2@pyopensci.org" },
353
-
{ name = "New Friend", email = "newbie@pyopensci.org" }
354
-
]
355
-
readme = "README.md"
356
-
license = "MIT"
357
333
requires-python = ">=3.10"
358
334
```
359
335
360
-
### Step 4: Specify Dependencies
336
+
This helps `pip` select a compatible release of your package for the Python version a user is running.
337
+
:::
338
+
339
+
### Step 3: Specify dependencies
361
340
362
341
Next add your dependencies table to the project table.
363
-
The `dependencies =` section contains a list (or array in the toml language) of the Python packages that your package requires to run properly in a Python environment. Similar to the requirements listed in the `[build-system]` table above:
342
+
The `dependencies =` section contains a list (or array in the toml language) of
343
+
the Python packages that your package requires to run properly in a Python
344
+
environment. Similar to the requirements listed in the `[build-system]`
One build tool that you should be aware of that pins dependencies to an upper bound by default is Poetry. [Read more about how to safely add dependencies with Poetry, here.](challenges-with-poetry)
456
437
:::
457
438
458
-
### Step 5: Add PyPI classifiers
439
+
### Step 4: Add PyPI classifiers
459
440
460
441
Next you will add classifiers to your `pyproject.toml` file. The value for each classifier that you add to your `pyproject.toml` file must come from the list of [PyPI accepted classifier values found here](https://PyPI.org/classifiers/). Any deviations in spelling and format will cause issues when you publish to PyPI.
Note that while classifiers are not required in your `pyproject.toml` file, they will help users find your package. As such we strongly recommend that you add them.
518
498
519
-
### Step 6: Add the `[project.urls]` table
499
+
### Step 5: Add the `[project.urls]` table
520
500
521
501
Finally, add the project.urls table to your pyproject.toml file.
0 commit comments