From 39411702767cc9b2d6f9a48bef3c6b1e6c7b6187 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Fri, 10 Aug 2012 11:04:52 +0300 Subject: [PATCH] Removed generation of __version__.py 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 | 4 ++-- VERSION | 1 - gitbuildsys/__init__.py | 1 + setup.py | 27 ++++++++++++--------------- tools/gbs | 4 ++-- 5 files changed, 17 insertions(+), 20 deletions(-) delete mode 100644 VERSION diff --git a/Makefile b/Makefile index bb2615b..0ad9e88 100644 --- 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 index 6f4eebd..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.8.1 diff --git a/gitbuildsys/__init__.py b/gitbuildsys/__init__.py index d1433f5..59dad89 100644 --- a/gitbuildsys/__init__.py +++ b/gitbuildsys/__init__.py @@ -20,3 +20,4 @@ module for gbs tool """ +__version__ = "0.8.1" diff --git a/setup.py b/setup.py index cbc2576..e68f935 100644 --- 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): diff --git a/tools/gbs b/tools/gbs index 5774862..36460a0 100755 --- 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) -- 2.7.4