Mercurial > hg-stable
changeset 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 | f4eddec324b7 |
children | 5be8760d2fb3 |
files | setup.py |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Fri Jul 09 14:21:45 2010 +0200 +++ b/setup.py Fri Jul 02 16:21:34 2010 -0300 @@ -9,6 +9,17 @@ if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'): raise SystemExit("Mercurial requires Python 2.4 or later.") +if sys.version_info[0] >= 3: + def b(s): + '''A helper function to emulate 2.6+ bytes literals using string + literals.''' + return s.encode('latin1') +else: + def b(s): + '''A helper function to emulate 2.6+ bytes literals using string + literals.''' + return s + # Solaris Python packaging brain damage try: import hashlib @@ -114,8 +125,8 @@ # fine, we don't want to load it anyway. Python may warn about # a missing __init__.py in mercurial/locale, we also ignore that. err = [e for e in err.splitlines() - if not e.startswith('Not trusting file') \ - and not e.startswith('warning: Not importing')] + if not e.startswith(b('Not trusting file')) \ + and not e.startswith(b('warning: Not importing'))] if err: return '' return out