# HG changeset patch # User Jeremy Whitlock # Date 2009-05-22 19:03:06 # Node ID 3ccbe42ff72f989d999c2e291b3da5b82826acd2 # Parent 548fd7a05373f949e2523ece37de13860908f6a2 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. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -97,6 +97,8 @@ try: 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 @@ if os.path.isdir('.hg'): 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 @@ if os.path.isdir('.hg'): 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__