Skip to content

Commit 2d7d173

Browse files
committed
doc(faq): add entry for PEP 621 migration
1 parent ff40baa commit 2d7d173

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed

docs/faq.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,166 @@ The two key options we are using here are `--no-root` (skips installing the proj
271271
Poetry's default HTTP request timeout is 15 seconds, the same as `pip`.
272272
Similar to `PIP_REQUESTS_TIMEOUT`, the **experimental** environment variable `POETRY_REQUESTS_TIMEOUT`
273273
can be set to alter this value.
274+
275+
276+
### How do I migrate an existing Poetry project using `tools.poetry` section to use the new `project` section (PEP 621)?
277+
278+
{{% note %}}
279+
Poetry `>=2.0.0` should seamlessly support both `tools.poetry` section only configuration as well using the `project` section. This
280+
lets you decide when and if you would like to migrate to using the `project` section as [described by PyPA](https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table).
281+
282+
See documentation on [the `pyproject.toml` file]({{< relref "pyproject" >}}), for information specific to Poetry.
283+
{{% /note %}}
284+
285+
Due to the nature of this change some manual changes to your `pyproject.toml` file is unavoidable in order start using the `project` section. The following tabs
286+
show a transition example. If you wish to retain Poetry's richer [dependency specification]({{< relref "dependency-specification" >}}) syntax it is recommended that
287+
you use dynamic dependencies as described in the second tab below.
288+
289+
{{< tabs tabTotal="3" tabID1="migrate-pep621-old" tabName1="Original" tabID2="migrate-pep621-new-dynamic" tabName2="Using Dynamic Dependencies" tabID3="migrate-pep621-new-static" tabName3="Using Static Dependencies">}}
290+
291+
{{< tab tabID="migrate-pep621-old" >}}
292+
293+
```toml
294+
[tool.poetry]
295+
name = "foobar"
296+
version = "0.1.0"
297+
description = ""
298+
authors = ["Baz Qux <[email protected]>"]
299+
readme = "README.md"
300+
packages = [{ include = "awesome", from = "src" }]
301+
include = [{ path = "tests", format = "sdist" }]
302+
homepage = "https://python-foobar.org/"
303+
repository = "https://github.com/python-foobar/foobar"
304+
documentation = "https://python-foobar.org/docs"
305+
keywords = ["packaging", "dependency", "foobar"]
306+
classifiers = [
307+
"Topic :: Software Development :: Build Tools",
308+
"Topic :: Software Development :: Libraries :: Python Modules",
309+
]
310+
311+
[tool.poetry.scripts]
312+
foobar = "foobar.console.application:main"
313+
314+
[tool.poetry.dependencies]
315+
python = "^3.13"
316+
httpx = "^0.28.1"
317+
318+
[tool.poetry.group.dev.dependencies]
319+
pre-commit = ">=2.10"
320+
321+
[tool.poetry.group.test.dependencies]
322+
pytest = ">=8.0"
323+
324+
[build-system]
325+
requires = ["poetry-core>=2.0.0,<3.0.0"]
326+
build-backend = "poetry.core.masonry.api"
327+
```
328+
329+
{{< /tab >}}
330+
331+
{{< tab tabID="migrate-pep621-new-static" >}}
332+
333+
```toml
334+
[project]
335+
name = "foobar"
336+
version = "0.1.0"
337+
description = ""
338+
authors = [
339+
{ name = "Baz Qux", email = "[email protected]" }
340+
]
341+
readme = "README.md"
342+
requires-python = ">=3.13"
343+
keywords = ["packaging", "dependency", "foobar"]
344+
# classifiers property is dynamic because we want to create Python classifiers automatically
345+
# dependencies are dynamic because we want to keep Poetry's rich dependency definition format
346+
dynamic = ["classifiers", "dependencies"]
347+
348+
[project.urls]
349+
homepage = "https://python-foobar.org/"
350+
repository = "https://github.com/python-foobar/foobar"
351+
documentation = "https://python-foobar.org/docs"
352+
353+
[project.scripts]
354+
foobar = "foobar.console.application:main"
355+
356+
[tool.poetry]
357+
requires-poetry = ">=2.0"
358+
packages = [{ include = "foobar", from = "src" }]
359+
include = [{ path = "tests", format = "sdist" }]
360+
classifiers = [
361+
"Topic :: Software Development :: Build Tools",
362+
"Topic :: Software Development :: Libraries :: Python Modules",
363+
]
364+
365+
[tool.poetry.dependencies]
366+
httpx = "^0.28.1"
367+
368+
[tool.poetry.group.dev.dependencies]
369+
pre-commit = ">=2.10"
370+
371+
[tool.poetry.group.test.dependencies]
372+
pytest = ">=8.0"
373+
374+
[build-system]
375+
requires = ["poetry-core>=2.0.0,<3.0.0"]
376+
build-backend = "poetry.core.masonry.api"
377+
```
378+
379+
{{< /tab >}}
380+
381+
{{< tab tabID="migrate-pep621-new-static" >}}
382+
383+
```toml
384+
[project]
385+
name = "foobar"
386+
version = "0.1.0"
387+
description = ""
388+
authors = [
389+
{ name = "Baz Qux", email = "[email protected]" }
390+
]
391+
readme = "README.md"
392+
requires-python = ">=3.13"
393+
keywords = ["packaging", "dependency", "foobar"]
394+
# classifiers property is dynamic because we want to create Python classifiers automatically
395+
dynamic = ["classifiers"]
396+
dependencies = [
397+
"httpx (>=0.28.1,<0.29.0)"
398+
]
399+
400+
[project.urls]
401+
homepage = "https://python-foobar.org/"
402+
repository = "https://github.com/python-foobar/foobar"
403+
documentation = "https://python-foobar.org/docs"
404+
405+
[project.scripts]
406+
foobar = "foobar.console.application:main"
407+
408+
[tool.poetry]
409+
requires-poetry = ">=2.0"
410+
packages = [{ include = "foobar", from = "src" }]
411+
include = [{ path = "tests", format = "sdist" }]
412+
classifiers = [
413+
"Topic :: Software Development :: Build Tools",
414+
"Topic :: Software Development :: Libraries :: Python Modules",
415+
]
416+
417+
[tool.poetry.group.dev.dependencies]
418+
pre-commit = ">=2.10"
419+
420+
[tool.poetry.group.test.dependencies]
421+
pytest = ">=8.0"
422+
423+
[build-system]
424+
requires = ["poetry-core>=2.0.0,<3.0.0"]
425+
build-backend = "poetry.core.masonry.api"
426+
```
427+
428+
{{< /tab >}}
429+
430+
{{< /tabs >}}
431+
432+
{{% note %}}
433+
- The `classifiers` property is dynamic to allow Poetry to create and manage Python classifiers in accordance with supported Python version.
434+
- The `python` dependency, in this example was replaced with `project.requires-python`. However, note that if you need an upper bound on supported Python versions refer to the documentation [here]({{< relref "pyproject#requires-python" >}}).
435+
- The [`requires-poetry`]({{< relref "pyproject#requires-poetry" >}}) is added to the `tools.poetry` section.
436+
{{% /note %}}

0 commit comments

Comments
 (0)