|
| 1 | +--- |
| 2 | +layout: single |
| 3 | +title: "Announcing Poetry 2.0.0" |
| 4 | +date: 2024-12-xx |
| 5 | +categories: [releases] |
| 6 | +tags: ["1.x", "2.0"] |
| 7 | +--- |
| 8 | + |
| 9 | +The Poetry team is pleased to announce the immediate availability of Poetry **2.0.0**. |
| 10 | + |
| 11 | +<!--more--> |
| 12 | + |
| 13 | +If you have a previous version of Poetry installed via `pipx`, |
| 14 | +getting Poetry **2.0.0** is as easy as: |
| 15 | + |
| 16 | +```bash |
| 17 | +$ pipx upgrade poetry |
| 18 | +``` |
| 19 | + |
| 20 | +If you used the [official installer](/docs/#installation), you can run: |
| 21 | + |
| 22 | +```bash |
| 23 | +$ poetry self update |
| 24 | +``` |
| 25 | + |
| 26 | +## Highlights |
| 27 | + |
| 28 | +### Supporting the `project` section in pyproject.toml (PEP 621) |
| 29 | + |
| 30 | +Poetry 2.0 respects the `project` section in the `pyproject.toml` as originally |
| 31 | +specified in [PEP 621](https://peps.python.org/pep-0621/) and now defined in the |
| 32 | +[pyproject.toml specification](https://packaging.python.org/en/latest/specifications/pyproject-toml/#pyproject-toml-spec). |
| 33 | +You can replace many fields in the `tool.poetry` section with their counterparts in the `project` section: |
| 34 | + |
| 35 | +```toml |
| 36 | +[project] |
| 37 | +name = "poetry-demo" |
| 38 | +version = "0.1.0" |
| 39 | +description = "" |
| 40 | +authors = [ |
| 41 | + { name = "Sébastien Eustace", email = "[email protected]"} |
| 42 | +] |
| 43 | +readme = "README.md" |
| 44 | +requires-python = ">=3.8" |
| 45 | + |
| 46 | +[tool.poetry] |
| 47 | +packages = [{include = "poetry_demo"}] |
| 48 | + |
| 49 | +[build-system] |
| 50 | +requires = ["poetry-core>=2.0"] |
| 51 | +build-backend = "poetry.core.masonry.api" |
| 52 | +``` |
| 53 | + |
| 54 | +Moreover, many fields in the `tool.poetry` section are deprecated in favor |
| 55 | +of their counterparts in the `project` section. Run |
| 56 | + |
| 57 | +```bash |
| 58 | +poetry check |
| 59 | +``` |
| 60 | + |
| 61 | +to see a list of deprecated fields in your `pyproject.toml` and their replacements |
| 62 | +or have a look into the [documentation](https://python-poetry.org/docs/main/pyproject/) |
| 63 | +to check if a field is deprecated. |
| 64 | + |
| 65 | +Please note that `tool.poetry.dependencies` is not deprecated because it supports features |
| 66 | +that are not supported by `project.dependencies`. Therefore, you have several options, |
| 67 | +which are explained in detail in |
| 68 | +[`project.dependencies` and `tool.poetry.dependencies`](https://python-poetry.org/docs/main/dependency-specification/#projectdependencies-and-toolpoetrydependencies): |
| 69 | + |
| 70 | +- If you only need standard features, we recommend to replace `tool.poetry.dependencies` with `project.dependencies`. |
| 71 | +- If you need Poetry specific features, you can still use `project.dependencies` |
| 72 | + and add additional information in `tool.poetry.dependencies`. |
| 73 | +- If you are heavily using Poetry specific features, you can declare `project.dependencies` as `dynamic` |
| 74 | + and solely use `tool.poetry.dependencies`. |
| 75 | + |
| 76 | +### Project plugins and forcing a minimum Poetry version |
| 77 | + |
| 78 | +You can now specify that your project depends on certain plugins: |
| 79 | + |
| 80 | +```toml |
| 81 | +[tool.poetry.requires-plugins] |
| 82 | +my-application-plugin = ">1.0" |
| 83 | +``` |
| 84 | + |
| 85 | +If you run `poetry install` and the plugin is not installed, |
| 86 | +Poetry will install it only for your project. See |
| 87 | +[project plugins](https://python-poetry.org/docs/main/plugins/#project-plugins) |
| 88 | +for details. |
| 89 | + |
| 90 | +Further, you can specify that your project requires a minimum version of Poetry. |
| 91 | +For example, if you are using the `project` section, you can specify: |
| 92 | + |
| 93 | +```toml |
| 94 | +[tool.poetry] |
| 95 | +requires-poetry = ">=2.0" |
| 96 | +``` |
| 97 | + |
| 98 | +### Locking resulting markers and groups |
| 99 | + |
| 100 | +This change is more under the hood but might be useful for debugging or auditing purposes |
| 101 | +and enables future improvements. Poetry now includes the resulting groups and markers |
| 102 | +for each package in the lock file, e.g.: |
| 103 | + |
| 104 | +```toml |
| 105 | +groups = ["main", "dev"] |
| 106 | +markers = 'sys_platform == "win32"' |
| 107 | +``` |
| 108 | + |
| 109 | +for a package that is required in the `main` and `dev` group but only on Windows. |
| 110 | + |
| 111 | +Currently, this information is not used by default but you can configure Poetry to |
| 112 | +use this information during installation: |
| 113 | + |
| 114 | +```bash |
| 115 | +poetry config installer.re-resolve false |
| 116 | +``` |
| 117 | + |
| 118 | +Per default, when installing packages from a lock file, Poetry re-resolves the dependencies |
| 119 | +with the packages from the lock file being the only source for packages. If you |
| 120 | +deactivate this behavior (and the lock file has been created with Poetry 2.0), |
| 121 | +it will not re-resolve but just evaluate the locked groups and markers to decide |
| 122 | +if a package should be installed. |
| 123 | + |
| 124 | +Setting `installer.re-resolve` to `false` might result in faster installations, |
| 125 | +especially if your dependency tree is more deep than broad. |
| 126 | + |
| 127 | +## Breaking changes and removals |
| 128 | + |
| 129 | +In the following, we only explain the most important breaking changes and removals. |
| 130 | +Many deprecated features have been removed in this major release. |
| 131 | +For a full list of changes and removals, see the changelog. |
| 132 | + |
| 133 | +### `poetry export` and `poetry shell` only available via plugins |
| 134 | + |
| 135 | +Since Poetry 1.2, `poetry export` is not a core feature of Poetry but |
| 136 | +is provided by `poetry-plugin-export`. However, previously `poetry-plugin-export` |
| 137 | +had been a dependency of Poetry itself and thus was installed per default. |
| 138 | +As announced in the last two minor releases, `poetry-plugin-export` is not included |
| 139 | +anymore in the default Poetry installation. See |
| 140 | +[Using plugin](https://python-poetry.org/docs/main/plugins/#using-plugins) |
| 141 | +for how to install plugins or even define that a plugin is required for your project. |
| 142 | + |
| 143 | +Although not announced before, we seized the chance of a major release to remove the |
| 144 | +`poetry shell` command . Due to several issues with `poetry shell`, we recommend |
| 145 | +to use the new `poetry env activate` command instead. This command does only print |
| 146 | +the command to activate the virtual environment. See |
| 147 | +[Activating the environment](https://python-poetry.org/docs/main/managing-environments/#activating-the-environment) |
| 148 | +for examples how to activate the environment in different shells. If you still want to |
| 149 | +use `poetry shell`, you can install the `poetry-plugin-shell` plugin. |
| 150 | + |
| 151 | +### `poetry lock` defaults to `--no-update` |
| 152 | + |
| 153 | +`poetry lock` now defaults to `--no-update` to prevent accidental updates of the lock file. |
| 154 | +If you want to regenerate the lock file from scratch (old default behavior), |
| 155 | +you can use `poetry lock --regenerate`. |
| 156 | + |
| 157 | +### `poetry add --optional` requires an extra |
| 158 | + |
| 159 | +In order to support the `project` section the interface of `poetry add --optional` |
| 160 | +had to be changed so that you cannot add optional dependencies without specifying |
| 161 | +an extra anymore. |
| 162 | + |
| 163 | +### `--directory`/`-C` actually switches the directory |
| 164 | + |
| 165 | +The `--directory`/`-C` option now actually switches the directory instead of just setting |
| 166 | +the directory as project root. The old behavior is now available via `--project`/`-P`. |
| 167 | + |
| 168 | +### Consistent `include` behavior |
| 169 | + |
| 170 | +When using `tool.poetry.include` without specifying the format, Poetry now defaults |
| 171 | +to "only sdist". Previously, it defaulted to "only sdist" for directories and to |
| 172 | +"sdist and wheel" for files. We recommend to be explicit and specify the formats |
| 173 | +instead of relying on the default. |
| 174 | + |
| 175 | +## Changelog |
| 176 | + |
| 177 | +TODO |
0 commit comments