changeset 7958:73fa2be69ea9

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.)
author Jeremy Whitlock <jcscoobyrs@gmail.com>
date Thu, 02 Apr 2009 18:18:43 -0600
parents 88a2687fbd38
children 5fb6edbf0ab8
files setup.py
diffstat 1 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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):