diff options
author | David Cournapeau <cournape@gmail.com> | 2011-11-21 06:03:44 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2011-11-21 06:03:44 +0000 |
commit | 7f302cca29a057636cffe9be18a81f4d4d762ca0 (patch) | |
tree | eb5bd1c63c46da664d4e8c7830a3807eeff3abe5 | |
parent | 729778534afcfd54008020cfeb9c39c37d9e429b (diff) | |
download | numpy-7f302cca29a057636cffe9be18a81f4d4d762ca0.tar.gz |
BUG: fix #1984 (generate correct version.py).
-rw-r--r-- | bscript | 48 |
1 files changed, 41 insertions, 7 deletions
@@ -12,6 +12,10 @@ Caveats: import os import sys import shutil +import subprocess +import string + +import os.path as op # Ugly but necessary hack: import numpy here so that wscript in sub directories # will see this numpy and not an already installed one @@ -28,6 +32,12 @@ from bento.commands.extras.waf \ import waflib +sys.path.insert(0, os.getcwd()) +try: + _SETUP_PY = __import__("setup") +finally: + sys.path.pop(0) + def check_blas_lapack(conf): conf.env.HAS_CBLAS = False if sys.platform == "win32": @@ -144,10 +154,41 @@ def process_write_config(self): tsk.set_outputs(output) return tsk +def set_revision(template, version): + try: + proc = subprocess.Popen('git rev-parse --short HEAD', + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True) + git_revision, _ = proc.communicate() + git_revision = git_revision.strip() + except Exception: + git_revision = "Unknown" + + full_version = version + template_str = template.read() + + if not _SETUP_PY.ISRELEASED: + full_version += '.dev-' + git_revision[:7] + content = string.Template(template_str).substitute(version=version, + full_version=full_version, git_revision=git_revision, + is_released=_SETUP_PY.ISRELEASED) + output = template.change_ext("") + output.safe_write(content) + return output + +def make_git_commit_info(ctx): + commit_template = ctx.make_source_node(op.join("numpy", "version.py.in")) + return set_revision(commit_template, ctx.pkg.version) + @hooks.pre_build def pre_build(context): bld = context.waf_context + context.register_category("git_info") + commit_output = make_git_commit_info(context) + context.register_outputs("git_info", "git_commit_info", [commit_output]) + def iregistrer(category, name, nodes, from_node, target_dir): source_dir = os.path.join("$_srcrootdir", from_node.bldpath()) files = [n.path_from(from_node) for n in nodes] @@ -161,13 +202,6 @@ def show(): pass """, always=True) - bld(features="gen_pymodule", - target="numpy/version.py", - content="""\ -git_revision = "" -version = "" -""", - always=True) @hooks.options def options(context): |