Skip to content

Commit 571bd52

Browse files
authored
chore(build): move static part of dynamic metadata to pyproject.toml (deepmodeling#3618)
Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent 6da8eef commit 571bd52

File tree

2 files changed

+86
-62
lines changed

2 files changed

+86
-62
lines changed

backend/dynamic_metadata.py

+20-62
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
2+
import sys
3+
from pathlib import (
4+
Path,
5+
)
26
from typing import (
37
Dict,
48
List,
@@ -12,6 +16,11 @@
1216
get_argument_from_env,
1317
)
1418

19+
if sys.version_info >= (3, 11):
20+
import tomllib
21+
else:
22+
import tomli as tomllib
23+
1524
__all__ = ["dynamic_metadata"]
1625

1726

@@ -22,75 +31,24 @@ def __dir__() -> List[str]:
2231
def dynamic_metadata(
2332
field: str,
2433
settings: Optional[Dict[str, object]] = None,
25-
) -> str:
34+
):
2635
assert field in ["optional-dependencies", "entry-points", "scripts"]
2736
_, _, find_libpython_requires, extra_scripts, tf_version = get_argument_from_env()
37+
with Path("pyproject.toml").open("rb") as f:
38+
pyproject = tomllib.load(f)
39+
2840
if field == "scripts":
2941
return {
30-
"dp": "deepmd.main:main",
42+
**pyproject["tool"]["deepmd_build_backend"]["scripts"],
3143
**extra_scripts,
3244
}
3345
elif field == "optional-dependencies":
46+
optional_dependencies = pyproject["tool"]["deepmd_build_backend"][
47+
"optional-dependencies"
48+
]
49+
optional_dependencies["lmp"].extend(find_libpython_requires)
50+
optional_dependencies["ipi"].extend(find_libpython_requires)
3451
return {
35-
"test": [
36-
"dpdata>=0.2.7",
37-
"ase",
38-
"pytest",
39-
"pytest-cov",
40-
"pytest-sugar",
41-
"dpgui",
42-
"mendeleev",
43-
],
44-
"docs": [
45-
"sphinx>=3.1.1",
46-
"sphinx_rtd_theme>=1.0.0rc1",
47-
"sphinx_markdown_tables",
48-
"myst-nb>=1.0.0rc0",
49-
"myst-parser>=0.19.2",
50-
"sphinx-design",
51-
"breathe",
52-
"exhale",
53-
"numpydoc",
54-
"ase",
55-
"deepmodeling-sphinx>=0.1.0",
56-
"dargs>=0.3.4",
57-
"sphinx-argparse",
58-
"pygments-lammps",
59-
"sphinxcontrib-bibtex",
60-
],
61-
"lmp": [
62-
"lammps~=2023.8.2.3.0",
63-
*find_libpython_requires,
64-
],
65-
"ipi": [
66-
"i-PI",
67-
*find_libpython_requires,
68-
],
69-
"gui": [
70-
"dpgui",
71-
],
52+
**optional_dependencies,
7253
**get_tf_requirement(tf_version),
73-
"cu11": [
74-
"nvidia-cuda-runtime-cu11",
75-
"nvidia-cublas-cu11",
76-
"nvidia-cufft-cu11",
77-
"nvidia-curand-cu11",
78-
"nvidia-cusolver-cu11",
79-
"nvidia-cusparse-cu11",
80-
"nvidia-cudnn-cu11<9",
81-
"nvidia-cuda-nvcc-cu11",
82-
],
83-
"cu12": [
84-
"nvidia-cuda-runtime-cu12",
85-
"nvidia-cublas-cu12",
86-
"nvidia-cufft-cu12",
87-
"nvidia-curand-cu12",
88-
"nvidia-cusolver-cu12",
89-
"nvidia-cusparse-cu12",
90-
"nvidia-cudnn-cu12<9",
91-
"nvidia-cuda-nvcc-cu12",
92-
],
93-
"torch": [
94-
"torch>=2a",
95-
],
9654
}

pyproject.toml

+66
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ requires = [
44
# dynamic metadata API is still unstable
55
"scikit-build-core>=0.5,<0.9,!=0.6.0",
66
"packaging",
7+
'tomli >= 1.1.0 ; python_version < "3.11"',
78
]
89
build-backend = "backend.dp_backend"
910
backend-path = ["."]
@@ -63,6 +64,71 @@ Homepage = "https://github.com/deepmodeling/deepmd-kit"
6364
documentation = "https://docs.deepmodeling.com/projects/deepmd"
6465
repository = "https://github.com/deepmodeling/deepmd-kit"
6566

67+
# Metadata below is dynamic. However, it still has static parts,
68+
# which can be read by the build backend.
69+
[tool.deepmd_build_backend.optional-dependencies]
70+
test = [
71+
"dpdata>=0.2.7",
72+
"ase",
73+
"pytest",
74+
"pytest-cov",
75+
"pytest-sugar",
76+
"dpgui",
77+
"mendeleev",
78+
]
79+
docs = [
80+
"sphinx>=3.1.1",
81+
"sphinx_rtd_theme>=1.0.0rc1",
82+
"sphinx_markdown_tables",
83+
"myst-nb>=1.0.0rc0",
84+
"myst-parser>=0.19.2",
85+
"sphinx-design",
86+
"breathe",
87+
"exhale",
88+
"numpydoc",
89+
"ase",
90+
"deepmodeling-sphinx>=0.1.0",
91+
"dargs>=0.3.4",
92+
"sphinx-argparse",
93+
"pygments-lammps",
94+
"sphinxcontrib-bibtex",
95+
]
96+
lmp = [
97+
"lammps~=2023.8.2.3.0",
98+
]
99+
ipi = [
100+
"i-PI",
101+
]
102+
gui = [
103+
"dpgui",
104+
]
105+
cu11 = [
106+
"nvidia-cuda-runtime-cu11",
107+
"nvidia-cublas-cu11",
108+
"nvidia-cufft-cu11",
109+
"nvidia-curand-cu11",
110+
"nvidia-cusolver-cu11",
111+
"nvidia-cusparse-cu11",
112+
"nvidia-cudnn-cu11<9",
113+
"nvidia-cuda-nvcc-cu11",
114+
]
115+
cu12 = [
116+
"nvidia-cuda-runtime-cu12",
117+
"nvidia-cublas-cu12",
118+
"nvidia-cufft-cu12",
119+
"nvidia-curand-cu12",
120+
"nvidia-cusolver-cu12",
121+
"nvidia-cusparse-cu12",
122+
"nvidia-cudnn-cu12<9",
123+
"nvidia-cuda-nvcc-cu12",
124+
]
125+
torch = [
126+
"torch>=2a",
127+
]
128+
129+
[tool.deepmd_build_backend.scripts]
130+
dp = "deepmd.main:main"
131+
66132
[tool.setuptools_scm]
67133

68134
[tool.scikit-build]

0 commit comments

Comments
 (0)