comparison setup.py @ 11532:f3732ab1149f

setup.py: Adjustments to make setup.py run in py3k. In py3k, subprocess.Popen.communicate's output are bytes objects. String literals are Unicode objects. Thus, when a bytes object startswith method is called, with string literals, it fails. What this patch does is: * Convert the string (unicode in py3k) literals to bytes objects; * As "bytes" is not a builtin in python < 2.6, it defines a "b" helper function that merely returns its argument, as suggested by Antoine Pitrou.
author Renato Cunha <renatoc@gmail.com>
date Fri, 02 Jul 2010 16:21:34 -0300
parents 1c1126b1d919
children 5be8760d2fb3
comparison
equal deleted inserted replaced
11525:f4eddec324b7 11532:f3732ab1149f
6 # 'python setup.py --help' for more options 6 # 'python setup.py --help' for more options
7 7
8 import sys 8 import sys
9 if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'): 9 if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'):
10 raise SystemExit("Mercurial requires Python 2.4 or later.") 10 raise SystemExit("Mercurial requires Python 2.4 or later.")
11
12 if sys.version_info[0] >= 3:
13 def b(s):
14 '''A helper function to emulate 2.6+ bytes literals using string
15 literals.'''
16 return s.encode('latin1')
17 else:
18 def b(s):
19 '''A helper function to emulate 2.6+ bytes literals using string
20 literals.'''
21 return s
11 22
12 # Solaris Python packaging brain damage 23 # Solaris Python packaging brain damage
13 try: 24 try:
14 import hashlib 25 import hashlib
15 sha = hashlib.sha1() 26 sha = hashlib.sha1()
112 # another user (as in "sudo python setup.py install") we will get 123 # another user (as in "sudo python setup.py install") we will get
113 # trust warnings since the .hg/hgrc file is untrusted. That is 124 # trust warnings since the .hg/hgrc file is untrusted. That is
114 # fine, we don't want to load it anyway. Python may warn about 125 # fine, we don't want to load it anyway. Python may warn about
115 # a missing __init__.py in mercurial/locale, we also ignore that. 126 # a missing __init__.py in mercurial/locale, we also ignore that.
116 err = [e for e in err.splitlines() 127 err = [e for e in err.splitlines()
117 if not e.startswith('Not trusting file') \ 128 if not e.startswith(b('Not trusting file')) \
118 and not e.startswith('warning: Not importing')] 129 and not e.startswith(b('warning: Not importing'))]
119 if err: 130 if err:
120 return '' 131 return ''
121 return out 132 return out
122 133
123 version = '' 134 version = ''