aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-06-21 20:25:44 +0200
committerTristan Gingold <tgingold@free.fr>2019-06-21 20:25:44 +0200
commit8d92e3561725148d0447dff7a9330e239f8d0f98 (patch)
tree403007f0be8c69580b419f88ad3576c0b4961fb9 /python
parent50e6497da1041a9865e5020c840070bb1a2cccee (diff)
downloadghdl-8d92e3561725148d0447dff7a9330e239f8d0f98.tar.gz
ghdl-8d92e3561725148d0447dff7a9330e239f8d0f98.tar.bz2
ghdl-8d92e3561725148d0447dff7a9330e239f8d0f98.zip
setup.py: rework version extraction.
Diffstat (limited to 'python')
-rw-r--r--python/libghdl/__init__.py2
-rw-r--r--python/setup.py38
2 files changed, 37 insertions, 3 deletions
diff --git a/python/libghdl/__init__.py b/python/libghdl/__init__.py
index 8735bf666..a733cd1a8 100644
--- a/python/libghdl/__init__.py
+++ b/python/libghdl/__init__.py
@@ -33,7 +33,7 @@ def _check_libghdl_bindir(bindir, basename):
def _get_libghdl_path():
"""Locate the directory where the shared library is"""
- basename = get_libghdl_name()
+ basename = _get_libghdl_name()
# Try VUNIT_GHDL_PATH (path of the ghdl binary when using VUnit).
r = _check_libghdl_bindir (os.environ.get('VUNIT_GHDL_PATH'), basename)
if r is not None:
diff --git a/python/setup.py b/python/setup.py
index e75e37b84..4d9dc5c41 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -1,11 +1,42 @@
#!/usr/bin/env python
+import distutils.command.build_py
from distutils.core import setup
-from libghdl.config import __version__
+import re
+
+def get_version():
+ # Try from config.py. Reads it to avoid to load the shared library.
+ r = re.compile("^__version__ = '(.*)'\n")
+ try:
+ l = open('libghdl/config.py').read()
+ m = r.match(l)
+ if m:
+ return m.group(1)
+ except:
+ pass
+ # Try to extract from configure
+ r = re.compile('^ghdl_version="(.*)"')
+ try:
+ for l in open('../configure').readlines():
+ m = r.match(l)
+ if m:
+ return m.group(1)
+ except:
+ pass
+ raise Exception("Cannot find version")
+
+# Extract the version now, as setup() may change the current directory.
+version=get_version()
+
+class MyBuildPy(distutils.command.build_py.build_py):
+ def run(self):
+ with open('libghdl/config.py', 'w') as f:
+ f.write("__version__ = '{}'\n".format(version))
+ super(MyBuildPy, self).run()
setup(
name='libghdl',
- version=__version__,
+ version=version,
description='Interface to ghdl, a VHDL analyzer',
long_description="""GHDL is a vhdl simulator and libghdl provides a low-level
interface to the parser. This library gives access to the AST so that you can
@@ -15,6 +46,9 @@ write tools like linters.
author_email='tgingold@free.fr',
url='http://github.com/ghdl/ghdl',
license='GPL-2.0-or-later',
+ cmdclass={
+ 'build_py': MyBuildPy
+ },
package_dir={
'libghdl': './libghdl'
},