Fix how setup.py identifies the Mercurial version.
There is a problem with setup.py where it will not identify the Mercurial
version properly when not being ran in within a repository even if
mercurial/__version__.py exists.
To fix, use mercurial.__version__.version when available before defaulting
to "unknown". (Using mercurial.util.version() is not an option due to a
dependency issue where osutil can be referenced before it is built.)
--- a/setup.py Thu Apr 02 22:25:49 2009 +0400
+++ b/setup.py Thu Apr 02 18:18:43 2009 -0600
@@ -97,10 +97,7 @@
except ImportError:
pass
-def getversion():
- if not os.path.exists('.hg'):
- return None # not in a repository
-
+if os.path.exists('.hg'):
# execute hg out of this directory with a custom environment which
# includes the pure Python modules in mercurial/pure
pypath = os.environ.get('PYTHONPATH', '')
@@ -108,6 +105,7 @@
os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath])
os.environ['HGRCPATH'] = '' # do not read any config file
cmd = '%s hg id -it' % sys.executable
+ version = None
try:
l = os.popen(cmd).read().split()
@@ -122,16 +120,18 @@
version = l[-1] # latest tag or revision number
if version.endswith('+'):
version += time.strftime('%Y%m%d')
- return version
-version = getversion()
-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()
-else:
- version = "unknown"
+ 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__
+ version = __version__.version
+except ImportError:
+ version = 'unknown'
class install_package_data(install_data):
def finalize_options(self):