diff setup.py @ 562:c538229d02ca

setup: work around easy_install by getting version with a regex
author Augie Fackler <durin42@gmail.com>
date Mon, 15 Feb 2010 10:53:34 -0600
parents 97f2079e3778
children 09c016174e33
line wrap: on
line diff
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 import os
+import re
 import subprocess
 import sys
 import time
@@ -76,16 +77,20 @@ elif os.path.exists('.hg_archival.txt'):
     else:
         version = kw.get('node', '')[:12]
 
+verfile = os.path.join("hgsubversion", "__version__.py")
 if version:
-    f = open("hgsubversion/__version__.py", "w")
+    f = open(verfile, "w")
     f.write('# this file is autogenerated by setup.py\n')
     f.write('version = "%s"\n' % version)
     f.close()
 
-try:
-    from hgsubversion import __version__
-    version = __version__.version
-except ImportError:
+if os.path.exists(verfile):
+    # scrape the version out with a regex because setuptools
+    # needlessly swaps out file() for some non-object thing
+    # and breaks importing hgsubversion entirely
+    mat = re.findall('.*"(.*)"', open(verfile).read())
+    version = mat[0]
+if not version:
     version = 'unknown'
 
 try: