Skip to content

Commit 74ed822

Browse files
committed
move away from bild_backend to more stable build_backend and add tests
1 parent 4c165b0 commit 74ed822

2 files changed

Lines changed: 65 additions & 5 deletions

File tree

plux/build/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PluxConfiguration:
5959
entrypoint_static_file: str = "plux.ini"
6060
"""The name of the entrypoint ini file if entrypoint_build_mode is set to MANUAL."""
6161

62-
bild_backend: BuildBackend = BuildBackend.AUTO
62+
build_backend: BuildBackend = BuildBackend.AUTO
6363
"""The build backend to use. If set to ``auto``, the build backend will be detected automatically from the config."""
6464

6565
def merge(
@@ -69,7 +69,7 @@ def merge(
6969
include: list[str] = None,
7070
entrypoint_build_mode: EntrypointBuildMode = None,
7171
entrypoint_static_file: str = None,
72-
bild_backend: BuildBackend = None,
72+
build_backend: BuildBackend = None,
7373
) -> "PluxConfiguration":
7474
"""
7575
Merges or overwrites the given values into the current configuration and returns a new configuration object.
@@ -85,7 +85,7 @@ def merge(
8585
entrypoint_static_file=entrypoint_static_file
8686
if entrypoint_static_file is not None
8787
else self.entrypoint_static_file,
88-
bild_backend=bild_backend if bild_backend is not None else self.bild_backend,
88+
build_backend=build_backend if build_backend is not None else self.build_backend,
8989
)
9090

9191

@@ -193,9 +193,9 @@ def determine_build_backend_from_config(workdir: str) -> BuildBackend:
193193
# parse config to get build backend
194194
plux_config = read_plux_config_from_workdir(workdir)
195195

196-
if plux_config.bild_backend != BuildBackend.AUTO:
196+
if plux_config.build_backend != BuildBackend.AUTO:
197197
# first, check if the user configured one
198-
return plux_config.bild_backend
198+
return plux_config.build_backend
199199

200200
# otherwise, try to determine it from the build-backend attribute in the pyproject.toml
201201
try:

tests/build/test_config.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
import textwrap
3+
import uuid
4+
5+
import pytest
6+
7+
from plux.build.config import read_plux_config_from_workdir, BuildBackend, determine_build_backend_from_config
8+
9+
10+
@pytest.fixture
11+
def create_config_workdir(tmp_path):
12+
"""
13+
Factory fixture that creates a temporary directory with a pyproject.toml file in it using the given string.
14+
When the factory is invoked, it also changes the working directory to that temp directory.
15+
"""
16+
cur_dir = os.getcwd()
17+
18+
def _create(config: str):
19+
tmp_dir = tmp_path / f"project.{str(uuid.uuid4())[-8:]}"
20+
tmp_dir.mkdir()
21+
config_path = tmp_dir / "pyproject.toml"
22+
config_path.write_text(config)
23+
24+
os.chdir(tmp_dir)
25+
26+
return config_path
27+
28+
yield _create
29+
30+
os.chdir(cur_dir)
31+
32+
33+
@pytest.mark.parametrize("backend", ["setuptools", "hatchling"])
34+
def test_config_with_explicit_build_backend(backend, create_config_workdir):
35+
config = textwrap.dedent(f"""
36+
[tool.plux]
37+
entrypoint_build_mode = "manual"
38+
build_backend = "{backend}"
39+
""")
40+
41+
create_config_workdir(config)
42+
43+
cfg = read_plux_config_from_workdir()
44+
assert cfg.build_backend == BuildBackend(backend)
45+
46+
47+
def test_build_backend_is_read_from_config(create_config_workdir):
48+
# this test makes sure the build-system.build-backend extraction works
49+
config = textwrap.dedent("""
50+
[build-system]
51+
requires = ["hatchling", "wheel"]
52+
build-backend = "hatchling.build"
53+
""")
54+
55+
create_config_workdir(config)
56+
57+
cfg = read_plux_config_from_workdir()
58+
assert cfg.build_backend == BuildBackend.AUTO
59+
60+
assert determine_build_backend_from_config(os.getcwd()) == BuildBackend.HATCHLING

0 commit comments

Comments
 (0)