Skip to content

Commit b446cea

Browse files
committed
fix: generate version when prepare and read in setup.py
Signed-off-by: jac <[email protected]>
1 parent dce6325 commit b446cea

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

python/setup.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
import os
12
from setuptools import setup, Extension
23

4+
def _read_version():
5+
# The _version.py file is generated by scripts/python/prepare_python_build.sh
6+
# We read it here to set the version statically.
7+
here = os.path.dirname(os.path.abspath(__file__))
8+
_version_file = os.path.join(here, 'pyvsag', '_version.py')
9+
10+
if os.path.exists(_version_file):
11+
ns = {}
12+
with open(_version_file) as f:
13+
exec(f.read(), ns)
14+
return ns.get('__version__')
15+
return '0.0.0'
16+
317
# All other configuration is in setup.cfg / pyproject.toml.
418
# This file is kept for the C-extension definition.
519
setup(
20+
version=_read_version(),
621
ext_modules=[Extension('example', sources=['example.c'])],
722
zip_safe=False,
823
)

scripts/python/prepare_python_build.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ pip install -q setuptools_scm
2525
echo " - Generating python/pyvsag/_version.py..."
2626
python3 -c "
2727
import setuptools_scm
28-
version = setuptools_scm.get_version()
28+
try:
29+
# Explicitly configure setuptools_scm since pyproject.toml is in a subdir
30+
version = setuptools_scm.get_version(
31+
root='.',
32+
version_scheme='release-branch-semver',
33+
local_scheme='no-local-version'
34+
)
35+
except Exception:
36+
version = '0.0.0'
37+
2938
with open('python/pyvsag/_version.py', 'w') as f:
3039
f.write(f'__version__ = \"{version}\"\\n')
3140
print(f' - Version generated: {version}')

0 commit comments

Comments
 (0)