Skip to content

Commit a152b3b

Browse files
njzjz-botnjzjz-bot
andauthored
fix(build): migrate to stable dynamic metadata API (deepmodeling#5769)
Summary: - migrate project metadata configuration to the standard `[[tool.dynamic-metadata]]` interface introduced in scikit-build-core 1.0 - update the in-tree metadata provider to return project fragments using the v1 protocol - require `scikit-build-core>=1`, opt into `minimum-version = "1.0"`, and remove the obsolete experimental flag - migrate the renamed CMake version environment setting to a valid version specifier Supersedes deepmodeling#5759, which only widens the upper bound while retaining the deprecated metadata interface. Fixes deepmodeling#3558 Validation: - `ruff check .` - `ruff format .` - resolved the complete project metadata table with scikit-build-core 1.0.0, including version, optional dependencies, scripts, and readme - built the source distribution successfully in an isolated environment with scikit-build-core 1.0.2 Coding agent: Codex Codex version: codex-cli 0.144.1 Model: gpt-5.6-sol Reasoning effort: xhigh <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Build & Packaging** * Updated package metadata handling to support the standard provider configuration. * Improved compatibility with newer scikit-build-core releases. * Updated CMake version requirements used during builds. * Refined generation of optional dependencies and executable scripts from project configuration. * Removed support for the legacy entry-points metadata option. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: njzjz-bot <njzjz.bot@gmail.com>
1 parent 0c5a914 commit a152b3b

3 files changed

Lines changed: 42 additions & 21 deletions

File tree

backend/dynamic_metadata.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
2+
"""Provide project metadata that depends on the selected build configuration."""
3+
24
import sys
5+
from collections.abc import (
6+
Mapping,
7+
)
38
from pathlib import (
49
Path,
510
)
11+
from typing import (
12+
Any,
13+
)
614

715
from .find_pytorch import (
816
get_pt_requirement,
@@ -27,29 +35,44 @@ def __dir__() -> list[str]:
2735

2836

2937
def dynamic_metadata(
30-
field: str,
31-
settings: dict[str, object] | None = None,
32-
):
33-
assert field in ["optional-dependencies", "entry-points", "scripts"]
38+
settings: Mapping[str, object],
39+
_project: Mapping[str, Any],
40+
) -> dict[str, Any]:
41+
"""Return one metadata fragment using the standard v1 provider protocol.
42+
43+
Each ``[[tool.dynamic-metadata]]`` entry selects a field explicitly. The
44+
returned mapping is merged into the resolved ``[project]`` table by
45+
scikit-build-core.
46+
"""
47+
field = settings.get("field")
48+
if not isinstance(field, str) or field not in {
49+
"optional-dependencies",
50+
"scripts",
51+
}:
52+
msg = f"Unsupported dynamic metadata field: {field!r}"
53+
raise ValueError(msg)
54+
3455
_, _, find_libpython_requires, extra_scripts, tf_version, pt_version = (
3556
get_argument_from_env()
3657
)
3758
with Path("pyproject.toml").open("rb") as f:
3859
pyproject = tomllib.load(f)
3960

4061
if field == "scripts":
41-
return {
62+
result = {
4263
**pyproject["tool"]["deepmd_build_backend"]["scripts"],
4364
**extra_scripts,
4465
}
45-
elif field == "optional-dependencies":
66+
else:
4667
optional_dependencies = pyproject["tool"]["deepmd_build_backend"][
4768
"optional-dependencies"
4869
]
4970
optional_dependencies["lmp"].extend(find_libpython_requires)
5071
optional_dependencies["ipi"].extend(find_libpython_requires)
51-
return {
72+
result = {
5273
**optional_dependencies,
5374
**get_tf_requirement(tf_version),
5475
**get_pt_requirement(pt_version),
5576
}
77+
78+
return {field: result}

backend/read_env.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,6 @@ def get_argument_from_env() -> tuple[str, list, list, dict, str, str]:
135135
def set_scikit_build_env() -> None:
136136
"""Set scikit-build environment variables before executing scikit-build."""
137137
cmake_minimum_required_version, cmake_args, _, _, _, _ = get_argument_from_env()
138-
os.environ["SKBUILD_CMAKE_MINIMUM_VERSION"] = cmake_minimum_required_version
138+
# scikit-build-core v1 expects cmake.version to be a version specifier.
139+
os.environ["SKBUILD_CMAKE_VERSION"] = f">={cmake_minimum_required_version}"
139140
os.environ["SKBUILD_CMAKE_ARGS"] = ";".join(cmake_args)

pyproject.toml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[build-system]
22
requires = [
3-
# TODO: unpin the upper bound when scikit-build dynamic metadata API is stable
4-
# dynamic metadata API is still unstable
5-
"scikit-build-core>=0.11,!=0.6.0,<0.13",
3+
"scikit-build-core>=1",
64
"packaging",
75
'tomli >= 1.1.0 ; python_version < "3.11"',
86
"dependency_groups",
@@ -200,8 +198,7 @@ pin_jax_gpu = [
200198
[tool.setuptools_scm]
201199

202200
[tool.scikit-build]
203-
experimental = true
204-
minimum-version = "0.5"
201+
minimum-version = "1.0"
205202
cmake.source-dir = "source"
206203
sdist.include = [
207204
"/deepmd/_version.py",
@@ -224,18 +221,18 @@ wheel.packages = [
224221
wheel.py-api = "py37"
225222
build-dir = "build/{wheel_tag}"
226223

227-
[tool.scikit-build.metadata.version]
224+
[[tool.dynamic-metadata]]
228225
provider = "scikit_build_core.metadata.setuptools_scm"
229226

230-
[tool.scikit-build.metadata.optional-dependencies]
231-
provider = "backend.dynamic_metadata"
232-
provider-path = "backend"
227+
[[tool.dynamic-metadata]]
228+
provider = {path = ".", module = "backend.dynamic_metadata"}
229+
field = "optional-dependencies"
233230

234-
[tool.scikit-build.metadata.scripts]
235-
provider = "backend.dynamic_metadata"
236-
provider-path = "backend"
231+
[[tool.dynamic-metadata]]
232+
provider = {path = ".", module = "backend.dynamic_metadata"}
233+
field = "scripts"
237234

238-
[tool.scikit-build.metadata.readme]
235+
[[tool.dynamic-metadata]]
239236
provider = "scikit_build_core.metadata.fancy_pypi_readme"
240237

241238
[[tool.scikit-build.generate]]

0 commit comments

Comments
 (0)