Skip to content

Commit f6216e5

Browse files
committed
add support for PEP 639 License Clarity
1 parent 68ea7c8 commit f6216e5

8 files changed

Lines changed: 68 additions & 41 deletions

File tree

docs/libraries.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,19 @@ poetry build
6262
This command will package your library in two different formats: `sdist` which is
6363
the source format, and `wheel` which is a `compiled` package.
6464

65-
Poetry will automatically include some metadata files when building a package. When building
66-
a `wheel`, the following files are included in the `.dist-info` directory:
67-
- `LICENSE`
68-
- `LICENSE.*`
69-
- `COPYING`
70-
- `COPYING.*`
71-
- `LICENSES/**`
72-
73-
When building an `sdist`, the following files will be included in the root folder:
74-
- `LICENSE*`
65+
Poetry will automatically include some license-related files when building a package -
66+
in the `.dist-info/licenses` directory when building a `wheel`,
67+
and in the root folder when building an `sdist`:
68+
- `LICENSE*`
69+
- `LICENCE*`
70+
- `COPYING*`
71+
- `AUTHORS*`
72+
- `NOTICE*`
73+
- `LICENSES/**/*`
74+
75+
You can override this behavior by specifying
76+
[`license-files`]({{< relref "pyproject/#license-files" >}})
77+
in the `pyproject.toml` file.
7578

7679
### Alternative build backends
7780

docs/pyproject.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ description = "A short description of the package."
7171

7272
### license
7373

74-
The license of the package.
74+
An [SPDX expression](https://packaging.python.org/en/latest/glossary/#term-License-Expression)
75+
representing the license of the package.
7576

7677
The recommended notation for the most common licenses is (alphabetical):
7778

@@ -93,20 +94,43 @@ Optional, but it is highly recommended to supply this.
9394
More identifiers are listed at the [SPDX Open Source License Registry](https://spdx.org/licenses/).
9495

9596
```toml
96-
license = { text = "MIT" }
97+
license = "MIT"
9798
```
98-
{{% note %}}
99-
If your project is proprietary and does not use a specific license, you can set this value as `Proprietary`.
100-
{{% /note %}}
10199

102-
You can also specify a license file. However, when doing this, the complete license text
103-
will be added to the metadata and the License classifier cannot be determined
104-
automatically so that you have to add it manually.
100+
{{% warning %}}
101+
Specifying license as a table, e.g. `{ text = "MIT" }` is deprecated.
102+
If you used to specify a license file, e.g. `{ file = "LICENSE" }`,
103+
use `license-files` instead.
104+
{{% /warning %}}
105+
106+
### license-files
107+
108+
A list of glob patterns that match the license files of the package
109+
relative to the root of the project source tree.
105110

106111
```toml
107-
license = { file = "LICENSE" }
112+
[project]
113+
# ...
114+
license-files = [
115+
"*-LICENSE",
116+
"CONTRIBUTORS",
117+
"MY-SPECIAL-LICENSE-DIR/**/*"
118+
]
108119
```
109120

121+
Per default, Poetry will include the following files:
122+
- `LICENSE*`
123+
- `LICENCE*`
124+
- `COPYING*`
125+
- `AUTHORS*`
126+
- `NOTICE*`
127+
- `LICENSES/**/*`
128+
129+
{{% note %}}
130+
The default applies only if the `license-files` field is not specified.
131+
Specifying an empty list results in no license files being included.
132+
{{% /note %}}
133+
110134
### readme
111135

112136
A path to the README file or the content.
@@ -198,7 +222,7 @@ classifiers = [
198222
```
199223

200224
{{% warning %}}
201-
Note that suitable classifiers based on your `python` requirement and `license`
225+
Note that suitable classifiers based on your `python` requirement
202226
are **not** automatically added for you if you define classifiers statically
203227
in the `project` section.
204228

@@ -419,9 +443,6 @@ More identifiers are listed at the [SPDX Open Source License Registry](https://s
419443
```toml
420444
license = "MIT"
421445
```
422-
{{% note %}}
423-
If your project is proprietary and does not use a specific licence, you can set this value as `Proprietary`.
424-
{{% /note %}}
425446

426447
### authors
427448

@@ -545,11 +566,8 @@ classifiers = [
545566
Note that Python classifiers are automatically added for you
546567
and are determined by your `python` requirement.
547568

548-
The `license` property will also set the License classifier automatically.
549-
550569
If you do not want Poetry to automatically add suitable classifiers
551-
based on the `python` requirement and `license` property,
552-
use `project.classifiers` instead of this setting.
570+
based on the `python` requirement, use `project.classifiers` instead of this setting.
553571
{{% /note %}}
554572

555573
### packages

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "2.2.0.dev0"
44
description = "Python dependency management and packaging made easy."
55
requires-python = ">=3.9,<4.0"
66
dependencies = [
7-
"poetry-core @ git+https://github.com/python-poetry/poetry-core.git",
7+
"poetry-core @ git+https://github.com/radoering/poetry-core.git@pep639",
88
"build (>=1.2.1,<2.0.0)",
99
"cachecontrol[filecache] (>=0.14.0,<0.15.0)",
1010
"cleo (>=2.1.0,<3.0.0)",
@@ -16,7 +16,7 @@ dependencies = [
1616
"installer (>=0.7.0,<0.8.0)",
1717
"keyring (>=25.1.0,<26.0.0)",
1818
# packaging uses calver, so version is unclamped
19-
"packaging (>=24.0)",
19+
"packaging (>=24.2)", # PEP 639 support was added in 24.2
2020
"pkginfo (>=1.12,<2.0)",
2121
"platformdirs (>=3.0.0,<5)",
2222
"pyproject-hooks (>=1.0.0,<2.0.0)",
@@ -45,7 +45,7 @@ maintainers = [
4545
{ name = "finswimmer", email = "finswimmer77@gmail.com" },
4646
{ name = "Bartosz Sokorski", email = "b.sokorski@gmail.com" },
4747
]
48-
license = { text = "MIT" }
48+
license = "MIT"
4949
readme = "README.md"
5050
keywords = ["packaging", "dependency", "poetry"]
5151
# classifieres is dynamic because we want to create Python classifiers automatically

tests/console/commands/test_check.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def test_check_invalid(
173173
Error: Invalid source "not-exists" referenced in dependencies.
174174
Error: Invalid source "not-exists2" referenced in dependencies.
175175
Error: poetry.lock was not found.
176+
Warning: [project.license] is not a valid SPDX identifier.\
177+
This is deprecated and will raise an error in the future.
176178
Warning: A wildcard Python dependency is ambiguous.\
177179
Consider specifying a more explicit one.
178180
Warning: The "pendulum" dependency specifies the "allows-prereleases" property,\

tests/fixtures/invalid_pyproject/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "invalid"
33
version = "1.0.0"
4-
license = { text = "INVALID" }
4+
license = "INVALID"
55
classifiers = [
66
"Environment :: Console",
77
"Intended Audience :: Clowns",

tests/fixtures/simple_project/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Some description."
55
authors = [
66
{ name = "Sébastien Eustace", email = "sebastien@eustace.io" }
77
]
8-
license = { text = "MIT" }
8+
license = "MIT"
99
readme = "README.rst"
1010
keywords = ["packaging", "dependency", "poetry"]
1111
dynamic = [ "classifiers", "dependencies", "requires-python" ]

tests/masonry/builders/test_editable_builder.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ def test_builder_installs_proper_files_for_standard_packages(
192192
==========
193193
194194
"""
195-
assert metadata == dist_info.joinpath("METADATA").read_text(encoding="utf-8")
195+
if project == "simple_project":
196+
metadata = metadata.replace("License:", "License-Expression:").replace(
197+
"Classifier: License :: OSI Approved :: MIT License\n", ""
198+
)
199+
assert dist_info.joinpath("METADATA").read_text(encoding="utf-8") == metadata
196200

197201
with open(dist_info.joinpath("RECORD"), encoding="utf-8", newline="") as f:
198202
reader = csv.reader(f)
@@ -220,7 +224,7 @@ def test_builder_installs_proper_files_for_standard_packages(
220224
sys.exit(baz.boom.bim())
221225
"""
222226

223-
assert baz_script == tmp_venv._bin_dir.joinpath("baz").read_text(encoding="utf-8")
227+
assert tmp_venv._bin_dir.joinpath("baz").read_text(encoding="utf-8") == baz_script
224228

225229
foo_script = f"""\
226230
#!{tmp_venv.python}
@@ -231,7 +235,7 @@ def test_builder_installs_proper_files_for_standard_packages(
231235
sys.exit(bar())
232236
"""
233237

234-
assert foo_script == tmp_venv._bin_dir.joinpath("foo").read_text(encoding="utf-8")
238+
assert tmp_venv._bin_dir.joinpath("foo").read_text(encoding="utf-8") == foo_script
235239

236240
fox_script = f"""\
237241
#!{tmp_venv.python}
@@ -242,7 +246,7 @@ def test_builder_installs_proper_files_for_standard_packages(
242246
sys.exit(bar.baz())
243247
"""
244248

245-
assert fox_script == tmp_venv._bin_dir.joinpath("fox").read_text(encoding="utf-8")
249+
assert tmp_venv._bin_dir.joinpath("fox").read_text(encoding="utf-8") == fox_script
246250

247251

248252
def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(

0 commit comments

Comments
 (0)