[PATCH 4 of 4] setup: give a more explicit version string for both archive and in-place builds
Gilles Moris
gilles.moris at free.fr
Tue Aug 11 03:08:14 CDT 2009
setup.py | 44 ++++++++++++++++++++++++++++++++++++++------
1 files changed, 38 insertions(+), 6 deletions(-)
# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1249977954 -7200
# Node ID 9fe820488de03185cbc1a25e224ad154aefb515a
# Parent b5174f4fd0c766fa5a1f898b49c67c11271dfb61
setup: give a more explicit version string for both archive and in-place builds
If the rev is not based on a tag, this includes mention to the last tag and the
distance to it.
It also mention if local changes were applied during the build.
It's worth noting that a dependency has been added to mercurial.i18n to enable
the translation of the strings.
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -37,6 +37,8 @@
from distutils.spawn import spawn, find_executable
from distutils.ccompiler import new_compiler
+from mercurial.i18n import _
+
extra = {}
scripts = ['hg', 'contrib/hgk']
if os.name == 'nt':
@@ -131,19 +133,49 @@
l = out.split()
while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
l.pop()
+ lasttag = ''
+ if len(l) == 1: # no tag found for that rev
+ # then search for last tag
+ cmd = [sys.executable, 'hg', 'parents', '--template',
+ _(' based on %s + %s changes') % ('{lasttag}',
+ '{lasttagdistance}')]
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, env=env)
+ out, err = p.communicate()
+
+ 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:
+ # append last tag and the distance to it
+ lasttag = out
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')
+ version += lasttag
+ if l[0].endswith('+'): # dirty working directory
+ version += _(' with local changes as of %s') % \
+ time.strftime('%Y%m%d')
elif os.path.exists('.hg_archival.txt'):
hgarchival = open('.hg_archival.txt')
+ lasttag = lasttagdistance = None
for line in hgarchival:
if line.startswith('node:'):
version = line.split(':')[1].strip()[:12]
+ if line.startswith('tag:'):
+ version = line.split(':')[1].strip()
+ # stop on the first tag we find
+ break
+ # otherwise, try to fallback to the last tag
+ if line.startswith('lasttag:'):
+ lasttag = line.split(':', 1)[1].strip()
+ if line.startswith('lasttagdistance:'):
+ lasttagdistance = line.split(':')[1].strip()
+ if lasttag and lasttagdistance:
+ # note that if distance is 0, it will not enter, which is expected
+ version += _(' based on %s + %s changes') % \
+ (lasttag, lasttagdistance)
break
if version:
More information about the Mercurial-devel
mailing list