diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e542c333..b4c94e769 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: exclude: "^tests" - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.9 + rev: v0.11.0 hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -129,12 +129,12 @@ repos: additional_dependencies: [cogapp] - repo: https://github.com/henryiii/validate-pyproject-schema-store - rev: 2025.02.24 + rev: 2025.03.10 hooks: - id: validate-pyproject - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.31.2 + rev: 0.31.3 hooks: - id: check-dependabot - id: check-github-workflows diff --git a/src/scikit_build_core/format.py b/src/scikit_build_core/format.py index a942ad8fc..7f38dbd44 100644 --- a/src/scikit_build_core/format.py +++ b/src/scikit_build_core/format.py @@ -71,7 +71,7 @@ def pyproject_format( """Generate :py:class:`PyprojectFormatter` dictionary to use in f-string format.""" if dummy: # Return a dict with all the known keys but with values replaced with dummy values - return {key: "*" for key in PyprojectFormatter.__annotations__} + return dict.fromkeys(PyprojectFormatter.__annotations__, "*") assert settings is not None # First set all known values diff --git a/src/scikit_build_core/hatch/plugin.py b/src/scikit_build_core/hatch/plugin.py index 7cde735bd..affefb46b 100644 --- a/src/scikit_build_core/hatch/plugin.py +++ b/src/scikit_build_core/hatch/plugin.py @@ -10,7 +10,7 @@ import tempfile import typing from pathlib import Path -from typing import Any, Literal +from typing import Any from hatchling.builders.hooks.plugin.interface import BuildHookInterface from packaging.version import Version @@ -46,7 +46,9 @@ def _read_config(self) -> SettingsReader: config_dict.pop("require-runtime-dependencies", None) config_dict.pop("require-runtime-features", None) - state = typing.cast(Literal["sdist", "wheel", "editable"], self.target_name) + state = typing.cast( + "typing.Literal['sdist', 'wheel', 'editable']", self.target_name + ) return SettingsReader.from_file( "pyproject.toml", state=state, extra_settings=config_dict ) diff --git a/src/scikit_build_core/resources/_editable_redirect.py b/src/scikit_build_core/resources/_editable_redirect.py index fdf08a9a0..677f37ac8 100644 --- a/src/scikit_build_core/resources/_editable_redirect.py +++ b/src/scikit_build_core/resources/_editable_redirect.py @@ -6,9 +6,11 @@ import subprocess import sys +# Importing as little as possible is important, since every usage of Python +# imports this file. That's why we use this trick for TYPE_CHECKING TYPE_CHECKING = False if TYPE_CHECKING: - import importlib.machinery + from importlib.machinery import ModuleSpec DIR = os.path.abspath(os.path.dirname(__file__)) @@ -133,7 +135,7 @@ def find_spec( fullname: str, path: object = None, target: object = None, - ) -> importlib.machinery.ModuleSpec | None: + ) -> ModuleSpec | None: # If no known submodule_search_locations is found, it means it is a root # module. if fullname in self.submodule_search_locations: diff --git a/src/scikit_build_core/settings/sources.py b/src/scikit_build_core/settings/sources.py index 7cfb3c8ef..d288e340f 100644 --- a/src/scikit_build_core/settings/sources.py +++ b/src/scikit_build_core/settings/sources.py @@ -639,6 +639,6 @@ def unrecognized_options(self, options: object) -> Generator[str, None, None]: if typing.TYPE_CHECKING: - _: Source = typing.cast(EnvSource, None) - _ = typing.cast(ConfSource, None) - _ = typing.cast(TOMLSource, None) + _: Source = typing.cast("EnvSource", None) + _ = typing.cast("ConfSource", None) + _ = typing.cast("TOMLSource", None) diff --git a/tests/test_builder.py b/tests/test_builder.py index 10e4b0e3d..27ace40c1 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -105,7 +105,7 @@ def test_builder_macos_arch_extra(monkeypatch): archflags = "-arch arm64 -arch x86_64" monkeypatch.setattr(sys, "platform", "darwin") monkeypatch.setenv("ARCHFLAGS", archflags) - tmpcfg = typing.cast(CMaker, SimpleNamespace(env=os.environ.copy())) + tmpcfg = typing.cast("CMaker", SimpleNamespace(env=os.environ.copy())) tmpbuilder = Builder( settings=ScikitBuildSettings(wheel=WheelSettings()), @@ -125,7 +125,7 @@ def test_builder_macos_arch_extra(monkeypatch): ) def test_builder_get_cmake_args(monkeypatch, cmake_args, answer): monkeypatch.setenv("CMAKE_ARGS", cmake_args) - tmpcfg = typing.cast(CMaker, SimpleNamespace(env=os.environ.copy())) + tmpcfg = typing.cast("CMaker", SimpleNamespace(env=os.environ.copy())) tmpbuilder = Builder( settings=ScikitBuildSettings(wheel=WheelSettings()), config=tmpcfg, @@ -138,7 +138,7 @@ def test_build_tool_args(): settings = ScikitBuildSettings(build=BuildSettings(tool_args=["b"])) tmpbuilder = Builder( settings=settings, - config=typing.cast(CMaker, config), + config=typing.cast("CMaker", config), ) tmpbuilder.build(["a"]) config.build.assert_called_once_with( diff --git a/tests/test_pyproject_pep660.py b/tests/test_pyproject_pep660.py index d2f4f3a1d..110bd6806 100644 --- a/tests/test_pyproject_pep660.py +++ b/tests/test_pyproject_pep660.py @@ -11,7 +11,7 @@ @pytest.fixture(params=["redirect", "inplace"]) def editable_mode(request: pytest.FixtureRequest) -> str: - return typing.cast(str, request.param) + return typing.cast("str", request.param) # TODO: figure out why gmake is reporting no rule to make simple_pure.cpp diff --git a/tests/test_skbuild_settings.py b/tests/test_skbuild_settings.py index 61276e3de..88ed4a657 100644 --- a/tests/test_skbuild_settings.py +++ b/tests/test_skbuild_settings.py @@ -390,14 +390,29 @@ def test_skbuild_settings_pyproject_toml_broken( 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? - """.split() - ) + 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( @@ -430,14 +445,27 @@ def test_skbuild_settings_pyproject_conf_broken( 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? - """.split() - ) + 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( @@ -742,13 +770,33 @@ def test_skbuild_settings_auto_cmake_warning( ex = capsys.readouterr().out 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. - """.split() - ) + 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():