From 2b72872838e5e367137a7bf58376e29278bc4fb3 Mon Sep 17 00:00:00 2001 From: finswimmer Date: Wed, 30 Oct 2024 10:12:44 +0100 Subject: [PATCH] feat: limit build-system to current major version of poetry-core by default (#9812) --- src/poetry/layouts/layout.py | 15 +++++++++++++-- tests/console/commands/test_init.py | 13 +++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) 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()