|
8 | 8 | import types
|
9 | 9 | import zipfile
|
10 | 10 | from pathlib import Path
|
11 |
| -from typing import Any |
| 11 | +from typing import TYPE_CHECKING, Any |
12 | 12 |
|
13 | 13 | import pytest
|
14 | 14 | from packaging.version import Version
|
|
23 | 23 |
|
24 | 24 | from pathutils import contained
|
25 | 25 |
|
| 26 | +if TYPE_CHECKING: |
| 27 | + from scikit_build_core._compat.typing import Literal |
| 28 | + |
26 | 29 |
|
27 | 30 | # these are mock plugins returning known results
|
28 | 31 | # it turns out to be easier to create EntryPoint objects pointing to real
|
@@ -347,3 +350,38 @@ def test_regex_remove(
|
347 | 350 | )
|
348 | 351 |
|
349 | 352 | assert version == ("1.2.3dev1" if dev else "1.2.3")
|
| 353 | + |
| 354 | + |
| 355 | +@pytest.mark.usefixtures("package_dynamic_metadata") |
| 356 | +@pytest.mark.parametrize("override", [None, "env", "sdist"]) |
| 357 | +def test_build_requires_field(override, monkeypatch) -> None: |
| 358 | + shutil.copy("build_requires_project.toml", "pyproject.toml") |
| 359 | + |
| 360 | + if override == "env": |
| 361 | + monkeypatch.setenv("LOCAL_FOO", "True") |
| 362 | + else: |
| 363 | + monkeypatch.delenv("LOCAL_FOO", raising=False) |
| 364 | + |
| 365 | + with Path("pyproject.toml").open("rb") as ft: |
| 366 | + pyproject = tomllib.load(ft) |
| 367 | + state: Literal["sdist", "metadata_wheel"] = ( |
| 368 | + "sdist" if override == "sdist" else "metadata_wheel" |
| 369 | + ) |
| 370 | + settings_reader = SettingsReader(pyproject, {}, state=state) |
| 371 | + |
| 372 | + settings_reader.validate_may_exit() |
| 373 | + |
| 374 | + if override is None: |
| 375 | + assert set(GetRequires().dynamic_metadata()) == { |
| 376 | + "foo", |
| 377 | + } |
| 378 | + elif override == "env": |
| 379 | + assert set(GetRequires().dynamic_metadata()) == { |
| 380 | + # TODO: This should be resolved to actual path |
| 381 | + "foo @ {root:uri}/foo", |
| 382 | + } |
| 383 | + elif override =="sdist": |
| 384 | + assert set(GetRequires().dynamic_metadata()) == { |
| 385 | + # TODO: Check if special handling should be done for sdist |
| 386 | + "foo", |
| 387 | + } |
0 commit comments