@@ -22,6 +22,9 @@ import __builtin__
22
22
__builtin__.__NUMPY_SETUP__ = True
23
23
24
24
from bento.commands import hooks
25
+ from bento.utils.utils \
26
+ import \
27
+ cmd_is_runnable
25
28
26
29
import waflib
27
30
@@ -87,32 +90,25 @@ def check_blas_lapack(conf):
87
90
#conf.env.HAS_LAPACK = True
88
91
#conf.env.LIB_LAPACK = ["lapack", "f77blas", "cblas", "atlas"]
89
92
90
- def set_revision(template, version):
91
- try:
92
- proc = subprocess.Popen('git rev-parse --short HEAD',
93
- stdout=subprocess.PIPE,
94
- stderr=subprocess.PIPE,
95
- shell=True)
96
- git_revision, _ = proc.communicate()
97
- git_revision = git_revision.strip()
98
- except Exception:
99
- git_revision = "Unknown"
100
-
101
- full_version = version
102
- template_str = template.read()
93
+ def compute_git_revision(top_node):
94
+ git_repo_node = top_node.find_node(".git")
95
+ if git_repo_node and cmd_is_runnable(["git", "--version"]):
96
+ s = subprocess.Popen(["git", "rev-parse", "HEAD"],
97
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=top_node.abspath())
98
+ out = s.communicate()[0]
99
+ return out.decode().strip()
100
+ else:
101
+ return ""
103
102
103
+ def _register_metadata(context):
104
+ git_revision = compute_git_revision(context.top_node)
105
+ full_version = context.pkg.version
104
106
if not _SETUP_PY.ISRELEASED:
105
107
full_version += '.dev-' + git_revision[:7]
106
- content = string.Template(template_str).substitute(version=version,
107
- full_version=full_version, git_revision=git_revision,
108
- is_released=_SETUP_
10000
PY.ISRELEASED)
109
- output = template.change_ext("")
110
- output.safe_write(content)
111
- return output
112
108
113
- def make_git_commit_info(ctx):
114
- commit_template = ctx.make_source_node(op.join("numpy ", "version.py.in") )
115
- return set_revision(commit_template, ctx.pkg.version )
109
+ context.register_metadata("git_revision", git_revision)
110
+ context.register_metadata("is_released ", _SETUP_PY.ISRELEASED )
111
+ context.register_metadata("full_version", full_version )
116
112
117
113
@hooks.post_configure
118
114
def post_configure(context):
@@ -123,11 +119,8 @@ def post_configure(context):
123
119
124
120
@hooks.pre_build
125
121
def pre_build(context):
126
- commit_output = make_git_commit_info(context)
127
- context.register_outputs_simple([commit_output])
128
-
129
- # FIXME: we write a dummy show for now - the original show function is not
130
- # super useful anyway.
131
- config_node = context.make_build_node("numpy/__config__.py")
132
- config_node.safe_write("def show(): pass")
133
- context.register_outputs_simple([config_node])
122
+ _register_metadata(context)
123
+
124
+ @hooks.pre_sdist
125
+ def pre_sdist(context):
126
+ _register_metadata(context)
0 commit comments