[PATCH 1 of 7] setup.py: Adjustments to make setup.py run in py3k
Renato Cunha
renatoc at gmail.com
Thu Jul 1 17:19:14 CDT 2010
setup.py | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
# HG changeset patch
# User Renato Cunha <renatoc at gmail.com>
# Date 1278022747 10800
# Node ID f901363d4d9ea5dd0d84a8c515fd5b581c6c29d9
# Parent 8b452fe4bf506a1a08bbc7e1bac81aceda8f4d10
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.
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -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
@@ -111,8 +122,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
More information about the Mercurial-devel
mailing list