diff --git a/deepmd/__init__.py b/deepmd/__init__.py index 12af8f25b2..b02817b6fc 100644 --- a/deepmd/__init__.py +++ b/deepmd/__init__.py @@ -32,7 +32,7 @@ set_mkl() try: - from ._version import version as __version__ + from deepmd_cli._version import version as __version__ except ImportError: from .__about__ import ( __version__, diff --git a/deepmd_cli/main.py b/deepmd_cli/main.py index fceca239ea..8aa6785681 100644 --- a/deepmd_cli/main.py +++ b/deepmd_cli/main.py @@ -1,31 +1,16 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import argparse -import importlib.util import logging -import os -import sys import textwrap from typing import ( List, Optional, ) - -def load_child_module(name): - """Load a child module without loading its parent module.""" - names = name.split(".") - parent_spec = importlib.util.find_spec(names[0]) - paths = os.path.join(*names[1:]) + ".py" - spec = importlib.util.spec_from_file_location( - name, os.path.join(parent_spec.submodule_search_locations[0], paths) - ) - module = importlib.util.module_from_spec(spec) - sys.modules[name] = module - spec.loader.exec_module(module) - return module - - -__version__ = load_child_module("deepmd._version").__version__ +try: + from deepmd_cli._version import version as __version__ +except ImportError: + __version__ = "unknown" def get_ll(log_level: str) -> int: diff --git a/pyproject.toml b/pyproject.toml index 8a63a8727e..f14de6f85e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,6 @@ documentation = "https://docs.deepmodeling.com/projects/deepmd" repository = "https://github.com/deepmodeling/deepmd-kit" [tool.setuptools_scm] -write_to = "deepmd/_version.py" [tool.scikit-build] experimental = true @@ -97,6 +96,12 @@ provider-path = "backend" provider = "backend.dynamic_metadata" provider-path = "backend" +[[tool.scikit-build.generate]] +path = "deepmd_cli/_version.py" +template = ''' +version = "${version}" +''' + [tool.cibuildwheel] test-command = [ "python -m deepmd -h",