From 90bf6801c4820328f64db1a165ecf8ae2b4d7e92 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Fri, 1 Jun 2007 15:31:13 +0100 Subject: [PATCH] lazily compute VESION; write a pybindgen/version.py file in configure --- pybindgen/wscript | 2 ++ wscript | 33 ++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/pybindgen/wscript b/pybindgen/wscript index a4920c8..3019923 100644 --- a/pybindgen/wscript +++ b/pybindgen/wscript @@ -4,6 +4,8 @@ def build(bld): obj = bld.create_obj('py') obj.find_sources_in_dirs('.') + # commented, triggers a WAF bug (Issue #40) + #obj.source.append('version.py') obj.inst_dir = 'pybindgen' obj = bld.create_obj('py') diff --git a/wscript b/wscript index 495e95d..028f397 100644 --- a/wscript +++ b/wscript @@ -3,6 +3,7 @@ import Params from Params import fatal +import Utils import os import pproc as subprocess import shutil @@ -11,17 +12,18 @@ def get_version_from_bzr(): import bzrlib.tag, bzrlib.branch branch = bzrlib.branch.Branch.open('file://' + os.getcwd()) tags = bzrlib.tag.BasicTags(branch) - current_rev = branch.revision_history()[-1] + current_rev = branch.last_revision() for tag, revid in tags.get_tag_dict().iteritems(): if revid == current_rev: return str(tag) return str("bzr_r%i" % (branch.revno(),)) -try: - VERSION = get_version_from_bzr() -except ImportError: - VERSION = 'unknown' +def get_version(): + try: + return get_version_from_bzr() + except ImportError: + return 'unknown' APPNAME='pybindgen' srcdir = '.' @@ -52,6 +54,27 @@ def configure(conf): "(Hint: if you do not have a debugging Python library installed" " try using the configure option '--debug-level release')") + + ## Write a pybindgen/version.py file containing the project version + version = get_version() + version_lst = version.split('.') + configfile = 'pybindgen/version.py' + lst = Utils.split_path(configfile) + base = [conf.m_blddir, conf.env.variant()] + lst[:-1] + dir_ = Utils.join_path(*base) + try: + os.makedirs(dir_) + except OSError: + pass + fname = Utils.join_path(dir_, lst[-1]) + dest = open(fname, 'w') + if len(version_lst) > 1: + dest.write('__version__ = (%s)\n' % (', '.join(version.split('.')),)) + else: + dest.write('__version__ = "%s"\n' % (version,)) + dest.close() + + def build(bld): if Params.g_commands['check']: bld.add_subdirs('tests')