Skip to content

Commit

Permalink
feat(cli): fallback to build-in poetry-core on build
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Jan 22, 2025
1 parent 8f95399 commit e9e227d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/poetry/console/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ def _requires_isolated_build(self) -> bool:
:returns: True if an isolated build is required, False otherwise.
"""
if not self._has_build_backend_defined():
self.io.write_error_line(
"<warning>WARNING: No build backend defined. Please define one in the pyproject.toml.\n"
"Fallback to the build-in `poetry-core` version.\n"
"This warning will turn into an error in the future.\n"
"More details can be found at https://python-poetry.org/docs/main/libraries/#packaging</>"
)
return False

if (
self.poetry.package.build_script
or len(self.poetry.build_system_dependencies) != 1
Expand All @@ -114,6 +123,9 @@ def _get_builder(self) -> Callable[..., None]:

return self._build

def _has_build_backend_defined(self) -> bool:
return "build-backend" in self.poetry.pyproject.data.get("build-system", {})

def build(self, options: BuildOptions) -> int:
if not self.poetry.is_package_mode:
self.io.write_error_line(
Expand Down
2 changes: 2 additions & 0 deletions tests/console/commands/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def test_prepare_formats(fmt: str | None, expected_formats: list[str]) -> None:
("multiple_build_deps", True),
("no_core", True),
("core_from_git", True),
("no_build_system", False),
("no_build_backend", False),
],
)
def test_requires_isolated_build(
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/build_systems/no_build_backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
14 changes: 14 additions & 0 deletions tests/fixtures/build_systems/no_build_backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = [
{ name = "Poetry Contributors", email = "[email protected]" }
]
license = { text = "MIT" }
readme = "README.md"
keywords = ["packaging", "dependency", "poetry"]
requires-python = ">=3.4"

[build-system]
requires = ["poetry-core>=1.1.0a7"]
Empty file.
2 changes: 2 additions & 0 deletions tests/fixtures/build_systems/no_build_system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
11 changes: 11 additions & 0 deletions tests/fixtures/build_systems/no_build_system/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = [
{ name = "Poetry Contributors", email = "[email protected]" }
]
license = { text = "MIT" }
readme = "README.md"
keywords = ["packaging", "dependency", "poetry"]
requires-python = ">=3.4"
Empty file.

0 comments on commit e9e227d

Please sign in to comment.