comparison 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
comparison
equal deleted inserted replaced
561:312c8c98eeff 562:c538229d02ca
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 import os 3 import os
4 import re
4 import subprocess 5 import subprocess
5 import sys 6 import sys
6 import time 7 import time
7 if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'): 8 if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'):
8 raise SystemExit("Mercurial requires python 2.4 or later.") 9 raise SystemExit("Mercurial requires python 2.4 or later.")
74 elif 'latesttag' in kw: 75 elif 'latesttag' in kw:
75 version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw 76 version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
76 else: 77 else:
77 version = kw.get('node', '')[:12] 78 version = kw.get('node', '')[:12]
78 79
80 verfile = os.path.join("hgsubversion", "__version__.py")
79 if version: 81 if version:
80 f = open("hgsubversion/__version__.py", "w") 82 f = open(verfile, "w")
81 f.write('# this file is autogenerated by setup.py\n') 83 f.write('# this file is autogenerated by setup.py\n')
82 f.write('version = "%s"\n' % version) 84 f.write('version = "%s"\n' % version)
83 f.close() 85 f.close()
84 86
85 try: 87 if os.path.exists(verfile):
86 from hgsubversion import __version__ 88 # scrape the version out with a regex because setuptools
87 version = __version__.version 89 # needlessly swaps out file() for some non-object thing
88 except ImportError: 90 # and breaks importing hgsubversion entirely
91 mat = re.findall('.*"(.*)"', open(verfile).read())
92 version = mat[0]
93 if not version:
89 version = 'unknown' 94 version = 'unknown'
90 95
91 try: 96 try:
92 from svn import core 97 from svn import core
93 assert core.SVN_VER_MAJOR == 1 98 assert core.SVN_VER_MAJOR == 1