-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathtest_settings_overrides.py
855 lines (721 loc) · 25.6 KB
/
test_settings_overrides.py
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
from __future__ import annotations
import sysconfig
import typing
from pathlib import Path
from textwrap import dedent
import pytest
import scikit_build_core.settings.skbuild_overrides
from scikit_build_core.settings.skbuild_overrides import regex_match
from scikit_build_core.settings.skbuild_read_settings import SettingsReader
if typing.TYPE_CHECKING:
from pytest_subprocess import FakeProcess
class VersionInfo(typing.NamedTuple):
major: int
minor: int
micro: int
releaselevel: str = "final"
@pytest.mark.parametrize("python_version", ["3.9", "3.10"])
def test_skbuild_overrides_pyver(
python_version: str, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr("sys.version_info", (*map(int, python_version.split(".")), 0))
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if = {python-version = ">=3.10"}
cmake.args = ["-DFOO=BAR"]
experimental = true
cmake.define.SPAM = "EGGS"
sdist.cmake = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if python_version == "3.10":
assert settings.cmake.args == ["-DFOO=BAR"]
assert settings.cmake.define == {"SPAM": "EGGS"}
assert settings.experimental
assert settings.sdist.cmake
else:
assert not settings.cmake.args
assert not settings.cmake.define
assert not settings.experimental
@pytest.mark.parametrize("implementation_version", ["7.3.14", "7.3.15"])
def test_skbuild_overrides_implver(
implementation_version: str, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr("sys.implementation.name", "pypy")
monkeypatch.setattr(
"sys.implementation.version",
VersionInfo(*(int(x) for x in implementation_version.split("."))), # type: ignore[arg-type]
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.implementation-name = "pypy"
if.implementation-version = ">=7.3.15"
experimental = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if implementation_version == "7.3.15":
assert settings.experimental
else:
assert not settings.experimental
@pytest.mark.parametrize("implementation_name", ["cpython", "pypy"])
@pytest.mark.parametrize("platform_system", ["darwin", "linux"])
def test_skbuild_overrides_dual(
implementation_name: str,
platform_system: str,
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
):
monkeypatch.setattr(
"sys.implementation", type("Mock", (), {"name": implementation_name})
)
monkeypatch.setattr("sys.platform", platform_system)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if = {implementation-name = "pypy", platform-system = "darwin"}
editable.verbose = false
install.components = ["headers"]
[[tool.scikit-build.overrides]]
if.implementation-name = "cpython"
if.platform-system = "darwin"
install.components = ["bindings"]
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
print(settings_reader.overrides)
if implementation_name == "pypy" and platform_system == "darwin":
assert not settings.editable.verbose
assert settings.install.components == ["headers"]
elif implementation_name == "cpython" and platform_system == "darwin":
assert settings.editable.verbose
assert settings.install.components == ["bindings"]
else:
assert settings.editable.verbose
assert not settings.install.components
@pytest.mark.parametrize("implementation_name", ["cpython", "pypy"])
@pytest.mark.parametrize("platform_system", ["darwin", "linux"])
def test_skbuild_overrides_any(
implementation_name: str,
platform_system: str,
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
):
monkeypatch.setattr(
"sys.implementation", type("Mock", (), {"name": implementation_name})
)
monkeypatch.setattr("sys.platform", platform_system)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.any = {implementation-name = "pypy", platform-system = "darwin"}
editable.verbose = false
install.components = ["headers"]
[[tool.scikit-build.overrides]]
if.any.implementation-name = "cpython"
if.any.platform-system = "darwin"
install.components = ["bindings"]
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if implementation_name == "cpython" or platform_system == "darwin":
assert settings.editable.verbose == (
platform_system == "linux" and implementation_name == "cpython"
)
assert settings.install.components == ["bindings"]
elif implementation_name == "pypy" or platform_system == "darwin":
assert not settings.editable.verbose
assert settings.install.components == ["headers"]
else:
assert settings.editable.verbose
assert not settings.install.components
@pytest.mark.parametrize("python_version", ["3.9", "3.10"])
@pytest.mark.parametrize("implementation_name", ["cpython", "pypy"])
@pytest.mark.parametrize("platform_system", ["darwin", "linux"])
def test_skbuild_overrides_any_mixed(
implementation_name: str,
platform_system: str,
python_version: str,
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
):
monkeypatch.setattr(
"sys.implementation", type("Mock", (), {"name": implementation_name})
)
monkeypatch.setattr("sys.platform", platform_system)
monkeypatch.setattr("sys.version_info", (*map(int, python_version.split(".")), 0))
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.any = {implementation-name = "pypy", platform-system = "darwin"}
if.python-version = ">=3.10"
editable.verbose = false
install.components = ["headers"]
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if python_version == "3.10" and (
implementation_name == "pypy" or platform_system == "darwin"
):
assert not settings.editable.verbose
assert settings.install.components == ["headers"]
else:
assert settings.editable.verbose
assert not settings.install.components
@pytest.mark.parametrize("platform_node", ["thismatch", "matchthat"])
def test_skbuild_overrides_platnode(
platform_node: str, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr("platform.node", lambda: platform_node)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.platform-node = "^match"
experimental = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if platform_node == "matchthat":
assert settings.experimental
else:
assert not settings.experimental
@pytest.mark.parametrize("platform_machine", ["x86_64", "x86_32", "other"])
def test_skbuild_overrides_regex(
platform_machine: str,
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
):
monkeypatch.setattr("platform.machine", lambda: platform_machine)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[tool.scikit-build]
install.components = ["default"]
[[tool.scikit-build.overrides]]
if = {platform_machine = "x86_.*"}
install.components = ["headers"]
[[tool.scikit-build.overrides]]
if = {platform_machine = "x86_32"}
install.components = ["headers_32"]
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if platform_machine == "x86_64":
assert settings.install.components == ["headers"]
elif platform_machine == "x86_32":
assert settings.install.components == ["headers_32"]
else:
assert settings.install.components == ["default"]
def test_skbuild_overrides_no_if(
tmp_path: Path,
):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
minimum-version="0.1"
"""
),
encoding="utf-8",
)
with pytest.raises(KeyError, match="At least one 'if' override must be provided"):
SettingsReader.from_file(pyproject_toml)
def test_skbuild_overrides_empty_if(
tmp_path: Path,
):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if = {}
minimum-version="0.1"
"""
),
encoding="utf-8",
)
with pytest.raises(KeyError, match="At least one 'if' override must be provided"):
SettingsReader.from_file(pyproject_toml)
def test_skbuild_overrides_invalid_key(
tmp_path: Path,
):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if = {python_version = ">=3"}
invalid-key = "Hi"
"""
),
encoding="utf-8",
)
settings = SettingsReader.from_file(pyproject_toml)
with pytest.raises(SystemExit):
settings.validate_may_exit()
@pytest.mark.parametrize("regex", ["is", "this", "^this", "string$"])
def test_regex_match(regex: str):
assert regex_match("this_is_a_string", regex)
@pytest.mark.parametrize("regex", ["^string", "this$", "other"])
def test_not_regex_match(regex: str):
assert not regex_match("this_is_a_string", regex)
@pytest.mark.parametrize("envvar", ["BAR", "", None])
def test_skbuild_env(
envvar: str | None, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
if envvar is None:
monkeypatch.delenv("FOO", raising=False)
else:
monkeypatch.setenv("FOO", envvar)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.env.FOO = "BAR"
sdist.cmake = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if envvar == "BAR":
assert settings.sdist.cmake
else:
assert not settings.sdist.cmake
@pytest.mark.parametrize("envvar", ["tRUE", "3", "0", "", None])
def test_skbuild_env_bool(
envvar: str | None, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
if envvar is None:
monkeypatch.delenv("FOO", raising=False)
else:
monkeypatch.setenv("FOO", envvar)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.env.FOO = true
sdist.cmake = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if envvar in {"tRUE", "3"}:
assert settings.sdist.cmake
else:
assert not settings.sdist.cmake
@pytest.mark.parametrize("foo", ["true", "false"])
@pytest.mark.parametrize("bar", ["true", "false"])
@pytest.mark.parametrize("any", [True, False])
def test_skbuild_env_bool_all_any(
foo: str, bar: str, any: bool, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setenv("FOO", foo)
monkeypatch.setenv("BAR", bar)
any_str = ".any" if any else ""
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
f"""\
[[tool.scikit-build.overrides]]
if{any_str}.env.FOO = true
if{any_str}.env.BAR = true
sdist.cmake = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml)
settings = settings_reader.settings
if (foo == "true" and bar == "true") or (any and (foo == "true" or bar == "true")):
assert settings.sdist.cmake
else:
assert not settings.sdist.cmake
@pytest.mark.parametrize("state", ["wheel", "sdist"])
def test_skbuild_overrides_state(state: str, tmp_path: Path):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
f"""\
[[tool.scikit-build.overrides]]
if.state = "{state}"
experimental = true
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml, state="wheel")
settings = settings_reader.settings
if state == "wheel":
assert settings.experimental
else:
assert not settings.experimental
@pytest.mark.parametrize("inherit", ["none", "append", "prepend"])
def test_skbuild_overrides_inherit(inherit: str, tmp_path: Path):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
f"""\
[tool.scikit-build]
cmake.args = ["a", "b"]
cmake.targets = ["a", "b"]
wheel.packages = ["a", "b"]
wheel.license-files = ["a.txt", "b.txt"]
wheel.exclude = ["x", "y"]
install.components = ["a", "b"]
cmake.define = {{a="A", b="B"}}
[[tool.scikit-build.overrides]]
if.state = "wheel"
inherit.cmake.args = "{inherit}"
inherit.cmake.targets = "{inherit}"
inherit.wheel.packages = "{inherit}"
inherit.wheel.license-files = "{inherit}"
inherit.wheel.exclude = "{inherit}"
inherit.install.components = "{inherit}"
inherit.cmake.define = "{inherit}"
cmake.args = ["c", "d"]
cmake.targets = ["c", "d"]
wheel.packages = ["c", "d"]
wheel.license-files = ["c.txt", "d.txt"]
wheel.exclude = ["xx", "yy"]
install.components = ["c", "d"]
cmake.define = {{b="X", c="C"}}
"""
),
encoding="utf-8",
)
settings_reader = SettingsReader.from_file(pyproject_toml, state="wheel")
settings = settings_reader.settings
if inherit == "none":
assert settings.cmake.args == ["c", "d"]
assert settings.cmake.targets == ["c", "d"]
assert settings.wheel.packages == ["c", "d"]
assert settings.wheel.license_files == ["c.txt", "d.txt"]
assert settings.wheel.exclude == ["xx", "yy"]
assert settings.install.components == ["c", "d"]
assert settings.cmake.define == {"b": "X", "c": "C"}
elif inherit == "append":
assert settings.cmake.args == ["a", "b", "c", "d"]
assert settings.cmake.targets == ["a", "b", "c", "d"]
assert settings.wheel.packages == ["a", "b", "c", "d"]
assert settings.wheel.license_files == ["a.txt", "b.txt", "c.txt", "d.txt"]
assert settings.wheel.exclude == ["x", "y", "xx", "yy"]
assert settings.install.components == ["a", "b", "c", "d"]
assert settings.cmake.define == {"a": "A", "b": "X", "c": "C"}
elif inherit == "prepend":
assert settings.cmake.args == ["c", "d", "a", "b"]
assert settings.cmake.targets == ["c", "d", "a", "b"]
assert settings.wheel.packages == ["c", "d", "a", "b"]
assert settings.wheel.license_files == ["c.txt", "d.txt", "a.txt", "b.txt"]
assert settings.wheel.exclude == ["xx", "yy", "x", "y"]
assert settings.install.components == ["c", "d", "a", "b"]
assert settings.cmake.define == {"a": "A", "b": "B", "c": "C"}
@pytest.mark.parametrize("from_sdist", [True, False])
def test_skbuild_overrides_from_sdist(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, from_sdist: bool
):
pyproject_toml = (
tmp_path / ("from_sdist" if from_sdist else "not_from_sdist") / "pyproject.toml"
)
pyproject_toml.parent.mkdir(exist_ok=True)
pyproject_toml.write_text(
dedent(
"""\
[tool.scikit-build]
cmake.version = ">=3.15"
wheel.cmake = false
sdist.cmake = false
[[tool.scikit-build.overrides]]
if.from-sdist = false
wheel.cmake = true
[[tool.scikit-build.overrides]]
if.from-sdist = true
sdist.cmake = true
"""
),
encoding="utf-8",
)
if from_sdist:
pyproject_toml.parent.joinpath("PKG-INFO").touch(exist_ok=True)
monkeypatch.chdir(pyproject_toml.parent)
settings_reader = SettingsReader.from_file(pyproject_toml, state="wheel")
settings = settings_reader.settings
assert settings.wheel.cmake != from_sdist
assert settings.sdist.cmake == from_sdist
def test_failed_retry(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[tool.scikit-build]
wheel.cmake = false
sdist.cmake = false
[[tool.scikit-build.overrides]]
if.failed = true
wheel.cmake = true
[[tool.scikit-build.overrides]]
if.failed = false
sdist.cmake = true
"""
),
encoding="utf-8",
)
monkeypatch.chdir(tmp_path)
settings_reader = SettingsReader.from_file(pyproject_toml, retry=False)
settings = settings_reader.settings
assert not settings.wheel.cmake
assert settings.sdist.cmake
settings_reader = SettingsReader.from_file(pyproject_toml, retry=True)
settings = settings_reader.settings
assert settings.wheel.cmake
assert not settings.sdist.cmake
@pytest.mark.parametrize("sys_tag", ["win32", "linux"])
def test_wheel_platform(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, sys_tag: str):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[tool.scikit-build]
wheel.cmake = false
[[tool.scikit-build.overrides]]
if.cmake-wheel = true
wheel.cmake = true
"""
),
encoding="utf-8",
)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr("packaging.tags.sys_tags", lambda: [sys_tag])
settings_reader = SettingsReader.from_file(pyproject_toml, retry=False)
settings = settings_reader.settings
assert settings.wheel.cmake == (sys_tag == "win32")
@pytest.mark.parametrize("cmake_version", ["3.21", "3.27"])
@pytest.mark.usefixtures("protect_get_requires")
def test_system_cmake(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
cmake_version: str | None,
fp: FakeProcess,
) -> None:
if cmake_version:
fp.register(
[Path("cmake/path"), "-E", "capabilities"],
stdout=f'{{"version":{{"string": "{cmake_version}"}}}}',
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[tool.scikit-build]
wheel.cmake = false
[[tool.scikit-build.overrides]]
if.system-cmake = ">=3.24"
wheel.cmake = true
"""
),
encoding="utf-8",
)
monkeypatch.chdir(tmp_path)
settings_reader = SettingsReader.from_file(pyproject_toml, retry=False)
settings = settings_reader.settings
assert settings.wheel.cmake == (cmake_version == "3.27")
def test_free_threaded_override(tmp_path: Path):
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[tool.scikit-build]
wheel.cmake = false
[[tool.scikit-build.overrides]]
if.abi-flags = "t"
wheel.cmake = true
"""
)
)
settings_reader = SettingsReader.from_file(pyproject_toml, state="wheel")
settings = settings_reader.settings
assert settings.wheel.cmake == bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
@pytest.mark.parametrize("version", ["0.9", "0.10"])
def test_skbuild_overrides_version(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, version: str
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_overrides, "__version__", version
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[tool.scikit-build]
wheel.cmake = false
[[tool.scikit-build.overrides]]
if.scikit-build-version = ">=0.10"
wheel.cmake = true
"""
)
)
settings_reader = SettingsReader.from_file(pyproject_toml, state="wheel")
settings = settings_reader.settings
if version == "0.10":
assert settings.wheel.cmake
else:
assert not settings.wheel.cmake
def test_skbuild_overrides_unmatched_version(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_overrides, "__version__", "0.10"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.scikit-build-version = "<0.10"
if.is-not-real = true
also-not-real = true
"""
)
)
settings = SettingsReader.from_file(pyproject_toml)
settings.validate_may_exit()
def test_skbuild_overrides_matched_version_if(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_overrides, "__version__", "0.10"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.scikit-build-version = ">=0.10"
if.is-not-real = true
"""
)
)
with pytest.raises(TypeError, match="is_not_real"):
SettingsReader.from_file(pyproject_toml)
def test_skbuild_overrides_matched_version_extra(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_overrides, "__version__", "0.10"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.scikit-build-version = ">=0.10"
not-real = true
"""
)
)
settings = SettingsReader.from_file(pyproject_toml)
with pytest.raises(SystemExit):
settings.validate_may_exit()
assert "not-real" in capsys.readouterr().out
def test_skbuild_overrides_matched_version_if_any(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_overrides, "__version__", "0.9"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.any.scikit-build-version = ">=0.10"
if.any.not-real = true
also-not-real = true
"""
)
)
settings = SettingsReader.from_file(pyproject_toml)
settings.validate_may_exit()
def test_skbuild_overrides_matched_version_if_any_dual(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_overrides, "__version__", "0.9"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.scikit-build-version = ">=0.10"
if.any.not-real = true
if.any.python-version = ">=3.7"
also-not-real = true
"""
)
)
settings = SettingsReader.from_file(pyproject_toml)
settings.validate_may_exit()
def test_skbuild_overrides_matched_version_if_any_match(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_overrides, "__version__", "0.10"
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
dedent(
"""\
[[tool.scikit-build.overrides]]
if.any.scikit-build-version = ">=0.10"
if.any.not-real = true
if.python-version = ">=3.7"
experimental = true
"""
)
)
with pytest.raises(TypeError, match="not_real"):
SettingsReader.from_file(pyproject_toml)