Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import os
from setuptools import setup, Extension

def _read_version():
# The _version.py file is generated by scripts/python/prepare_python_build.sh
# We read it here to set the version statically.
here = os.path.dirname(os.path.abspath(__file__))
_version_file = os.path.join(here, 'pyvsag', '_version.py')

if os.path.exists(_version_file):
ns = {}
with open(_version_file) as f:
exec(f.read(), ns)
return ns.get('__version__')
return '0.0.0'

# All other configuration is in setup.cfg / pyproject.toml.
# This file is kept for the C-extension definition.
setup(
version=_read_version(),
ext_modules=[Extension('example', sources=['example.c'])],
zip_safe=False,
)
11 changes: 10 additions & 1 deletion scripts/python/prepare_python_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ pip install -q setuptools_scm
echo " - Generating python/pyvsag/_version.py..."
python3 -c "
import setuptools_scm
version = setuptools_scm.get_version()
try:
# Explicitly configure setuptools_scm since pyproject.toml is in a subdir
version = setuptools_scm.get_version(
root='.',
version_scheme='release-branch-semver',
local_scheme='no-local-version'
)
except Exception:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching a broad Exception is generally discouraged as it can mask unexpected errors. It's better to catch a more specific exception. setuptools_scm.get_version() raises a LookupError when it cannot determine the version. You should catch LookupError instead.

Suggested change
except Exception:
except LookupError:

version = '0.0.0'

with open('python/pyvsag/_version.py', 'w') as f:
f.write(f'__version__ = \"{version}\"\\n')
print(f' - Version generated: {version}')
Expand Down
Loading