Mercurial > hg-stable
comparison setup.py @ 20696:77ab0abb08a0
setup: handle more invalid python3 syntax
This should keep the file portable to both python2 and python3.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Thu, 19 Sep 2013 15:38:42 -0400 |
parents | 7d4d04299927 |
children | 1cd5bff45db2 |
comparison
equal
deleted
inserted
replaced
20695:d99fcf4483f8 | 20696:77ab0abb08a0 |
---|---|
11 if sys.version_info[0] >= 3: | 11 if sys.version_info[0] >= 3: |
12 def b(s): | 12 def b(s): |
13 '''A helper function to emulate 2.6+ bytes literals using string | 13 '''A helper function to emulate 2.6+ bytes literals using string |
14 literals.''' | 14 literals.''' |
15 return s.encode('latin1') | 15 return s.encode('latin1') |
16 printf = eval('print') | |
17 libdir_escape = 'unicode_escape' | |
16 else: | 18 else: |
19 libdir_escape = 'string_escape' | |
17 def b(s): | 20 def b(s): |
18 '''A helper function to emulate 2.6+ bytes literals using string | 21 '''A helper function to emulate 2.6+ bytes literals using string |
19 literals.''' | 22 literals.''' |
20 return s | 23 return s |
24 def printf(*args, **kwargs): | |
25 f = kwargs.get('file', sys.stdout) | |
26 end = kwargs.get('end', '\n') | |
27 f.write(b' '.join(args) + end) | |
21 | 28 |
22 # Solaris Python packaging brain damage | 29 # Solaris Python packaging brain damage |
23 try: | 30 try: |
24 import hashlib | 31 import hashlib |
25 sha = hashlib.sha1() | 32 sha = hashlib.sha1() |
149 err = [e for e in err.splitlines() | 156 err = [e for e in err.splitlines() |
150 if not e.startswith(b('not trusting file')) \ | 157 if not e.startswith(b('not trusting file')) \ |
151 and not e.startswith(b('warning: Not importing')) \ | 158 and not e.startswith(b('warning: Not importing')) \ |
152 and not e.startswith(b('obsolete feature not enabled'))] | 159 and not e.startswith(b('obsolete feature not enabled'))] |
153 if err: | 160 if err: |
154 print >> sys.stderr, "stderr from '%s':" % (' '.join(cmd)) | 161 printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr) |
155 print >> sys.stderr, '\n'.join([' ' + e for e in err]) | 162 printf(b('\n').join([b(' ') + e for e in err]), file=sys.stderr) |
156 return '' | 163 return '' |
157 return out | 164 return out |
158 | 165 |
159 version = '' | 166 version = '' |
160 | 167 |
400 | 407 |
401 # skip binary files | 408 # skip binary files |
402 if b('\0') in data: | 409 if b('\0') in data: |
403 continue | 410 continue |
404 | 411 |
405 data = data.replace('@LIBDIR@', libdir.encode('string_escape')) | 412 data = data.replace(b('@LIBDIR@'), libdir.encode(libdir_escape)) |
406 fp = open(outfile, 'wb') | 413 fp = open(outfile, 'wb') |
407 fp.write(data) | 414 fp.write(data) |
408 fp.close() | 415 fp.close() |
409 | 416 |
410 cmdclass = {'build': hgbuild, | 417 cmdclass = {'build': hgbuild, |