Repository: scikit-build/scikit-build-core
Pull request #526 (2023-10-17 04:55:21)

Overrides platform node
This adds support for `platform_node` in the overrides. Also takes care of a small typo in the markdown syntax for the main project README.


Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 7763dc0..4087d63 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -54,13 +54,13 @@ repos:
         exclude: "^tests|src/scikit_build_core/resources/scikit-build.schema.json"
 
   - repo: https://github.com/astral-sh/ruff-pre-commit
-    rev: v0.0.292
+    rev: v0.1.0
     hooks:
       - id: ruff
         args: ["--fix", "--show-fixes"]
 
   - repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v1.5.1
+    rev: v1.6.0
     hooks:
       - id: mypy
         exclude: |
diff --git a/README.md b/README.md
index 9359b45..2ee94ee 100644
--- a/README.md
+++ b/README.md
@@ -281,7 +281,7 @@ Most CMake environment variables should be supported, and `CMAKE_ARGS` can be
 used to set extra CMake args. `ARCHFLAGS` is used to specify macOS universal2 or
 cross-compiles, just like setuptools.
 
-You can also specify `[[tool.scikit-build.overrides]]`` to customize values for
+You can also specify `[[tool.scikit-build.overrides]]` to customize values for
 different systems. See the docs for details.
 
 ## Other projects for building
diff --git a/docs/configuration.md b/docs/configuration.md
index 013e183..b81bd49 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -586,6 +586,7 @@ take several values, based on [PEP 508][]:
 - `python_version`: The two-digit Python version. Takes a specifier set.
 - `sys_platform`: The value of `sys.platform`. Takes a regex.
 - `platform_machine`: The value of `platform.machine()`. Takes a regex.
+- `platform_node`: The value of `platform.node()`. Takes a regex.
 - `implementation_name`: The value of `sys.implementation.name`. Takes a regex.
 - `implementation_version`: Derived from `sys.implementation.version`, following
   PEP 508. Takes a specifier set.
diff --git a/src/scikit_build_core/resources/scikit-build.schema.json b/src/scikit_build_core/resources/scikit-build.schema.json
index 6ff309f..1d2dcb4 100644
--- a/src/scikit_build_core/resources/scikit-build.schema.json
+++ b/src/scikit_build_core/resources/scikit-build.schema.json
@@ -376,6 +376,9 @@
               },
               "platform-machine": {
                 "type": "string"
+              },
+              "platform-node": {
+                "type": "string"
               }
             }
           },
diff --git a/src/scikit_build_core/settings/skbuild_read_settings.py b/src/scikit_build_core/settings/skbuild_read_settings.py
index 4d23c4c..871f15e 100644
--- a/src/scikit_build_core/settings/skbuild_read_settings.py
+++ b/src/scikit_build_core/settings/skbuild_read_settings.py
@@ -42,7 +42,7 @@ def regex_match(value: str, match: str) -> str:
     """
     Returns a non-empty string if a value matches a regex.
     """
-    did_match = re.compile(match).match(value) is not None
+    did_match = re.compile(match).search(value) is not None
     return f"{match!r} matched {value}" if did_match else ""
 
 
@@ -52,6 +52,7 @@ def override_match(
     implementation_version: str | None = None,
     platform_system: str | None = None,
     platform_machine: str | None = None,
+    platform_node: str | None = None,
 ) -> bool:
     matches = []
 
@@ -86,6 +87,11 @@ def override_match(
         match_msg = regex_match(current_platform_machine, platform_machine)
         matches.append(match_msg)
 
+    if platform_node is not None:
+        current_platform_node = platform.node()
+        match_msg = regex_match(current_platform_node, platform_node)
+        matches.append(match_msg)
+
     if not matches:
         msg = "At least one override must be provided"
         raise ValueError(msg)
diff --git a/src/scikit_build_core/settings/skbuild_schema.py b/src/scikit_build_core/settings/skbuild_schema.py
index b24fb91..7ef1f60 100644
--- a/src/scikit_build_core/settings/skbuild_schema.py
+++ b/src/scikit_build_core/settings/skbuild_schema.py
@@ -101,6 +101,7 @@ def generate_skbuild_schema(tool_name: str = "scikit-build") -> dict[str, Any]:
                         "implementation-version": {"type": "string"},
                         "platform-system": {"type": "string"},
                         "platform-machine": {"type": "string"},
+                        "platform-node": {"type": "string"},
                     },
                 },
                 **props,


Test patch:
diff --git a/tests/test_settings_overrides.py b/tests/test_settings_overrides.py
index a11de4a..bd42a51 100644
--- a/tests/test_settings_overrides.py
+++ b/tests/test_settings_overrides.py
@@ -3,7 +3,7 @@ from textwrap import dedent
 
 import pytest
 
-from scikit_build_core.settings.skbuild_read_settings import SettingsReader
+from scikit_build_core.settings.skbuild_read_settings import SettingsReader, regex_match
 
 
 @pytest.mark.parametrize("python_version", ["3.9", "3.10"])
@@ -86,6 +86,32 @@ def test_skbuild_overrides_dual(
         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,
@@ -179,3 +205,13 @@ def test_skbuild_overrides_invalid_key(
     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)