Skip to content

Commit 308dcde

Browse files
authored
fix: better JSON schema generator, use Version/Path/Union (#455)
In support of #1480. Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent a4bd3d3 commit 308dcde

File tree

20 files changed

+293
-150
lines changed

20 files changed

+293
-150
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
timeout-minutes: 5
2222
steps:
2323
- uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
2426
- uses: actions/setup-python@v4
2527
with:
2628
python-version: "3.11"
@@ -31,6 +33,10 @@ jobs:
3133
run: |
3234
echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
3335
pipx run nox -s pylint
36+
- name: Run nox generator
37+
run: |
38+
pipx run nox -s generate_schema -s readme
39+
git diff --exit-code
3440
3541
checks:
3642
name:

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ cmake.build-type = "Release"
146146

147147
# The source directory to use when building the project. Currently only affects
148148
# the native builder (not the setuptools plugin).
149-
cmake.source-dir = ""
149+
cmake.source-dir = "."
150150

151151
# The build targets to use when building the project. Empty builds the default
152152
# target.
@@ -195,11 +195,9 @@ wheel.py-api = ""
195195
# (before 21.0.1) find the correct wheel.
196196
wheel.expand-macos-universal-tags = false
197197

198-
# The install directory for the wheel. This is relative to the platlib root. You
199-
# might set this to the package name. The original dir is still at
200-
# SKBUILD_PLATLIB_DIR (also SKBUILD_DATA_DIR, etc. are available). EXPERIMENTAL:
201-
# An absolute path will be one level higher than the platlib root, giving access
202-
# to "/platlib", "/data", "/headers", and "/scripts".
198+
# The install directory for the wheel. This is relative to the platlib root.
199+
# EXPERIMENTAL: An absolute path will be one level higher than the platlib root,
200+
# giving access to "/platlib", "/data", "/headers", and "/scripts".
203201
wheel.install-dir = ""
204202

205203
# A list of license files to include in the wheel. Supports glob patterns.

noxfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def _run_tests(
6262

6363
@nox.session(reuse_venv=True)
6464
def generate_schema(session: nox.Session) -> None:
65+
"""
66+
(Re)generate src/scikit_build_core/resources/scikit-build.schema.json from model.
67+
"""
6568
session.install("-e.")
6669
schema = session.run(
6770
"python", "-m", "scikit_build_core.settings.skbuild_schema", silent=True

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ show_error_codes = true
151151
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
152152
strict = true
153153
disallow_untyped_defs = false
154+
disallow_incomplete_defs = false
154155

155156
[[tool.mypy.overrides]]
156157
module = ["scikit_build_core.*"]
157158
disallow_untyped_defs = true
159+
disallow_incomplete_defs = true
158160

159161
[[tool.mypy.overrides]]
160162
module = ["numpy", "pathspec", "setuptools_scm", "hatch_fancy_pypi_readme"]

src/scikit_build_core/build/sdist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def build_sdist(
9898
pkg_info = bytes(copy.deepcopy(metadata).as_rfc822())
9999

100100
# Only normalize SDist name if 0.5+ is requested for backwards compat
101-
should_normalize_name = settings.minimum_version is None or Version(
102-
settings.minimum_version
103-
) >= Version("0.5")
101+
should_normalize_name = (
102+
settings.minimum_version is None or settings.minimum_version >= Version("0.5")
103+
)
104104

105105
sdist_name = (
106106
canonicalize_name(metadata.name).replace("-", "_")

src/scikit_build_core/build/wheel.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from collections.abc import Sequence
1010
from pathlib import Path
1111

12-
from packaging.version import Version
13-
1412
from .. import __version__
1513
from .._compat import tomllib
1614
from .._logging import logger, rich_print
@@ -100,9 +98,7 @@ def _build_wheel_impl(
10098
if wheel_directory is None:
10199
action = f"metadata_{action}"
102100

103-
cmake = CMake.default_search(
104-
minimum_version=Version(settings.cmake.minimum_version)
105-
)
101+
cmake = CMake.default_search(minimum_version=settings.cmake.minimum_version)
106102

107103
rich_print(
108104
f"[green]***[/green] [bold][green]scikit-build-core {__version__}[/green]",
@@ -170,7 +166,7 @@ def _build_wheel_impl(
170166

171167
config = CMaker(
172168
cmake,
173-
source_dir=Path(settings.cmake.source_dir or "."),
169+
source_dir=settings.cmake.source_dir,
174170
build_dir=build_dir,
175171
build_type=settings.cmake.build_type,
176172
)

src/scikit_build_core/builder/builder.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,17 @@ def get_cmake_args(self) -> list[str]:
8282
def configure(
8383
self,
8484
*,
85-
defines: Mapping[str, str],
85+
defines: Mapping[str, str | bool],
8686
cache_entries: Mapping[str, str | Path] | None = None,
8787
name: str | None = None,
8888
version: Version | None = None,
8989
limited_abi: bool | None = None,
9090
configure_args: Iterable[str] = (),
9191
) -> None:
92-
cmake_defines = dict(defines)
92+
cmake_defines = {
93+
k: ("TRUE" if v else "FALSE") if isinstance(v, bool) else v
94+
for k, v in defines.items()
95+
}
9396

9497
# Add any extra CMake modules
9598
eps = metadata.entry_points(group="cmake.module")
@@ -108,8 +111,7 @@ def configure(
108111
logger.debug("Extra SITE_PACKAGES: {}", site_packages)
109112

110113
# Add the FindPython backport if needed
111-
fp_backport = self.settings.backport.find_python
112-
if fp_backport and self.config.cmake.version < Version(fp_backport):
114+
if self.config.cmake.version < self.settings.backport.find_python:
113115
fp_dir = Path(find_python.__file__).parent.resolve()
114116
self.config.module_dirs.append(fp_dir)
115117
logger.debug("FindPython backport activated at {}", fp_dir)
@@ -180,7 +182,12 @@ def configure(
180182
cmake_defines["CMAKE_OSX_ARCHITECTURES"] = ";".join(archs)
181183

182184
# Add the pre-defined or passed CMake defines
183-
cmake_defines.update(self.settings.cmake.define)
185+
cmake_defines.update(
186+
{
187+
k: ("TRUE" if v else "FALSE") if isinstance(v, bool) else v
188+
for k, v in self.settings.cmake.define.items()
189+
}
190+
)
184191

185192
self.config.configure(
186193
defines=cmake_defines,

src/scikit_build_core/builder/generator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import sysconfig
77
from collections.abc import Mapping, MutableMapping
88

9-
from packaging.version import Version
10-
119
from .._logging import logger
1210
from ..cmake import CMake
1311
from ..errors import NinjaNotFoundError
@@ -87,8 +85,9 @@ def set_environment_for_gen(
8785
default = "Ninja"
8886

8987
if env.get("CMAKE_GENERATOR", default or "Ninja") == "Ninja":
90-
min_ninja = Version(ninja_settings.minimum_version)
91-
ninja = best_program(get_ninja_programs(), minimum_version=min_ninja)
88+
ninja = best_program(
89+
get_ninja_programs(), minimum_version=ninja_settings.minimum_version
90+
)
9291

9392
if ninja is not None:
9493
env.setdefault("CMAKE_GENERATOR", "Ninja")

src/scikit_build_core/builder/get_requires.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from collections.abc import Generator, Mapping
88

99
from packaging.tags import sys_tags
10-
from packaging.version import Version
1110

1211
from .._compat import tomllib
1312
from .._compat.typing import Literal
@@ -50,7 +49,7 @@ def __post_init__(self) -> None:
5049
).settings
5150

5251
def cmake(self) -> Generator[str, None, None]:
53-
cmake_min = Version(self._settings.cmake.minimum_version)
52+
cmake_min = self._settings.cmake.minimum_version
5453
cmake = best_program(
5554
get_cmake_programs(module=False), minimum_version=cmake_min
5655
)
@@ -74,7 +73,7 @@ def ninja(self) -> Generator[str, None, None]:
7473
if os.environ.get("CMAKE_MAKE_PROGRAM", ""):
7574
return
7675

77-
ninja_min = Version(self._settings.ninja.minimum_version)
76+
ninja_min = self._settings.ninja.minimum_version
7877
ninja = best_program(
7978
get_ninja_programs(module=False), minimum_version=ninja_min
8079
)

src/scikit_build_core/resources/scikit-build.schema.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
"type": "object",
2626
"patternProperties": {
2727
".+": {
28-
"type": "string"
28+
"oneOf": [
29+
{
30+
"type": "string"
31+
},
32+
{
33+
"type": "boolean"
34+
}
35+
]
2936
}
3037
},
3138
"description": "A table of defines to pass to CMake when configuring the project. Additive."
@@ -42,7 +49,7 @@
4249
},
4350
"source-dir": {
4451
"type": "string",
45-
"default": "",
52+
"default": ".",
4653
"description": "The source directory to use when building the project. Currently only affects the native builder (not the setuptools plugin)."
4754
},
4855
"targets": {
@@ -103,11 +110,6 @@
103110
"type": "boolean",
104111
"default": true,
105112
"description": "If set to True, try to build a reproducible distribution (Unix and Python 3.9+ recommended). ``SOURCE_DATE_EPOCH`` will be used for timestamps, or a fixed value if not set."
106-
},
107-
"cmake": {
108-
"type": "boolean",
109-
"default": false,
110-
"description": "If set to True, CMake will be run before building the SDist."
111113
}
112114
}
113115
},

0 commit comments

Comments
 (0)