|
| 1 | +from scikit_build_core.builder._load_provider import process_dynamic_metadata |
| 2 | + |
| 3 | + |
| 4 | +def test_template_basic() -> None: |
| 5 | + pyproject = process_dynamic_metadata( |
| 6 | + { |
| 7 | + "name": "test", |
| 8 | + "version": "0.1.0", |
| 9 | + "dynamic": ["requires-python"], |
| 10 | + }, |
| 11 | + { |
| 12 | + "requires-python": { |
| 13 | + "provider": "scikit_build_core.metadata.template", |
| 14 | + "result": ">={project[version]}", |
| 15 | + }, |
| 16 | + }, |
| 17 | + ) |
| 18 | + |
| 19 | + assert pyproject["requires-python"] == ">=0.1.0" |
| 20 | + |
| 21 | + |
| 22 | +def test_template_needs() -> None: |
| 23 | + # These are intentionally out of order to test the order of processing |
| 24 | + pyproject = process_dynamic_metadata( |
| 25 | + { |
| 26 | + "name": "test", |
| 27 | + "version": "0.1.0", |
| 28 | + "dynamic": ["requires-python", "license", "readme"], |
| 29 | + }, |
| 30 | + { |
| 31 | + "license": { |
| 32 | + "provider": "scikit_build_core.metadata.template", |
| 33 | + "result": "{project[requires-python]}", |
| 34 | + }, |
| 35 | + "readme": { |
| 36 | + "provider": "scikit_build_core.metadata.template", |
| 37 | + "result": {"file": "{project[license]}"}, |
| 38 | + }, |
| 39 | + "requires-python": { |
| 40 | + "provider": "scikit_build_core.metadata.template", |
| 41 | + "result": ">={project[version]}", |
| 42 | + }, |
| 43 | + }, |
| 44 | + ) |
| 45 | + |
| 46 | + assert pyproject["requires-python"] == ">=0.1.0" |
| 47 | + |
| 48 | + |
| 49 | +def test_regex() -> None: |
| 50 | + pyproject = process_dynamic_metadata( |
| 51 | + { |
| 52 | + "name": "test", |
| 53 | + "version": "0.1.0", |
| 54 | + "dynamic": ["requires-python"], |
| 55 | + }, |
| 56 | + { |
| 57 | + "requires-python": { |
| 58 | + "provider": "scikit_build_core.metadata.regex", |
| 59 | + "input": "pyproject.toml", |
| 60 | + "regex": r"name = \"(?P<name>.+)\"", |
| 61 | + "result": ">={name}", |
| 62 | + }, |
| 63 | + }, |
| 64 | + ) |
| 65 | + |
| 66 | + assert pyproject["requires-python"] == ">=scikit_build_core" |
0 commit comments