101 # execute hg out of this directory with a custom environment which |
101 # execute hg out of this directory with a custom environment which |
102 # includes the pure Python modules in mercurial/pure |
102 # includes the pure Python modules in mercurial/pure |
103 pypath = os.environ.get('PYTHONPATH', '') |
103 pypath = os.environ.get('PYTHONPATH', '') |
104 purepath = os.path.join('mercurial', 'pure') |
104 purepath = os.path.join('mercurial', 'pure') |
105 os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath]) |
105 os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath]) |
106 cmd = '%s id -it' % os.path.join('.', 'hg') |
106 cmd = '%s hg id -it' % sys.executable |
107 l = os.popen(cmd).read().split() |
107 l = os.popen(cmd).read().split() |
108 os.environ['PYTHONPATH'] = pypath |
108 os.environ['PYTHONPATH'] = pypath |
109 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags |
109 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags |
110 l.pop() |
110 l.pop() |
111 version = l and l[-1] or 'unknown' # latest tag or revision number |
111 version = l and l[-1] or 'unknown' # latest tag or revision number |
112 if version.endswith('+'): |
112 if version.endswith('+'): |
113 version += time.strftime('%Y%m%d') |
113 version += time.strftime('%Y%m%d') |
114 |
114 |
115 except OSError: |
115 except OSError, e: |
|
116 print "warning: could not establish Mercurial version: %s" % e |
116 version = "unknown" |
117 version = "unknown" |
117 |
118 |
118 f = file("mercurial/__version__.py", "w") |
119 f = file("mercurial/__version__.py", "w") |
119 f.write('# this file is autogenerated by setup.py\n') |
120 f.write('# this file is autogenerated by setup.py\n') |
120 f.write('version = "%s"\n' % version) |
121 f.write('version = "%s"\n' % version) |