Skip to content

Commit

Permalink
chore: bump deps
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Oct 25, 2024
1 parent 8e6e394 commit c14a4ca
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
17 changes: 9 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude: ^src/scikit_build_core/_vendor

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -25,7 +25,7 @@ repos:
exclude: "^tests"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.7.1
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand All @@ -39,7 +39,7 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.18.0
rev: 1.19.1
hooks:
- id: blacken-docs
additional_dependencies: [black==24.*]
Expand All @@ -59,7 +59,7 @@ repos:
exclude: "^tests|src/scikit_build_core/resources/scikit-build.schema.json|^docs/projects.md"

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.13.0
hooks:
- id: mypy
exclude: |
Expand All @@ -81,16 +81,17 @@ repos:
- markdown-it-py<3 # Python 3.7 compat needed for mypy check
- ninja
- nox
- orjson
- packaging
- pytest<8
- pytest
- pytest-subprocess
- rich
- setuptools-scm
- tomli
- types-setuptools>=70.1

- repo: https://github.com/henryiii/check-sdist
rev: "v1.0.0"
rev: "v1.2.0"
hooks:
- id: check-sdist
args: [--inject-junk]
Expand Down Expand Up @@ -129,12 +130,12 @@ repos:
additional_dependencies: [cogapp]

- repo: https://github.com/henryiii/validate-pyproject-schema-store
rev: 2024.09.23
rev: 2024.10.21
hooks:
- id: validate-pyproject

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.3
rev: 0.29.4
hooks:
- id: check-dependabot
- id: check-github-workflows
Expand Down
16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ dependencies = [
"tomli >=1.2.2; python_version<'3.11'",
"typing-extensions >=3.10.0; python_version<'3.9'",
]
# Note: for building wheels and sdists, there are also additional dependencies
# in the pyproject extra. And cmake and possibly ninja if those are not already
# present (user controllable)
# Note: cmake and possibly ninja are also required if those are not already
# present (user controllable) - but a system version is fine.

[project.optional-dependencies]
pyproject = [
Expand Down Expand Up @@ -82,7 +81,7 @@ test-schema = [
"validate-pyproject",
]
cov = [
"pytest-cov[toml]",
"pytest-cov",
]
wheels = [
"cmake",
Expand Down Expand Up @@ -126,8 +125,11 @@ version.source = "vcs"
build.hooks.vcs.version-file = "src/scikit_build_core/_version.py"


[tool.uv.pip]
reinstall-package = ["scikit-build-core"]
[tool.uv]
dev-dependencies = ["scikit-build-core[test,test-hatchling,test-meta,test-numpy,test-schema,cov,dev]"]
environments = ["python_version >= '3.11'"]
pip.reinstall-package = ["scikit-build-core"]
workspace.members = ["tmp/hello/hello"]


[tool.pytest.ini_options]
Expand Down Expand Up @@ -222,7 +224,7 @@ ignore = ["W002"] # Triggers on __init__.py's


[tool.ruff]
exclude = ["src/scikit_build_core/_vendor/*"] # Required due to "build" module
exclude = ["src/scikit_build_core/_vendor/*"]

[tool.ruff.lint]
extend-select = [
Expand Down
25 changes: 16 additions & 9 deletions src/scikit_build_core/file_api/reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dataclasses
import json
import sys
import typing
from pathlib import Path
from typing import Any, Callable, Dict, List, Type, TypeVar, Union # noqa: TID251

Expand Down Expand Up @@ -56,7 +57,7 @@ def make_class(self, data: InputDict, target: Type[T]) -> T:
):
return self._load_from_json(Path(data["jsonFile"]), target)

input_dict = {}
input_dict: Dict[str, Type[Any]] = {}
exceptions: List[Exception] = []

# We don't have DataclassInstance exposed in typing yet
Expand All @@ -65,12 +66,13 @@ def make_class(self, data: InputDict, target: Type[T]) -> T:
"cmakefiles", "cmakeFiles"
)
if json_field in data:
field_type = field.type
try:
input_dict[field.name] = self._convert_any(
data[json_field], field.type
data[json_field], field_type
)
except TypeError as err:
msg = f"Failed to convert field {field.name!r} of type {field.type}"
msg = f"Failed to convert field {field.name!r} of type {field_type}"

Check warning on line 75 in src/scikit_build_core/file_api/reply.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/file_api/reply.py#L75

Added line #L75 was not covered by tests
if sys.version_info < (3, 11):
err.__notes__ = [*getattr(err, "__notes__", []), msg] # type: ignore[attr-defined]
else:
Expand All @@ -85,18 +87,23 @@ def make_class(self, data: InputDict, target: Type[T]) -> T:

return target(**input_dict)

def _convert_any(self, item: Any, target: Type[T]) -> T:
if dataclasses.is_dataclass(target):
@typing.overload
def _convert_any(self, item: Any, target: Type[T]) -> T: ...
@typing.overload
def _convert_any(self, item: Any, target: Any) -> Any: ...

def _convert_any(self, item: Any, target: Union[Type[T], Any]) -> Any:
if isinstance(target, type) and dataclasses.is_dataclass(target):
# We don't have DataclassInstance exposed in typing yet
return self.make_class(item, target) # type: ignore[return-value]
return self.make_class(item, target)
origin = get_origin(target)
if origin is not None:
if origin is list:
return [self._convert_any(i, get_args(target)[0]) for i in item] # type: ignore[return-value]
return [self._convert_any(i, get_args(target)[0]) for i in item]
if origin is Union:
return self._convert_any(item, get_args(target)[0]) # type: ignore[no-any-return]
return self._convert_any(item, get_args(target)[0])

return target(item) # type: ignore[call-arg]
return target(item)


def load_reply_dir(path: Path) -> Index:
Expand Down
7 changes: 4 additions & 3 deletions src/scikit_build_core/settings/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ def mk_docs(dc: type[object], prefix: str = "") -> Generator[DCDoc, None, None]:
docs = pull_docs(dc)

for field in dataclasses.fields(dc):
if dataclasses.is_dataclass(field.type):
yield from mk_docs(field.type, prefix=f"{prefix}{field.name}.")
field_type = field.type
if isinstance(field_type, type) and dataclasses.is_dataclass(field_type):
yield from mk_docs(field_type, prefix=f"{prefix}{field.name}.")

Check warning on line 74 in src/scikit_build_core/settings/documentation.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/settings/documentation.py#L72-L74

Added lines #L72 - L74 were not covered by tests
continue

if get_origin(field.type) is list:
field_type = get_args(field.type)[0]
if dataclasses.is_dataclass(field_type):
if isinstance(field_type, type) and dataclasses.is_dataclass(field_type):

Check warning on line 79 in src/scikit_build_core/settings/documentation.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/settings/documentation.py#L79

Added line #L79 was not covered by tests
yield from mk_docs(field_type, prefix=f"{prefix}{field.name}[].")
continue

Expand Down
7 changes: 4 additions & 3 deletions src/scikit_build_core/settings/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def to_json_schema(dclass: type[Any], *, normalize_keys: bool) -> dict[str, Any]
errs = []
required = []
for field in dataclasses.fields(dclass):
if dataclasses.is_dataclass(field.type):
field_type = field.type
if isinstance(field_type, type) and dataclasses.is_dataclass(field.type):
props[field.name] = to_json_schema(
field.type, normalize_keys=normalize_keys
field_type, normalize_keys=normalize_keys
)
continue

Expand Down Expand Up @@ -110,7 +111,7 @@ def to_json_schema(dclass: type[Any], *, normalize_keys: bool) -> dict[str, Any]


def convert_type(t: Any, *, normalize_keys: bool) -> dict[str, Any]:
if dataclasses.is_dataclass(t):
if isinstance(t, type) and dataclasses.is_dataclass(t):
return to_json_schema(t, normalize_keys=normalize_keys)
if t is str or t is Path or t is Version or t is SpecifierSet:
return {"type": "string"}
Expand Down
22 changes: 12 additions & 10 deletions src/scikit_build_core/settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _process_annotated(target: type[Any]) -> tuple[Any, tuple[Any, ...]]:
return target, ()


def _get_target_raw_type(target: type[Any]) -> Any:
def _get_target_raw_type(target: type[Any] | Any) -> Any:
"""
Takes a type like ``Optional[str]`` and returns str, or ``Optional[Dict[str,
int]]`` and returns dict. Returns Union for a Union with more than one
Expand Down Expand Up @@ -151,12 +151,14 @@ def _get_inner_type(__target: type[Any]) -> type[Any]:
raise AssertionError(msg)


def _nested_dataclass_to_names(__target: type[Any], *inner: str) -> Iterator[list[str]]:
def _nested_dataclass_to_names(
__target: type[Any] | Any, *inner: str
) -> Iterator[list[str]]:
"""
Yields each entry, like ``("a", "b", "c")`` for ``a.b.c``.
"""

if dataclasses.is_dataclass(__target):
if isinstance(__target, type) and dataclasses.is_dataclass(__target):
for field in dataclasses.fields(__target):
yield from _nested_dataclass_to_names(field.type, *inner, field.name)
else:
Expand Down Expand Up @@ -194,7 +196,7 @@ def get_item(self, *fields: str, is_dict: bool) -> Any:
...

@classmethod
def convert(cls, item: Any, target: type[Any]) -> object:
def convert(cls, item: Any, target: type[Any] | Any) -> object:
"""
Convert an ``item`` from the base representation of the source's source
into a ``target`` type. Raises TypeError if the conversion fails.
Expand Down Expand Up @@ -246,7 +248,7 @@ def get_item(
raise KeyError(msg)

@classmethod
def convert(cls, item: str, target: type[Any]) -> object:
def convert(cls, item: str, target: type[Any] | Any) -> object:
"""
Convert an item from the environment (always a string) into a target type.
"""
Expand Down Expand Up @@ -322,7 +324,7 @@ def _unrecognized_dict(
continue
(inner_option_field,) = matches
inner_option = inner_option_field.type
if dataclasses.is_dataclass(inner_option):
if isinstance(inner_option, type) and dataclasses.is_dataclass(inner_option):
yield from _unrecognized_dict(
settings[keystr], inner_option, (*above, keystr)
)
Expand Down Expand Up @@ -386,7 +388,7 @@ def get_item(

@classmethod
def convert(
cls, item: str | list[str] | dict[str, str] | bool, target: type[Any]
cls, item: str | list[str] | dict[str, str] | bool, target: type[Any] | Any
) -> object:
target, _ = _process_annotated(target)
raw_target = _get_target_raw_type(target)
Expand Down Expand Up @@ -484,13 +486,13 @@ def get_item(self, *fields: str, is_dict: bool) -> Any: # noqa: ARG002
raise KeyError(msg) from None

@classmethod
def convert(cls, item: Any, target: type[Any]) -> object:
def convert(cls, item: Any, target: type[Any] | Any) -> object:
"""
Convert an ``item`` from TOML into a ``target`` type.
"""
target, annotations = _process_annotated(target)
raw_target = _get_target_raw_type(target)
if dataclasses.is_dataclass(raw_target):
if isinstance(raw_target, type) and dataclasses.is_dataclass(raw_target):
fields = dataclasses.fields(raw_target)
values = ((k.replace("-", "_"), v) for k, v in item.items())
return raw_target(
Expand Down Expand Up @@ -579,7 +581,7 @@ def convert_target(self, target: type[T], *prefixes: str) -> T:
errors = []
prep: dict[str, Any] = {}
for field in dataclasses.fields(target): # type: ignore[arg-type]
if dataclasses.is_dataclass(field.type):
if isinstance(field.type, type) and dataclasses.is_dataclass(field.type):
try:
prep[field.name] = self.convert_target(
field.type, *prefixes, field.name
Expand Down

0 comments on commit c14a4ca

Please sign in to comment.