[PATCH] Update setup.py to identify the version when not ran in a repository

Jeremy Whitlock jcscoobyrs at gmail.com
Thu Apr 2 16:57:39 CDT 2009


# HG changeset patch
# User Jeremy Whitlock <jcscoobyrs at gmail.com>
# Date 1238617555 21600
# Node ID c6b51395244c050fff6b7e3623e34671c7c6bf60
# Parent  67e59a9886d5902de5b94cd2552d854b6292ec63
Update setup.py to identify the version when not ran in a repository.

setup.py only identifies the correct version when ran within a repository.  For
source tarballs, this results in an incorrect version being reported and used
for creating release packages, like RPMs.

To fix this, try to get the version from mercurial.util.version() when not in a
repository before defaulting to "unknown".

diff -r 67e59a9886d5 -r c6b51395244c setup.py
--- a/setup.py	Thu Mar 26 19:01:06 2009 +0900
+++ b/setup.py	Wed Apr 01 14:25:55 2009 -0600
@@ -99,7 +99,8 @@
 
 def getversion():
     if not os.path.exists('.hg'):
-        return None # not in a repository
+        from mercurial import util
+        return util.version()
 
     # execute hg out of this directory with a custom environment which
     # includes the pure Python modules in mercurial/pure
@@ -125,7 +126,7 @@
         return version
 
 version = getversion()
-if version:
+if version and version != "unknown":
     f = file("mercurial/__version__.py", "w")
     f.write('# this file is autogenerated by setup.py\n')
     f.write('version = "%s"\n' % version)


More information about the Mercurial-devel mailing list