From 09e0bf73c35aef6222338c4056fa88e708dff275 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sun, 15 Dec 2013 13:01:37 -0500 Subject: [PATCH] setup.py now modifies __init__.py on build to include a more descriptive version string if .git is present. --- setup.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8bda9eeb..1bf206b2 100644 --- a/setup.py +++ b/setup.py @@ -17,11 +17,12 @@ if os.path.isdir(buildPath): ## Determine current version string -init = open(os.path.join(path, 'pyqtgraph/__init__.py')).read() +init = open(os.path.join(path, 'pyqtgraph', '__init__.py')).read() m = re.search(r'__version__ = (\S+)\n', init) if m is None: raise Exception("Cannot determine version number!") version = m.group(1).strip('\'\"') +initVersion = version # If this is a git checkout, append the current commit if os.path.isdir(os.path.join(path, '.git')): @@ -59,8 +60,27 @@ if os.path.isdir(os.path.join(path, '.git')): print("PyQtGraph version: " + version) +import distutils.command.build + +class Build(distutils.command.build.build): + def run(self): + ret = distutils.command.build.build.run(self) + + # If the version in __init__ is different from the automatically-generated + # version string, then we will update __init__ in the build directory + global path, version, initVersion + if initVersion == version: + return ret + + initfile = os.path.join(path, self.build_lib, 'pyqtgraph', '__init__.py') + data = open(initfile, 'r').read() + open(initfile, 'w').write(re.sub(r"__version__ = .*", "__version__ = '%s'" % version, data)) + return ret + + setup(name='pyqtgraph', version=version, + cmdclass={'build': Build}, description='Scientific Graphics and GUI Library for Python', long_description="""\ PyQtGraph is a pure-python graphics and GUI library built on PyQt4/PySide and