diff --git a/src/poetry/layouts/layout.py b/src/poetry/layouts/layout.py index 4b1d42bf719..18f72e903ea 100644 --- a/src/poetry/layouts/layout.py +++ b/src/poetry/layouts/layout.py @@ -1,10 +1,13 @@ from __future__ import annotations +import importlib.metadata + from pathlib import Path from typing import TYPE_CHECKING from typing import Any from packaging.utils import canonicalize_name +from poetry.core.constraints.version import Version from poetry.core.utils.helpers import module_name from poetry.core.utils.patterns import AUTHOR_REGEX from tomlkit import inline_table @@ -41,8 +44,16 @@ [tool.poetry.group.dev.dependencies] """ -BUILD_SYSTEM_MIN_VERSION: str | None = None -BUILD_SYSTEM_MAX_VERSION: str | None = None +poetry_core_version = Version.parse(importlib.metadata.version("poetry-core")) + +BUILD_SYSTEM_MIN_VERSION: str | None = Version.from_parts( + major=poetry_core_version.major, + minor=poetry_core_version.minor if poetry_core_version.major == 0 else 0, + patch=poetry_core_version.patch + if (poetry_core_version.major, poetry_core_version.minor) == (0, 0) + else 0, +).to_string() +BUILD_SYSTEM_MAX_VERSION: str | None = poetry_core_version.next_breaking().to_string() class Layout: diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py index 20aeede6b2a..68f3e39faa3 100644 --- a/tests/console/commands/test_init.py +++ b/tests/console/commands/test_init.py @@ -4,6 +4,7 @@ import shutil import subprocess import sys +import textwrap from pathlib import Path from typing import TYPE_CHECKING @@ -95,6 +96,14 @@ def test_noninteractive( assert 'name = "my-package"' in toml_content assert '"pytest (>=3.6.0,<4.0.0)"' in toml_content + expected_build_system = textwrap.dedent(""" + [build-system] + requires = ["poetry-core>=2.0.0,<3.0.0"] + build-backend = "poetry.core.masonry.api" + """) + + assert expected_build_system in toml_content + def test_interactive_with_dependencies( tester: CommandTester, repo: TestRepository @@ -148,6 +157,10 @@ def test_interactive_with_dependencies( [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" + +[build-system] +requires = ["poetry-core>=2.0.0,<3.0.0"] +build-backend = "poetry.core.masonry.api" """ assert expected in tester.io.fetch_output()