Skip to content

Commit beadd42

Browse files
authored
add support for PEP 639 License Clarity (#10413)
Further, license files and the "WHEEL" file are now also included in editable installs.
1 parent 9f276d3 commit beadd42

File tree

11 files changed

+78
-54
lines changed

11 files changed

+78
-54
lines changed

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+
By 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: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)",
@@ -44,7 +44,7 @@ maintainers = [
4444
{ name = "finswimmer", email = "[email protected]" },
4545
{ name = "Bartosz Sokorski", email = "[email protected]" },
4646
]
47-
license = { text = "MIT" }
47+
license = "MIT"
4848
readme = "README.md"
4949
keywords = ["packaging", "dependency", "poetry"]
5050
# classifieres is dynamic because we want to create Python classifiers automatically

src/poetry/masonry/builders/editable.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ def _add_scripts(self) -> list[Path]:
216216
def _add_dist_info(self, added_files: list[Path]) -> None:
217217
from poetry.core.masonry.builders.wheel import WheelBuilder
218218

219-
added_files = added_files[:]
220-
221219
builder = WheelBuilder(self._poetry)
222220
dist_info = self._env.site_packages.mkdir(Path(builder.dist_info))
223221

@@ -226,24 +224,15 @@ def _add_dist_info(self, added_files: list[Path]) -> None:
226224
f" <b>{dist_info.parent}</b>"
227225
)
228226

229-
with dist_info.joinpath("METADATA").open("w", encoding="utf-8") as f:
230-
builder._write_metadata_file(f)
231-
232-
added_files.append(dist_info.joinpath("METADATA"))
227+
builder.prepare_metadata(dist_info.parent)
228+
for path in sorted(f for f in dist_info.rglob("*") if f.is_file()):
229+
added_files.append(path)
233230

234231
with dist_info.joinpath("INSTALLER").open("w", encoding="utf-8") as f:
235232
f.write("poetry")
236233

237234
added_files.append(dist_info.joinpath("INSTALLER"))
238235

239-
if self.convert_entry_points():
240-
with dist_info.joinpath("entry_points.txt").open(
241-
"w", encoding="utf-8"
242-
) as f:
243-
builder._write_entry_points(f)
244-
245-
added_files.append(dist_info.joinpath("entry_points.txt"))
246-
247236
# write PEP 610 metadata
248237
direct_url_json = dist_info.joinpath("direct_url.json")
249238
direct_url_json.write_text(

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",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
license ...

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 = "[email protected]" }
77
]
8-
license = { text = "MIT" }
8+
license = "MIT"
99
readme = "README.rst"
1010
keywords = ["packaging", "dependency", "poetry"]
1111
dynamic = [ "classifiers", "dependencies", "requires-python" ]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
license ...

0 commit comments

Comments
 (0)