提交 9ce7ddec authored 作者: nouiz's avatar nouiz

Merge pull request #257 from josharian/issue12

Fix #12
...@@ -53,9 +53,15 @@ ISRELEASED = False ...@@ -53,9 +53,15 @@ ISRELEASED = False
VERSION = '%d.%d.%d%s' % (MAJOR, MINOR, MICRO, SUFFIX) VERSION = '%d.%d.%d%s' % (MAJOR, MINOR, MICRO, SUFFIX)
# Return the hg revision as a string -- borrowed from hg_version in NumPy's def git_version():
# setup.py file """
def hg_version(): Return the sha1 of local git HEAD as a string.
"""
# josharian: I doubt that the minimal environment stuff here is
# still needed; it is inherited. This was originally
# an hg_version function borrowed from NumPy's setup.py.
# I'm leaving it in for now because I don't have enough other
# environments to test in to be confident that it is safe to remove.
def _minimal_ext_cmd(cmd): def _minimal_ext_cmd(cmd):
# construct minimal environment # construct minimal environment
env = {} env = {}
...@@ -69,47 +75,47 @@ def hg_version(): ...@@ -69,47 +75,47 @@ def hg_version():
env['LC_ALL'] = 'C' env['LC_ALL'] = 'C'
out = subprocess.Popen( out = subprocess.Popen(
cmd, cmd,
stdout = subprocess.PIPE, stdout=subprocess.PIPE,
env=env env=env
).communicate()[0] ).communicate()[0]
return out return out
try: try:
out = _minimal_ext_cmd(['hg', '-q', 'id']) out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
HG_REVISION = out.strip().decode('ascii') git_revision = out.strip().decode('ascii')
except OSError: except OSError:
HG_REVISION = "unknown-hg" git_revision = "unknown-git"
return HG_REVISION return git_revision
def write_version_py(filename='theano/version.py'): def write_version_py(filename='theano/version.py'):
cnt = """ cnt = """
# THIS FILE IS GENERATED FROM THEANO SETUP.PY # THIS FILE IS GENERATED FROM THEANO SETUP.PY
short_version = '%(version)s' short_version = '%(version)s'
version = '%(version)s' version = '%(version)s'
hg_revision = '%(hg_revision)s' git_revision = '%(git_revision)s'
full_version = '%(version)s.dev-%%(hg_revision)s' %% {'hg_revision': hg_revision} full_version = '%(version)s.dev-%%(git_revision)s' %% {'git_revision': git_revision}
release = %(isrelease)s release = %(isrelease)s
if not release: if not release:
version = full_version version = full_version
""" """
FULL_VERSION = VERSION FULL_VERSION = VERSION
if os.path.exists('.hg'): if os.path.isdir('.git'):
HG_REVISION = hg_version() GIT_REVISION = git_version()
elif os.path.exists(filename): elif os.path.exists(filename):
# must be a source distribution, use existing version file # must be a source distribution, use existing version file
HG_REVISION = "RELEASE" GIT_REVISION = "RELEASE"
else: else:
HG_REVISION = "unknown-hg" GIT_REVISION = "unknown-git"
FULL_VERSION += '.dev-' + HG_REVISION FULL_VERSION += '.dev-' + GIT_REVISION
a = open(filename, 'w') a = open(filename, 'w')
try: try:
try: try:
a.write(cnt % {'version': VERSION, a.write(cnt % {'version': VERSION,
'full_version' : FULL_VERSION, 'full_version': FULL_VERSION,
'hg_revision' : HG_REVISION, 'git_revision': GIT_REVISION,
'isrelease': str(ISRELEASED)}) 'isrelease': str(ISRELEASED)})
except Exception, e: except Exception, e:
print e print e
finally: finally:
......
#!/bin/sh
# Script to update version.py in response to Mercurial hooks. This should
# not appear in a release tarball.
if [ -z "$HG_NODE" ] ; then
echo No HG_NODE, skipping update of theano.__version__
exit 0 # this seems to be normal sometimes
else
sed -e "s/^hg_revision.*/hg_revision = '`python -c \"print \\"$HG_NODE\\"[0:12]\"`'/" theano/version.py >theano/version.py.out && mv theano/version.py.out theano/version.py
fi
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论