Skip to content

Commit fe627e9

Browse files
feat: use PEP 639 where possible (#592)
* feat: use PEP 639 where possible Signed-off-by: Henry Schreiner <[email protected]> * docs: update text and min versions Signed-off-by: Henry Schreiner <[email protected]> * style: pre-commit fixes --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6cc4c0e commit fe627e9

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

docs/_includes/pyproject.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ The metadata is specified in a [standards-based][metadata] format:
77
name = "package"
88
description = "A great package."
99
readme = "README.md"
10+
license = "BSD-3-Clause"
11+
license-files = ["LICENSE"]
1012
authors = [
1113
{ name = "My Name", email = "[email protected]" },
1214
]
@@ -21,7 +23,6 @@ dependencies = [
2123

2224
classifiers = [
2325
"Development Status :: 4 - Beta",
24-
"License :: OSI Approved :: BSD License",
2526
"Programming Language :: Python :: 3 :: Only",
2627
"Programming Language :: Python :: 3.9",
2728
"Programming Language :: Python :: 3.10",
@@ -47,19 +48,28 @@ or [Whey](https://whey.readthedocs.io/en/latest/configuration.html). Note that
4748

4849
### License
4950

50-
The license can be done one of two ways. The classic convention (shown above)
51-
uses one or more [Trove Classifiers][] to specify the license. The other way is
52-
to use the `license` field and an [SPDX identifier expression][spdx]:
51+
The license can be done one of two ways.
5352

54-
```toml
55-
license = "BSD-3-Clause"
56-
```
53+
The modern way is to use the `license` field and an [SPDX identifier
54+
expression][spdx]. You can specify a list of files globs in `license-files`.
55+
Currently, `hatchling>=1.26`, `flit-core>=1.11`, `pdm-backend>=2.4`,
56+
`setuptools>=77`, and `scikit-build-core>=0.12` support this. Only `maturin`,
57+
`meson-python`, and `flit-core` do not support this yet.
58+
59+
The classic convention uses one or more [Trove Classifiers][] to specify the
60+
license. There also was a `license.file` field, required by `meson-python`, but
61+
other tools often did the wrong thing (such as load the entire file into the
62+
metadata's free-form one line text field that was intended to describe
63+
deviations from the classifier license(s)).
5764

58-
You can also specify files to include with the `license-files` field.
65+
```
66+
classifiers = [
67+
"License :: OSI Approved :: BSD License",
68+
]
69+
```
5970

6071
You should not include the `License ::` classifiers if you use the `license`
61-
field {% rr PP007 %}. Some backends do not support this fully yet (notably
62-
Poetry and Setuptools).
72+
field {% rr PP007 %}.
6373

6474
### Extras
6575

noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,15 @@ def dist(session: nox.Session, backend: str, vcs: bool) -> None:
282282
# Check for LICENSE in SDist
283283
with tarfile.open(sdist) as tf:
284284
names = tf.getnames()
285+
if backend not in {"mesonpy", "poetry", "maturin"}:
286+
(metadata_path,) = (
287+
n for n in names if n.endswith("PKG-INFO") and "egg-info" not in n
288+
)
289+
with tf.extractfile(metadata_path) as mfile:
290+
info = mfile.read().decode("utf-8")
291+
if "License-Expression: BSD-3-Clause" not in info:
292+
msg = "License expression not found in METADATA"
293+
session.error(msg)
285294
if not any(n.endswith("LICENSE") for n in names):
286295
msg = f"license file missing from {backend} vcs={vcs}'s sdist. Found: {names}"
287296
session.error(msg)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors = [
1010
]
1111
description = "Review repos for compliance to the Scientific-Python development guidelines"
1212
requires-python = ">=3.10"
13-
license = 'BSD-3-Clause'
13+
license = "BSD-3-Clause"
1414
classifiers = [
1515
"Development Status :: 4 - Beta",
1616
"Environment :: Console",

{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
[build-system]
22
{%- if cookiecutter.backend == "pdm" %}
3-
requires = ["pdm-backend"]
3+
requires = ["pdm-backend>=2.4"]
44
build-backend = "pdm.backend"
55
{%- elif cookiecutter.backend == "maturin" %}
66
requires = ["maturin>=0.15,<2"]
77
build-backend = "maturin"
88
{%- elif cookiecutter.backend == "hatch" %}
99
{%- if cookiecutter.vcs %}
10-
requires = ["hatchling", "hatch-vcs"]
10+
requires = ["hatchling>=1.26", "hatch-vcs"]
1111
{%- else %}
12-
requires = ["hatchling"]
12+
requires = ["hatchling>=1.26"]
1313
{%- endif %}
1414
build-backend = "hatchling.build"
1515
{%- elif cookiecutter.backend == "setuptools" %}
1616
{%- if cookiecutter.vcs %}
17-
requires = ["setuptools>=61", "setuptools_scm[toml]>=7"]
17+
requires = ["setuptools>=77", "setuptools_scm[toml]>=7"]
1818
{%- else %}
19-
requires = ["setuptools>=61"]
19+
requires = ["setuptools>=77"]
2020
{%- endif %}
2121
build-backend = "setuptools.build_meta"
2222
{%- elif cookiecutter.backend == "flit" %}
2323
{%- if cookiecutter.vcs %}
24-
requires = ["flit_scm"]
24+
requires = ["flit_scm", "flit_core>=3.11"]
2525
build-backend = "flit_scm:buildapi"
2626
{%- else %}
27-
requires = ["flit_core>=3.4"]
27+
requires = ["flit_core>=3.11"]
2828
build-backend = "flit_core.buildapi"
2929
{%- endif %}
3030
{%- elif cookiecutter.backend == "pybind11" %}
3131
{%- if cookiecutter.vcs %}
32-
requires = ["setuptools>=61", "setuptools_scm[toml]>=7", "pybind11"]
32+
requires = ["setuptools>=77", "setuptools_scm[toml]>=7", "pybind11"]
3333
{%- else %}
34-
requires = ["setuptools>=61", "pybind11"]
34+
requires = ["setuptools>=77", "pybind11"]
3535
{%- endif %}
3636
build-backend = "setuptools.build_meta"
3737
{%- elif cookiecutter.backend == "skbuild" %}
38-
requires = ["pybind11", "scikit-build-core>=0.10"]
38+
requires = ["pybind11", "scikit-build-core>=0.11"]
3939
build-backend = "scikit_build_core.build"
4040
{%- elif cookiecutter.backend == "mesonpy" %}
4141
requires = ["meson-python", "pybind11"]
@@ -66,20 +66,31 @@ maintainers = [
6666
{%- endif %}
6767
description = "{{ cookiecutter.project_short_description }}"
6868
readme = "README.md"
69-
{%- if cookiecutter.backend in ['flit', 'mesonpy'] %}
69+
{%- if cookiecutter.backend not in ['poetry', 'mesonpy', 'maturin'] %}
70+
{%- if cookiecutter.license == "BSD" %}
71+
license = "BSD-3-Clause"
72+
{%- elif cookiecutter.license == "Apache" %}
73+
license = "Apache-2.0"
74+
{%- elif cookiecutter.license == "MIT" %}
75+
license = "MIT"
76+
{%- endif %}
77+
{%- endif %}
78+
{%- if cookiecutter.backend in ['mesonpy'] %}
7079
license.file = "LICENSE"
7180
{%- endif %}
7281
requires-python = ">=3.9"
7382
classifiers = [
7483
"Development Status :: 1 - Planning",
7584
"Intended Audience :: Science/Research",
7685
"Intended Audience :: Developers",
86+
{%- if cookiecutter.backend in ['poetry', 'mesonpy', 'maturin'] %}
7787
{%- if cookiecutter.license == "BSD" %}
7888
"License :: OSI Approved :: BSD License",
7989
{%- elif cookiecutter.license == "Apache" %}
8090
"License :: OSI Approved :: Apache Software License",
8191
{%- elif cookiecutter.license == "MIT" %}
8292
"License :: OSI Approved :: MIT License",
93+
{%- endif %}
8394
{%- endif %}
8495
"Operating System :: OS Independent",
8596
"Programming Language :: Python",

0 commit comments

Comments
 (0)