Fix how setup.py identifies the Mercurial version.
authorJeremy Whitlock <jcscoobyrs@gmail.com>
Thu, 02 Apr 2009 18:18:43 -0600
changeset 8493 4c030ada58d2
parent 8426 2ff17c4de1da
child 8494 97184c58d0b8
child 8560 107af208ed0b
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.)
setup.py
--- a/setup.py	Sun May 17 19:54:26 2009 +0200
+++ 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):