Removed generation of __version__.py
authorEd Bartosh <eduard.bartosh@intel.com>
Fri, 10 Aug 2012 08:04:52 +0000 (11:04 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Mon, 13 Aug 2012 14:11:01 +0000 (17:11 +0300)
It makes gbs fail when run from source tree, if version is not
generated yet. It also breakes tests because of the same reason.

I reimplemented it in a way that version is taken from __init__.py and
imported or parsed where version info is needed.
Note, that in setup.py and Makefile it's parsed in order to less depend
on python code. setup and Make should be able to work even if
__init__.py has syntax errors. The only requirements to get a version
from there is that it should be in parseable form.

Change-Id: I928d4c75f970345c6ccd7be2cc54e4f3d9d1df38

Makefile
VERSION [deleted file]
gitbuildsys/__init__.py
setup.py
tools/gbs

index bb2615bc7bf8cc80224cd720992705f618a8beb3..0ad9e889af9de838a740af0bafa2511964d066c5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-VERSION = $(shell cat VERSION)
-TAGVER = $(shell cat VERSION | sed -e "s/\([0-9\.]*\).*/\1/")
+VERSION = $(shell sed -ne 's/__version__\s*=\s*[\x22\x27]\([^\x22\x27]\+\)[\x22\x27].*/\1/p ' gitbuildsys/__init__.py)
+TAGVER = $(shell echo $(VERSION) | sed -e "s/\([0-9\.]*\).*/\1/")
 PKGNAME = gbs
 
 ifeq ($(VERSION), $(TAGVER))
diff --git a/VERSION b/VERSION
deleted file mode 100644 (file)
index 6f4eebd..0000000
--- a/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-0.8.1
index d1433f52b34ddce00a7c08bdf621c3c4eb576fb6..59dad893dcc01d07abcb04721592c9aef58c5eb8 100644 (file)
@@ -20,3 +20,4 @@
 module for gbs tool
 """
 
+__version__ = "0.8.1"
index cbc2576b0f77f70654978c9f938547609c64f3c4..e68f935e943d6ab274b042dfe4960485f7223f5d 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -2,6 +2,8 @@
 
 import os, sys
 import glob
+import re
+
 from distutils.core import setup
 try:
     import setuptools
@@ -10,24 +12,19 @@ except ImportError:
     pass
 
 MOD_NAME = 'gitbuildsys'
-
-version_path = 'VERSION'
+version_path = os.path.join(MOD_NAME, "__init__.py")
 if not os.path.isfile(version_path):
-    print 'No VERSION file in topdir, abort'
+    print 'No %s version file found' % version_path
     sys.exit(1)
 
-try:
-    # first line should be the version number
-    version = open(version_path).readline().strip()
-    if not version:
-        print 'VERSION file is invalid, abort'
-        sys.exit(1)
-
-    ver_file = open('%s/__version__.py' % MOD_NAME, 'w')
-    ver_file.write("VERSION = \"%s\"\n" % version)
-    ver_file.close()
-except IOError:
-    print 'WARNING: Cannot write version number file'
+content = open(version_path).read()
+match = re.search(r'^__version__\s*=\s*[\x22\x27]([^\x22\x27]+)[\x22\x27]',
+                  content, re.M)
+if match:
+    version = match.group(1)
+else:
+    print 'Unable to find version in %s' % version_path
+    sys.exit(1)
 
 # "--install-layout=deb" is required for pyver>2.5 in Debian likes
 if sys.version_info[:2] > (2, 5):
index 5774862524070280def3db0f77ba0556539db604..36460a0196a995e976ba6dc2039c06fd32dee5fd 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -19,7 +19,7 @@
 import sys
 import re
 
-from gitbuildsys.__version__ import VERSION
+from gitbuildsys import __version__
 from gitbuildsys import msger, cmdln, errors
 
 def handle_repository(option, opt_str, value, parser):
@@ -56,7 +56,7 @@ class Gbs(cmdln.Cmdln):
     """
 
     name = 'gbs'
-    version = VERSION
+    version = __version__
 
     def get_optparser(self):
         optparser = cmdln.CmdlnOptionParser(self, version=self.version)