Skip to content

Commit a134722

Browse files
[build] Extract package version from __init__.py (#288)
1 parent 5ec92ca commit a134722

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

setup.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
[metadata]
22
name = fast_llm
3-
# TODO: Take from __init__.py instead?
4-
version = 0.2.0
53

64
[options]
75
packages = find_namespace:

setup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import sys
2+
import re
3+
import pathlib
24

35
try:
46
import pybind11
@@ -16,6 +18,14 @@
1618
print(f"Error: setuptools version {_SETUPTOOLS_MIN_VERSION} " "or greater is required")
1719
sys.exit(1)
1820

21+
def get_version():
22+
"""Read version from fast_llm/__init__.py"""
23+
init_file = pathlib.Path(__file__).parent.joinpath("fast_llm", "__init__.py").read_text()
24+
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", init_file, re.M)
25+
if version_match:
26+
return version_match.group(1)
27+
raise RuntimeError("Unable to find version string in fast_llm/__init__.py")
28+
1929
cpp_extension = setuptools.Extension(
2030
"fast_llm.csrc.data",
2131
sources=["fast_llm/csrc/data.cpp"],
@@ -27,4 +37,5 @@
2737

2838
setuptools.setup(
2939
ext_modules=[cpp_extension],
40+
version=get_version(),
3041
)

0 commit comments

Comments
 (0)