1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
|
# Comparison with empty strings okay for symmetry
from __future__ import annotations
import re
import textwrap
from pathlib import Path
import pytest
from packaging.specifiers import SpecifierSet
from packaging.version import Version
import scikit_build_core._logging
import scikit_build_core.settings.skbuild_read_settings
from scikit_build_core.settings.skbuild_model import GenerateSettings
from scikit_build_core.settings.skbuild_read_settings import SettingsReader
def test_skbuild_settings_default(tmp_path: Path):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text("", encoding="utf-8")
config_settings: dict[str, list[str] | str] = {}
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
settings = settings_reader.settings
assert list(settings_reader.unrecognized_options()) == []
assert settings.ninja.minimum_version is None
assert settings.ninja.version == SpecifierSet(">=1.5")
assert settings.ninja.make_fallback
assert settings.cmake.minimum_version is None
assert settings.cmake.version == SpecifierSet(">=3.15")
assert settings.cmake.args == []
assert settings.cmake.define == {}
assert not settings.build.verbose
assert settings.cmake.build_type == "Release"
assert settings.cmake.source_dir == Path()
assert settings.build.targets == []
assert settings.logging.level == "WARNING"
assert settings.sdist.include == []
assert settings.sdist.exclude == []
assert settings.sdist.reproducible
assert not settings.sdist.cmake
assert settings.wheel.packages is None
assert settings.wheel.py_api == ""
assert not settings.wheel.expand_macos_universal_tags
assert settings.wheel.license_files is None
assert settings.wheel.exclude == []
assert settings.wheel.build_tag == ""
assert settings.backport.find_python == Version("3.26.1")
assert settings.strict_config
assert not settings.experimental
assert settings.minimum_version is None
assert settings.build_dir == ""
assert settings.metadata == {}
assert settings.editable.mode == "redirect"
assert not settings.editable.rebuild
assert settings.editable.verbose
assert settings.build.tool_args == []
assert settings.install.components == []
assert settings.install.strip
assert settings.generate == []
assert not settings.fail
assert settings.messages.after_failure == ""
assert settings.messages.after_success == ""
def test_skbuild_settings_envvar(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
monkeypatch.setenv("SKBUILD_NINJA_VERSION", ">=1.1")
monkeypatch.setenv("SKBUILD_NINJA_MAKE_FALLBACK", "0")
monkeypatch.setenv("SKBUILD_CMAKE_VERSION", ">=3.16")
monkeypatch.setenv("SKBUILD_CMAKE_ARGS", "-DFOO=BAR;-DBAR=FOO")
monkeypatch.setenv("SKBUILD_CMAKE_DEFINE", "a=1;b=2")
monkeypatch.setenv("SKBUILD_CMAKE_BUILD_TYPE", "Debug")
monkeypatch.setenv("SKBUILD_CMAKE_SOURCE_DIR", "a/b/c")
monkeypatch.setenv("SKBUILD_LOGGING_LEVEL", "DEBUG")
monkeypatch.setenv("SKBUILD_SDIST_INCLUDE", "a;b; c")
monkeypatch.setenv("SKBUILD_SDIST_EXCLUDE", "d;e;f")
monkeypatch.setenv("SKBUILD_SDIST_REPRODUCIBLE", "OFF")
monkeypatch.setenv("SKBUILD_SDIST_CMAKE", "ON")
monkeypatch.setenv("SKBUILD_WHEEL_PACKAGES", "j; k; l")
monkeypatch.setenv("SKBUILD_WHEEL_PY_API", "cp39")
monkeypatch.setenv("SKBUILD_WHEEL_EXPAND_MACOS_UNIVERSAL_TAGS", "True")
monkeypatch.setenv("SKBUILD_WHEEL_LICENSE_FILES", "a;b;c")
monkeypatch.setenv("SKBUILD_WHEEL_EXCLUDE", "b;y;e")
monkeypatch.setenv("SKBUILD_WHEEL_BUILD_TAG", "1")
monkeypatch.setenv("SKBUILD_BACKPORT_FIND_PYTHON", "0")
monkeypatch.setenv("SKBUILD_STRICT_CONFIG", "0")
monkeypatch.setenv("SKBUILD_EXPERIMENTAL", "1")
monkeypatch.setenv("SKBUILD_MINIMUM_VERSION", "0.10")
monkeypatch.setenv("SKBUILD_BUILD_DIR", "a/b/c")
monkeypatch.setenv("SKBUILD_EDITABLE_REBUILD", "True")
monkeypatch.setenv("SKBUILD_EDITABLE_VERBOSE", "False")
monkeypatch.setenv("SKBUILD_BUILD_VERBOSE", "TRUE")
monkeypatch.setenv("SKBUILD_BUILD_TARGETS", "a;b;c")
monkeypatch.setenv("SKBUILD_BUILD_TOOL_ARGS", "a;b")
monkeypatch.setenv("SKBUILD_INSTALL_COMPONENTS", "a;b;c")
monkeypatch.setenv("SKBUILD_INSTALL_STRIP", "False")
monkeypatch.setenv("SKBUILD_FAIL", "1")
monkeypatch.setenv(
"SKBUILD_MESSAGES_AFTER_FAILURE", "This is a test failure message"
)
monkeypatch.setenv(
"SKBUILD_MESSAGES_AFTER_SUCCESS", "This is a test success message"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text("", encoding="utf-8")
config_settings: dict[str, list[str] | str] = {}
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
settings = settings_reader.settings
assert list(settings_reader.unrecognized_options()) == []
assert settings.ninja.version == SpecifierSet(">=1.1")
assert settings.cmake.version == SpecifierSet(">=3.16")
assert settings.cmake.args == ["-DFOO=BAR", "-DBAR=FOO"]
assert settings.cmake.define == {"a": "1", "b": "2"}
assert settings.cmake.build_type == "Debug"
assert settings.cmake.source_dir == Path("a/b/c")
assert not settings.ninja.make_fallback
assert settings.logging.level == "DEBUG"
assert settings.sdist.include == ["a", "b", "c"]
assert settings.sdist.exclude == ["d", "e", "f"]
assert not settings.sdist.reproducible
assert settings.sdist.cmake
assert settings.wheel.packages == ["j", "k", "l"]
assert settings.wheel.py_api == "cp39"
assert settings.wheel.expand_macos_universal_tags
assert settings.wheel.license_files == ["a", "b", "c"]
assert settings.wheel.exclude == ["b", "y", "e"]
assert settings.wheel.build_tag == "1"
assert settings.backport.find_python == Version("0")
assert not settings.strict_config
assert settings.experimental
assert settings.minimum_version == Version("0.10")
assert settings.build_dir == "a/b/c"
assert settings.metadata == {}
assert settings.editable.mode == "redirect"
assert settings.editable.rebuild
assert not settings.editable.verbose
assert settings.build.verbose
assert settings.build.targets == ["a", "b", "c"]
assert settings.build.tool_args == ["a", "b"]
assert settings.install.components == ["a", "b", "c"]
assert not settings.install.strip
assert settings.fail
assert settings.messages.after_failure == "This is a test failure message"
assert settings.messages.after_success == "This is a test success message"
@pytest.mark.parametrize("prefix", [True, False], ids=["skbuild", "noprefix"])
def test_skbuild_settings_config_settings(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, prefix: bool
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text("", encoding="utf-8")
config_settings: dict[str, str | list[str]] = {
"ninja.version": ">=1.2",
"ninja.make-fallback": "False",
"cmake.version": ">=3.17",
"cmake.args": ["-DFOO=BAR", "-DBAR=FOO"],
"cmake.define.a": "1",
"cmake.define.b": "2",
"cmake.build-type": "Debug",
"cmake.source-dir": "a/b/c",
"logging.level": "INFO",
"sdist.include": ["a", "b", "c"],
"sdist.exclude": "d;e;f",
"sdist.reproducible": "false",
"sdist.cmake": "true",
"wheel.packages": ["j", "k", "l"],
"wheel.py-api": "cp39",
"wheel.expand-macos-universal-tags": "True",
"wheel.license-files": ["a", "b", "c"],
"wheel.exclude": ["b", "y", "e"],
"wheel.build-tag": "1foo",
"backport.find-python": "0",
"strict-config": "false",
"experimental": "1",
"minimum-version": "0.10",
"build-dir": "a/b/c",
"editable.mode": "redirect",
"editable.rebuild": "True",
"editable.verbose": "False",
"build.verbose": "true",
"build.targets": ["a", "b", "c"],
"build.tool-args": ["a", "b"],
"install.components": ["a", "b", "c"],
"install.strip": "True",
"fail": "1",
"messages.after-failure": "This is a test failure message",
"messages.after-success": "This is a test success message",
}
if prefix:
config_settings = {f"skbuild.{k}": v for k, v in config_settings.items()}
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
settings = settings_reader.settings
assert list(settings_reader.unrecognized_options()) == []
assert settings.ninja.version == SpecifierSet(">=1.2")
assert not settings.ninja.make_fallback
assert settings.cmake.version == SpecifierSet(">=3.17")
assert settings.cmake.args == ["-DFOO=BAR", "-DBAR=FOO"]
assert settings.cmake.define == {"a": "1", "b": "2"}
assert settings.build.verbose
assert settings.cmake.build_type == "Debug"
assert settings.cmake.source_dir == Path("a/b/c")
assert settings.logging.level == "INFO"
assert settings.sdist.include == ["a", "b", "c"]
assert settings.sdist.exclude == ["d", "e", "f"]
assert not settings.sdist.reproducible
assert settings.sdist.cmake
assert settings.wheel.packages == ["j", "k", "l"]
assert settings.wheel.py_api == "cp39"
assert settings.wheel.expand_macos_universal_tags
assert settings.wheel.license_files == ["a", "b", "c"]
assert settings.wheel.exclude == ["b", "y", "e"]
assert settings.wheel.build_tag == "1foo"
assert settings.backport.find_python == Version("0")
assert not settings.strict_config
assert settings.experimental
assert settings.minimum_version == Version("0.10")
assert settings.build_dir == "a/b/c"
assert settings.metadata == {}
assert settings.editable.mode == "redirect"
assert settings.editable.rebuild
assert not settings.editable.verbose
assert settings.build.targets == ["a", "b", "c"]
assert settings.build.tool_args == ["a", "b"]
assert settings.install.components == ["a", "b", "c"]
assert settings.install.strip
assert settings.fail
assert settings.messages.after_failure == "This is a test failure message"
assert settings.messages.after_success == "This is a test success message"
def test_skbuild_settings_pyproject_toml(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
ninja.version = ">=1.3"
ninja.make-fallback = false
cmake.version = ">=3.18"
cmake.args = ["-DFOO=BAR", "-DBAR=FOO"]
cmake.define = {a = "1", b = "2"}
cmake.build-type = "Debug"
cmake.source-dir = "a/b/c"
logging.level = "ERROR"
sdist.include = ["a", "b", "c"]
sdist.exclude = ["d", "e", "f"]
sdist.reproducible = false
sdist.cmake = true
wheel.packages = ["j", "k", "l"]
wheel.py-api = "cp39"
wheel.expand-macos-universal-tags = true
wheel.license-files = ["a", "b", "c"]
wheel.exclude = ["b", "y", "e"]
wheel.build-tag = "1_bar"
backport.find-python = "3.18"
strict-config = false
experimental = true
minimum-version = "0.10"
build-dir = "a/b/c"
metadata.version.provider = "a"
editable.mode = "redirect"
editable.rebuild = true
editable.verbose = false
build.verbose = true
build.targets = ["a", "b", "c"]
build.tool-args = ["a", "b"]
install.components = ["a", "b", "c"]
install.strip = true
fail = true
messages.after-failure = "This is a test failure message"
messages.after-success = "This is a test success message"
[[tool.scikit-build.generate]]
path = "a/b/c"
template = "hello"
[[tool.scikit-build.generate]]
path = "d/e/f"
template-path = "g/h/i"
location = "build"
"""
),
encoding="utf-8",
)
config_settings: dict[str, list[str] | str] = {}
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
settings = settings_reader.settings
assert list(settings_reader.unrecognized_options()) == []
assert settings.ninja.version == SpecifierSet(">=1.3")
assert not settings.ninja.make_fallback
assert settings.cmake.version == SpecifierSet(">=3.18")
assert settings.cmake.args == ["-DFOO=BAR", "-DBAR=FOO"]
assert settings.cmake.define == {"a": "1", "b": "2"}
assert settings.cmake.build_type == "Debug"
assert settings.cmake.source_dir == Path("a/b/c")
assert settings.logging.level == "ERROR"
assert settings.sdist.include == ["a", "b", "c"]
assert settings.sdist.exclude == ["d", "e", "f"]
assert not settings.sdist.reproducible
assert settings.sdist.cmake
assert settings.wheel.packages == ["j", "k", "l"]
assert settings.wheel.py_api == "cp39"
assert settings.wheel.expand_macos_universal_tags
assert settings.wheel.license_files == ["a", "b", "c"]
assert settings.wheel.exclude == ["b", "y", "e"]
assert settings.wheel.build_tag == "1_bar"
assert settings.backport.find_python == Version("3.18")
assert not settings.strict_config
assert settings.experimental
assert settings.minimum_version == Version("0.10")
assert settings.build_dir == "a/b/c"
assert settings.metadata == {"version": {"provider": "a"}}
assert settings.editable.mode == "redirect"
assert settings.editable.rebuild
assert not settings.editable.verbose
assert settings.build.verbose
assert settings.build.targets == ["a", "b", "c"]
assert settings.build.tool_args == ["a", "b"]
assert settings.install.components == ["a", "b", "c"]
assert settings.install.strip
assert settings.generate == [
GenerateSettings(path=Path("a/b/c"), template="hello", location="install"),
GenerateSettings(
path=Path("d/e/f"), template_path=Path("g/h/i"), location="build"
),
]
assert settings.fail
assert settings.messages.after_failure == "This is a test failure message"
assert settings.messages.after_success == "This is a test success message"
def test_skbuild_settings_pyproject_toml_broken(
tmp_path: Path, capsys: pytest.CaptureFixture[str], monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.9.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
minimum-version = "0.9"
cmake.verison = ">=3.18"
ninja.version = ">=1.3"
ninja.make-fallback = false
logger.level = "ERROR"
"""
),
encoding="utf-8",
)
config_settings: dict[str, list[str] | str] = {}
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
assert list(settings_reader.unrecognized_options()) == [
"tool.scikit-build.cmake.verison",
"tool.scikit-build.logger",
]
with pytest.raises(SystemExit):
settings_reader.validate_may_exit()
ex = capsys.readouterr().out
ex = re.sub(r"\x1b(\[.*?[@-~]|\].*?(\x07|\x1b\\))", "", ex)
assert ex.split() == [
"ERROR:",
"Unrecognized",
"options",
"in",
"pyproject.toml:",
"tool.scikit-build.cmake.verison",
"->",
"Did",
"you",
"mean:",
"tool.scikit-build.cmake.version,",
"tool.scikit-build.cmake.verbose,",
"tool.scikit-build.cmake.define?",
"tool.scikit-build.logger",
"->",
"Did",
"you",
"mean:",
"tool.scikit-build.logging,",
"tool.scikit-build.generate,",
"tool.scikit-build.search?",
]
def test_skbuild_settings_pyproject_conf_broken(
tmp_path: Path, capsys: pytest.CaptureFixture[str], monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.9.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
"tool.scikit-build.minimum-version = '0.9'", encoding="utf-8"
)
config_settings: dict[str, str | list[str]] = {
"cmake.verison": ">=3.17",
"ninja.version": ">=1.2",
"ninja.make-fallback": "False",
"logger.level": "INFO",
}
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
assert list(settings_reader.unrecognized_options()) == [
"cmake.verison",
"logger",
]
with pytest.raises(SystemExit):
settings_reader.validate_may_exit()
ex = capsys.readouterr().out
# Filter terminal color codes
ex = re.sub(r"\x1b(\[.*?[@-~]|\].*?(\x07|\x1b\\))", "", ex)
assert ex.split() == [
"ERROR:",
"Unrecognized",
"options",
"in",
"config-settings:",
"cmake.verison",
"->",
"Did",
"you",
"mean:",
"cmake.version,",
"cmake.verbose,",
"cmake.define?",
"logger",
"->",
"Did",
"you",
"mean:",
"logging?",
]
def test_skbuild_settings_min_version_defaults_strip(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.5.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text("", encoding="utf-8")
settings_reader = SettingsReader.from_file(
pyproject_toml, {"minimum-version": "0.4"}
)
settings = settings_reader.settings
assert not settings.install.strip
settings_reader = SettingsReader.from_file(
pyproject_toml, {"minimum-version": "0.5"}
)
settings = settings_reader.settings
assert settings.install.strip
def test_skbuild_settings_min_version_versions(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
"tool.scikit-build.cmake.minimum-version = '3.21'", encoding="utf-8"
)
cmakelists = tmp_path / "CMakeLists.txt"
cmakelists.write_text("cmake_minimum_required(VERSION 3.20)", encoding="utf-8")
settings_reader = SettingsReader.from_file(pyproject_toml, {})
settings = settings_reader.settings
assert settings.cmake.version == SpecifierSet(">=3.21")
settings_reader = SettingsReader.from_file(
pyproject_toml, {"minimum-version": "0.7"}
)
settings = settings_reader.settings
assert settings.cmake.version == SpecifierSet(">=3.21")
with pytest.raises(SystemExit):
SettingsReader.from_file(pyproject_toml, {"minimum-version": "0.8"})
def test_skbuild_settings_version_too_old(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.8.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
"tool.scikit-build.cmake.version = '>=3.21'", encoding="utf-8"
)
SettingsReader.from_file(pyproject_toml)
with pytest.raises(SystemExit):
SettingsReader.from_file(pyproject_toml, {"minimum-version": "0.7"})
def test_skbuild_settings_pyproject_toml_envvar_defines(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build.cmake.define]
a = "1"
b = {env = "SIMPLE"}
c = {env = "DEFAULT", default="empty"}
d = false
e = {env = "BOOL", default = false}
f = {env = "NOTSET"}
"""
),
encoding="utf-8",
)
config_settings: dict[str, list[str] | str] = {}
monkeypatch.setenv("SIMPLE", "2")
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
assert settings_reader.settings.cmake.define == {
"a": "1",
"b": "2",
"c": "empty",
"d": "FALSE",
"e": "FALSE",
}
monkeypatch.setenv("DEFAULT", "3")
monkeypatch.setenv("BOOL", "ON")
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
assert settings_reader.settings.cmake.define == {
"a": "1",
"b": "2",
"c": "3",
"d": "FALSE",
"e": "TRUE",
}
def test_backcompat_cmake_build(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
minimum-version = "0.9"
cmake.verbose = true
cmake.targets = ["a", "b"]
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml, {})
assert settings_reader.settings.build.verbose
assert settings_reader.settings.build.targets == ["a", "b"]
def test_backcompat_cmake_build_env(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.9.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
minimum-version = "0.9"
"""
),
encoding="utf-8",
)
monkeypatch.setenv("SKBUILD_CMAKE_VERBOSE", "ON")
monkeypatch.setenv("SKBUILD_CMAKE_TARGETS", "a;b")
settings_reader = SettingsReader.from_file(pyproject_toml, {})
assert settings_reader.settings.build.verbose
assert settings_reader.settings.build.targets == ["a", "b"]
def test_auto_minimum_version(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[build-system]
requires = ["scikit-build-core>=0.8"]
[tool.scikit-build]
minimum-version = "build-system.requires"
"""
),
encoding="utf-8",
)
reader = SettingsReader.from_file(pyproject_toml, {})
assert reader.settings.minimum_version == Version("0.8")
def test_auto_cmake_version(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[build-system]
requires = ["scikit-build-core>=0.8"]
[tool.scikit-build]
cmake.version = "CMakeLists.txt"
"""
),
encoding="utf-8",
)
cmakelists_txt = tmp_path / "CMakeLists.txt"
cmakelists_txt.write_text(
textwrap.dedent(
"""\
cmake_minimum_required(VERSION 3.21)
"""
),
encoding="utf-8",
)
monkeypatch.chdir(tmp_path)
reader = SettingsReader.from_file(pyproject_toml, {})
assert reader.settings.cmake.version == SpecifierSet(">=3.21")
@pytest.mark.parametrize("version", ["0.9", "0.10"])
def test_default_auto_cmake_version(
version: str, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
f"""\
[build-system]
requires = ["scikit-build-core>={version}"]
[tool.scikit-build]
minimum-version = "build-system.requires"
"""
),
encoding="utf-8",
)
cmakelists_txt = tmp_path / "CMakeLists.txt"
cmakelists_txt.write_text(
textwrap.dedent(
"""\
cmake_minimum_required(VERSION 3.21)
"""
),
encoding="utf-8",
)
monkeypatch.chdir(tmp_path)
reader = SettingsReader.from_file(pyproject_toml, {})
assert reader.settings.cmake.version == SpecifierSet(
">=3.21" if version == "0.10" else ">=3.15"
)
def test_skbuild_settings_auto_cmake_warning(
tmp_path: Path, capsys: pytest.CaptureFixture[str], monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
scikit_build_core._logging.rich_warning.cache_clear()
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
minimum-version = "0.10"
"""
),
encoding="utf-8",
)
cmakelists_txt = tmp_path / "CMakeLists.txt"
cmakelists_txt.write_text(
textwrap.dedent(
"""\
cmake_minimum_required(VERSION 3.14)
"""
),
encoding="utf-8",
)
config_settings: dict[str, list[str] | str] = {}
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
assert settings_reader.settings.cmake.version == SpecifierSet(">=3.15")
ex = capsys.readouterr().err
ex = re.sub(r"\x1b(\[.*?[@-~]|\].*?(\x07|\x1b\\))", "", ex)
print(ex)
assert ex.split() == [
"WARNING:",
"CMakeLists.txt",
"not",
"found",
"when",
"looking",
"for",
"minimum",
"CMake",
"version.",
"Report",
"this",
"or",
"(and)",
"set",
"manually",
"to",
"avoid",
"this",
"warning.",
"Using",
"3.15",
"as",
"a",
"fall-back.",
]
def test_skbuild_settings_cmake_define_list():
pyproject_toml = (
Path(__file__).parent / "packages" / "cmake_defines" / "pyproject.toml"
)
config_settings: dict[str, list[str] | str] = {}
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
settings = settings_reader.settings
assert settings.cmake.define == {
"NESTED_LIST": r"Apple;Lemon\;Lime;Banana",
"ONE_LEVEL_LIST": "Foo;Bar;ExceptionallyLargeListEntryThatWouldOverflowTheLine;Baz",
}
def test_skbuild_override_renamed(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
minimum-version = "0.7"
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml, {"build.verbose": "1"})
assert settings_reader.settings.build.verbose
settings_reader = SettingsReader.from_file(
pyproject_toml, env={"SKBUILD_BUILD_VERBOSE": "TRUE"}
)
assert settings_reader.settings.build.verbose
def test_skbuild_override_renamed_fail(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
minimum-version = "0.7"
build.verbose = true
"""
),
encoding="utf-8",
)
with pytest.raises(SystemExit):
SettingsReader.from_file(pyproject_toml)
def test_skbuild_override_static(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
minimum-version = "0.7"
build.verbose = true
"""
),
encoding="utf-8",
)
with pytest.raises(SystemExit):
SettingsReader.from_file(pyproject_toml)
def test_backcompat_cmake_build_both_specified(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
cmake.verbose = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml, {"build.verbose": "1"})
assert settings_reader.settings.build.verbose
def test_backcompat_cmake_build_both_specified_static(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
build.verbose = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml, {"cmake.verbose": "1"})
assert settings_reader.settings.build.verbose
def test_backcompat_cmake_build_targets_both_specified(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
textwrap.dedent(
"""\
[tool.scikit-build]
cmake.targets = ["a", "b"]
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml, {"build.targets": "c;d"})
assert settings_reader.settings.build.targets == ["c", "d"]
|