diff --git a/backend/dynamic_metadata.py b/backend/dynamic_metadata.py index 7be85d5009..2a66ff065c 100644 --- a/backend/dynamic_metadata.py +++ b/backend/dynamic_metadata.py @@ -1,4 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later +import sys +from pathlib import ( + Path, +) from typing import ( Dict, List, @@ -12,6 +16,11 @@ get_argument_from_env, ) +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib + __all__ = ["dynamic_metadata"] @@ -22,75 +31,24 @@ def __dir__() -> List[str]: def dynamic_metadata( field: str, settings: Optional[Dict[str, object]] = None, -) -> str: +): assert field in ["optional-dependencies", "entry-points", "scripts"] _, _, find_libpython_requires, extra_scripts, tf_version = get_argument_from_env() + with Path("pyproject.toml").open("rb") as f: + pyproject = tomllib.load(f) + if field == "scripts": return { - "dp": "deepmd.main:main", + **pyproject["tool"]["deepmd_build_backend"]["scripts"], **extra_scripts, } elif field == "optional-dependencies": + optional_dependencies = pyproject["tool"]["deepmd_build_backend"][ + "optional-dependencies" + ] + optional_dependencies["lmp"].extend(find_libpython_requires) + optional_dependencies["ipi"].extend(find_libpython_requires) return { - "test": [ - "dpdata>=0.2.7", - "ase", - "pytest", - "pytest-cov", - "pytest-sugar", - "dpgui", - "mendeleev", - ], - "docs": [ - "sphinx>=3.1.1", - "sphinx_rtd_theme>=1.0.0rc1", - "sphinx_markdown_tables", - "myst-nb>=1.0.0rc0", - "myst-parser>=0.19.2", - "sphinx-design", - "breathe", - "exhale", - "numpydoc", - "ase", - "deepmodeling-sphinx>=0.1.0", - "dargs>=0.3.4", - "sphinx-argparse", - "pygments-lammps", - "sphinxcontrib-bibtex", - ], - "lmp": [ - "lammps~=2023.8.2.3.0", - *find_libpython_requires, - ], - "ipi": [ - "i-PI", - *find_libpython_requires, - ], - "gui": [ - "dpgui", - ], + **optional_dependencies, **get_tf_requirement(tf_version), - "cu11": [ - "nvidia-cuda-runtime-cu11", - "nvidia-cublas-cu11", - "nvidia-cufft-cu11", - "nvidia-curand-cu11", - "nvidia-cusolver-cu11", - "nvidia-cusparse-cu11", - "nvidia-cudnn-cu11<9", - "nvidia-cuda-nvcc-cu11", - ], - "cu12": [ - "nvidia-cuda-runtime-cu12", - "nvidia-cublas-cu12", - "nvidia-cufft-cu12", - "nvidia-curand-cu12", - "nvidia-cusolver-cu12", - "nvidia-cusparse-cu12", - "nvidia-cudnn-cu12<9", - "nvidia-cuda-nvcc-cu12", - ], - "torch": [ - "torch>=2a", - ], } diff --git a/pyproject.toml b/pyproject.toml index 0e449d46af..2eb4c2f3c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,7 @@ requires = [ # dynamic metadata API is still unstable "scikit-build-core>=0.5,<0.9,!=0.6.0", "packaging", + 'tomli >= 1.1.0 ; python_version < "3.11"', ] build-backend = "backend.dp_backend" backend-path = ["."] @@ -63,6 +64,71 @@ Homepage = "https://github.com/deepmodeling/deepmd-kit" documentation = "https://docs.deepmodeling.com/projects/deepmd" repository = "https://github.com/deepmodeling/deepmd-kit" +# Metadata below is dynamic. However, it still has static parts, +# which can be read by the build backend. +[tool.deepmd_build_backend.optional-dependencies] +test = [ + "dpdata>=0.2.7", + "ase", + "pytest", + "pytest-cov", + "pytest-sugar", + "dpgui", + "mendeleev", +] +docs = [ + "sphinx>=3.1.1", + "sphinx_rtd_theme>=1.0.0rc1", + "sphinx_markdown_tables", + "myst-nb>=1.0.0rc0", + "myst-parser>=0.19.2", + "sphinx-design", + "breathe", + "exhale", + "numpydoc", + "ase", + "deepmodeling-sphinx>=0.1.0", + "dargs>=0.3.4", + "sphinx-argparse", + "pygments-lammps", + "sphinxcontrib-bibtex", +] +lmp = [ + "lammps~=2023.8.2.3.0", +] +ipi = [ + "i-PI", +] +gui = [ + "dpgui", +] +cu11 = [ + "nvidia-cuda-runtime-cu11", + "nvidia-cublas-cu11", + "nvidia-cufft-cu11", + "nvidia-curand-cu11", + "nvidia-cusolver-cu11", + "nvidia-cusparse-cu11", + "nvidia-cudnn-cu11<9", + "nvidia-cuda-nvcc-cu11", +] +cu12 = [ + "nvidia-cuda-runtime-cu12", + "nvidia-cublas-cu12", + "nvidia-cufft-cu12", + "nvidia-curand-cu12", + "nvidia-cusolver-cu12", + "nvidia-cusparse-cu12", + "nvidia-cudnn-cu12<9", + "nvidia-cuda-nvcc-cu12", +] +torch = [ + "torch>=2a", +] + +[tool.deepmd_build_backend.scripts] +dp = "deepmd.main:main" + [tool.setuptools_scm] [tool.scikit-build]