changeset 8548:3ccbe42ff72f

setup: read .hg_archival.txt for version info (issue1670) Previously, setup.py was enhanced to identify the Mercurial version from either .hg/ or mercurial/__version__.py. When archives are created using 'hg archive' or via hgweb, neither of those options are available. However, there is a .hg_archival.txt file in the root of the archive that has the information. This patch enhances setup.py to identify the Mercurial version from the .hg_archival.txt file when there is no .hg/ or mercurial/__version__.py available.
author Jeremy Whitlock <jcscoobyrs@gmail.com>
date Fri, 22 May 2009 21:03:06 +0200
parents 548fd7a05373
children 9f85da260508
files setup.py
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Fri May 22 14:26:58 2009 +0200
+++ b/setup.py	Fri May 22 21:03:06 2009 +0200
@@ -97,6 +97,8 @@
 except ImportError:
     pass
 
+version = None
+
 if os.path.isdir('.hg'):
     # execute hg out of this directory with a custom environment which
     # includes the pure Python modules in mercurial/pure
@@ -105,7 +107,6 @@
     os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath])
     os.environ['HGRCPATH'] = '' # do not read any config file
     cmd = [sys.executable, 'hg', 'id', '-i', '-t']
-    version = None
 
     l, e = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE).communicate()
@@ -122,12 +123,19 @@
             version = l[-1] # latest tag or revision number
             if version.endswith('+'):
                 version += time.strftime('%Y%m%d')
+elif os.path.exists('.hg_archival.txt'):
+    hgarchival = open('.hg_archival.txt')
+    for line in hgarchival:
+        if line.startswith('node:'):
+            version = line.split(':')[1].strip()[:12]
+            break
 
-    if version:
-        f = file("mercurial/__version__.py", "w")
-        f.write('# this file is autogenerated by setup.py\n')
-        f.write('version = "%s"\n' % version)
-        f.close()
+if version:
+    f = file("mercurial/__version__.py", "w")
+    f.write('# this file is autogenerated by setup.py\n')
+    f.write('version = "%s"\n' % version)
+    f.close()
+
 
 try:
     from mercurial import __version__