Skip to content

Commit 955df79

Browse files
authored
fix missing version file with setuptools-scm v8 (#2850)
See scikit-build/scikit-build-core#507. Now it's written to `{site_packages}/deepmd_cli/_version/__init__.py`. The previous implementation is too complex. --------- Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent 7fb1d11 commit 955df79

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

deepmd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
set_mkl()
3333

3434
try:
35-
from ._version import version as __version__
35+
from deepmd_cli._version import version as __version__
3636
except ImportError:
3737
from .__about__ import (
3838
__version__,

deepmd_cli/main.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import argparse
3-
import importlib.util
43
import logging
5-
import os
6-
import sys
74
import textwrap
85
from typing import (
96
List,
107
Optional,
118
)
129

13-
14-
def load_child_module(name):
15-
"""Load a child module without loading its parent module."""
16-
names = name.split(".")
17-
parent_spec = importlib.util.find_spec(names[0])
18-
paths = os.path.join(*names[1:]) + ".py"
19-
spec = importlib.util.spec_from_file_location(
20-
name, os.path.join(parent_spec.submodule_search_locations[0], paths)
21-
)
22-
module = importlib.util.module_from_spec(spec)
23-
sys.modules[name] = module
24-
spec.loader.exec_module(module)
25-
return module
26-
27-
28-
__version__ = load_child_module("deepmd._version").__version__
10+
try:
11+
from deepmd_cli._version import version as __version__
12+
except ImportError:
13+
__version__ = "unknown"
2914

3015

3116
def get_ll(log_level: str) -> int:

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ documentation = "https://docs.deepmodeling.com/projects/deepmd"
5959
repository = "https://github.com/deepmodeling/deepmd-kit"
6060

6161
[tool.setuptools_scm]
62-
write_to = "deepmd/_version.py"
6362

6463
[tool.scikit-build]
6564
experimental = true
@@ -97,6 +96,12 @@ provider-path = "backend"
9796
provider = "backend.dynamic_metadata"
9897
provider-path = "backend"
9998

99+
[[tool.scikit-build.generate]]
100+
path = "deepmd_cli/_version.py"
101+
template = '''
102+
version = "${version}"
103+
'''
104+
100105
[tool.cibuildwheel]
101106
test-command = [
102107
"python -m deepmd -h",

0 commit comments

Comments
 (0)