Skip to content

Commit 7f302cc

Browse files
committed
BUG: fix numpy#1984 (generate correct version.py).
1 parent 7297785 commit 7f302cc

1 file changed

Lines changed: 41 additions & 7 deletions

File tree

‎bscript‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Caveats:
1212
import os
1313
import sys
1414
import shutil
15+
import subprocess
16+
import string
17+
18+
import os.path as op
1519

1620
# Ugly but necessary hack: import numpy here so that wscript in sub directories
1721
# will see this numpy and not an already installed one
@@ -28,6 +32,12 @@ from bento.commands.extras.waf \
2832

2933
import waflib
3034

35+
sys.path.insert(0, os.getcwd())
36+
try:
37+
_SETUP_PY = __import__("setup")
38+
finally:
39+
sys.path.pop(0)
40+
3141
def check_blas_lapack(conf):
3242
conf.env.HAS_CBLAS = False
3343
if sys.platform == "win32":
@@ -144,10 +154,41 @@ def process_write_config(self):
144154
tsk.set_outputs(output)
145155
return tsk
146156

157+
def set_revision(template, version):
158+
try:
159+
proc = subprocess.Popen('git rev-parse --short HEAD',
160+
stdout=subprocess.PIPE,
161+
stderr=subprocess.PIPE,
162+
shell=True)
163+
git_revision, _ = proc.communicate()
164+
git_revision = git_revision.strip()
165+
except Exception:
166+
git_revision = "Unknown"
167+
168+
full_version = version
169+
template_str = template.read()
170+
171+
if not _SETUP_PY.ISRELEASED:
172+
full_version += '.dev-' + git_revision[:7]
173+
content = string.Template(template_str).substitute(version=version,
174+
full_version=full_version, git_revision=git_revision,
175+
is_released=_SETUP_PY.ISRELEASED)
176+
output = template.change_ext("")
177+
output.safe_write(content)
178+
return output
179+
180+
def make_git_commit_info(ctx):
181+
commit_template = ctx.make_source_node(op.join("numpy", "version.py.in"))
182+
return set_revision(commit_template, ctx.pkg.version)
183+
147184
@hooks.pre_build
148185
def pre_build(context):
149186
bld = context.waf_context
150187

188+
context.register_category("git_info")
189+
commit_output = make_git_commit_info(context)
190+
context.register_outputs("git_info", "git_commit_info", [commit_output])
191+
151192
def iregistrer(category, name, nodes, from_node, target_dir):
152193
source_dir = os.path.join("$_srcrootdir", from_node.bldpath())
153194
files = [n.path_from(from_node) for n in nodes]
@@ -159,13 +200,6 @@ def pre_build(context):
159200
content="""\
160201
def show():
161202
pass
162-
""",
163-
always=True)
164-
bld(features="gen_pymodule",
165-
target="numpy/version.py",
166-
content="""\
167-
git_revision = ""
168-
version = ""
169203
""",
170204
always=True)
171205

0 commit comments

Comments
 (0)