[PATCH 4 of 4] setup: append the latesttag to the version string when no tag is found
Gilles Moris
gilles.moris at free.fr
Fri Oct 9 06:49:34 CDT 2009
setup.py | 69 +++++++++++++++++++++++++++++++++++++++++++++------------------------
1 files changed, 45 insertions(+), 24 deletions(-)
# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1255088188 -7200
# Node ID 71ae44473398f03ffc5edf4e003ad133fc6a1b69
# Parent 93fe5e311cba260bbca66ec63410d0124882381e
setup: append the latesttag to the version string when no tag is found
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -97,6 +97,22 @@
except ImportError:
pass
+def runcmd(cmd):
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, env=env)
+ out, err = p.communicate()
+ # If root is executing setup.py, but the repository is owned by
+ # another user (as in "sudo python setup.py install") we will get
+ # trust warnings since the .hg/hgrc file is untrusted. That is
+ # fine, we don't want to load it anyway.
+ err = [e for e in err.splitlines()
+ if not e.startswith('Not trusting file')]
+ if err:
+ sys.stderr.write('warning: could not establish Mercurial '
+ 'version:\n%s\n' % '\n'.join(err))
+ return ''
+ return out
+
version = None
if os.path.isdir('.hg'):
@@ -112,35 +128,31 @@
# under Windows. Otherwise, the subprocess will fail with
# error 0xc0150004. See: http://bugs.python.org/issue3440
env['SystemRoot'] = os.environ['SystemRoot']
+
cmd = [sys.executable, 'hg', 'id', '-i', '-t']
+ l = runcmd(cmd).split()
+ while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
+ l.pop()
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, env=env)
- out, err = p.communicate()
+ latesttag = ''
+ if len(l) == 1: # no tag found for that rev
+ # then search for latest tag
+ cmd = [sys.executable, 'hg', 'parents', '--template',
+ ' [{latesttag}+{latesttagdistance}]']
+ latesttag = runcmd(cmd)
- # If root is executing setup.py, but the repository is owned by
- # another user (as in "sudo python setup.py install") we will get
- # trust warnings since the .hg/hgrc file is untrusted. That is
- # fine, we don't want to load it anyway.
- err = [e for e in err.splitlines()
- if not e.startswith('Not trusting file')]
- if err:
- sys.stderr.write('warning: could not establish Mercurial '
- 'version:\n%s\n' % '\n'.join(err))
- else:
- l = out.split()
- while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
- l.pop()
- if l:
- version = l[-1] # latest tag or revision number
- if l[0].endswith('+') and len(l) > 1:
- # for an unclean working directory based on a tag, we also
- # need a '+'
- version += '+'
- if version.endswith('+'):
- version += time.strftime('%Y%m%d')
+ if l:
+ version = l[-1] # latest tag or revision number
+ if l[0].endswith('+') and len(l) > 1:
+ # for an dirty working directory based on a tag, we also
+ # need a '+'
+ version += '+'
+ if version.endswith('+'):
+ version += time.strftime('%Y%m%d')
+ version += latesttag
elif os.path.exists('.hg_archival.txt'):
hgarchival = open('.hg_archival.txt')
+ latesttag = latesttagdistance = None
for line in hgarchival:
if line.startswith('node:'):
version = line.split(':')[1].strip()[:12]
@@ -148,6 +160,15 @@
version = line.split(':')[1].strip()
# stop on the first tag we find
break
+ # otherwise, try to fallback to the latest tag
+ if line.startswith('latesttag:'):
+ latesttag = line.split(':', 1)[1].strip()
+ if line.startswith('latesttagdistance:'):
+ latesttagdistance = line.split(':')[1].strip()
+ if latesttag and latesttagdistance:
+ # note that if distance is 0, it will not enter, which is expected
+ version += _(' [%s+%s]') % \
+ (latesttag, latesttagdistance)
if version:
f = open("mercurial/__version__.py", "w")
More information about the Mercurial-devel
mailing list