Skip to content

Commit

Permalink
feat: limit build-system to current major version of poetry-core by d…
Browse files Browse the repository at this point in the history
…efault (#9812)
  • Loading branch information
finswimmer authored Oct 30, 2024
1 parent 0c82c21 commit 2b72872
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/poetry/layouts/layout.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import subprocess
import sys
import textwrap

from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2b72872

Please sign in to comment.