Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/scikit_build_core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/scikit_build_core/hatch/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,7 +46,9 @@
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(

Check warning on line 49 in src/scikit_build_core/hatch/plugin.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/hatch/plugin.py#L49

Added line #L49 was not covered by tests
"typing.Literal['sdist', 'wheel', 'editable']", self.target_name
)
return SettingsReader.from_file(
"pyproject.toml", state=state, extra_settings=config_dict
)
Expand Down
6 changes: 4 additions & 2 deletions src/scikit_build_core/resources/_editable_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/scikit_build_core/settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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,
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pyproject_pep660.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 71 additions & 23 deletions tests/test_skbuild_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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():
Expand Down
Loading