##// END OF EJS Templates
setup.py: subprocess instead of os.popen, sys.stderr.write instead of print...
Christian Ebert -
r8547:548fd7a0 default
parent child Browse files
Show More
@@ -26,7 +26,7 b' except:'
26 raise SystemExit(
26 raise SystemExit(
27 "Couldn't import standard zlib (incomplete Python install).")
27 "Couldn't import standard zlib (incomplete Python install).")
28
28
29 import os, time
29 import os, subprocess, time
30 import shutil
30 import shutil
31 import tempfile
31 import tempfile
32 from distutils.core import setup, Extension
32 from distutils.core import setup, Extension
@@ -97,29 +97,31 b' try:'
97 except ImportError:
97 except ImportError:
98 pass
98 pass
99
99
100 if os.path.exists('.hg'):
100 if os.path.isdir('.hg'):
101 # execute hg out of this directory with a custom environment which
101 # execute hg out of this directory with a custom environment which
102 # includes the pure Python modules in mercurial/pure
102 # includes the pure Python modules in mercurial/pure
103 pypath = os.environ.get('PYTHONPATH', '')
103 pypath = os.environ.get('PYTHONPATH', '')
104 purepath = os.path.join('mercurial', 'pure')
104 purepath = os.path.join('mercurial', 'pure')
105 os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath])
105 os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath])
106 os.environ['HGRCPATH'] = '' # do not read any config file
106 os.environ['HGRCPATH'] = '' # do not read any config file
107 cmd = '%s hg id -it' % sys.executable
107 cmd = [sys.executable, 'hg', 'id', '-i', '-t']
108 version = None
108 version = None
109
109
110 try:
110 l, e = subprocess.Popen(cmd, stdout=subprocess.PIPE,
111 l = os.popen(cmd).read().split()
111 stderr=subprocess.PIPE).communicate()
112 except OSError, e:
113 print "warning: could not establish Mercurial version: %s" % e
114
115 os.environ['PYTHONPATH'] = pypath
112 os.environ['PYTHONPATH'] = pypath
116
113
117 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
114 if e:
118 l.pop()
115 sys.stderr.write('warning: could not establish Mercurial version: %s'
119 if l:
116 % e)
120 version = l[-1] # latest tag or revision number
117 else:
121 if version.endswith('+'):
118 l = l.split()
122 version += time.strftime('%Y%m%d')
119 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
120 l.pop()
121 if l:
122 version = l[-1] # latest tag or revision number
123 if version.endswith('+'):
124 version += time.strftime('%Y%m%d')
123
125
124 if version:
126 if version:
125 f = file("mercurial/__version__.py", "w")
127 f = file("mercurial/__version__.py", "w")
General Comments 0
You need to be logged in to leave comments. Login now