8000 ENH: use new metadata registration for version and config. · githubmlai/numpy@6fe584f · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 6fe584f

Browse files
committed
ENH: use new metadata registration for version and config.
1 parent 53e49df commit 6fe584f

File tree

4 files changed

+31
-36
lines changed

4 files changed

+31
-36
lines changed

bento.info

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ DataFiles: numpy-includes
7676
numpy/core/include/numpy/fenv/*.h
7777

7878
HookFile: bscript
79+
MetaTemplateFiles: numpy/version.py.in, numpy/__config__.py.in
7980
Recurse: numpy
8081
UseBackends: Waf
8182

bscript

< 10000 span class="sr-only">Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import __builtin__
2222
__builtin__.__NUMPY_SETUP__ = True
2323

2424
from bento.commands import hooks
25+
from bento.utils.utils \
26+
import \
27+
cmd_is_runnable
2528

2629
import waflib
2730

@@ -87,32 +90,25 @@ def check_blas_lapack(conf):
8790
#conf.env.HAS_LAPACK = True
8891
#conf.env.LIB_LAPACK = ["lapack", "f77blas", "cblas", "atlas"]
8992

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 ""
103102

103+
def _register_metadata(context):
104+
git_revision = compute_git_revision(context.top_node)
105+
full_version = context.pkg.version
104106
if not _SETUP_PY.ISRELEASED:
105107
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
112108

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)
116112

117113
@hooks.post_configure
118114
def post_configure(context):
@@ -123,11 +119,8 @@ def post_configure(context):
123119

124120
@hooks.pre_build
125121
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)

numpy/__config__.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def show():
2+
pass

numpy/version.py.in

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# THIS FILE IS GENERATED FROM NUMPY BENTO SCRIPTS
2-
short_version = "$version"
3-
version = "$version"
4-
full_version = "$full_version"
5-
git_revision = "$git_revision"
6-
release = $is_released
1+
short_version = $VERSION
2+
version = $VERSION
3+
full_version = $FULL_VERSION
4+
git_revision = $GIT_REVISION
5+
release = $IS_RELEASED
76

87
if not release:
98
version = full_version

0 commit comments

Comments
 (0)
0