Patchwork setup: handle more invalid python3 syntax

login
register
mail settings
Submitter Augie Fackler
Date March 12, 2014, 7:14 p.m.
Message ID <9b49c4801526513cefe5.1394651673@augie-macbookair>
Download mbox | patch
Permalink /patch/3932/
State Accepted
Commit 77ab0abb08a04d7f9a0e46027abce50191779a7e
Headers show

Comments

Augie Fackler - March 12, 2014, 7:14 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1379619522 14400
#      Thu Sep 19 15:38:42 2013 -0400
# Node ID 9b49c4801526513cefe5fc50f9ad1873e8ebc1e5
# Parent  a61ed1c2d7a70c6cc8c4a592f6d32dafc901361f
setup: handle more invalid python3 syntax

This should keep the file portable to both python2 and python3.
Matt Mackall - March 12, 2014, 9:14 p.m.
On Wed, 2014-03-12 at 15:14 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1379619522 14400
> #      Thu Sep 19 15:38:42 2013 -0400
> # Node ID 9b49c4801526513cefe5fc50f9ad1873e8ebc1e5
> # Parent  a61ed1c2d7a70c6cc8c4a592f6d32dafc901361f
> setup: handle more invalid python3 syntax

Queued for default, thanks.

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -13,11 +13,18 @@ 
         '''A helper function to emulate 2.6+ bytes literals using string
         literals.'''
         return s.encode('latin1')
+    printf = eval('print')
+    libdir_escape = 'unicode_escape'
 else:
+    libdir_escape = 'string_escape'
     def b(s):
         '''A helper function to emulate 2.6+ bytes literals using string
         literals.'''
         return s
+    def printf(*args, **kwargs):
+        f = kwargs.get('file', sys.stdout)
+        end = kwargs.get('end', '\n')
+        f.write(b' '.join(args) + end)
 
 # Solaris Python packaging brain damage
 try:
@@ -151,8 +158,8 @@ 
               and not e.startswith(b('warning: Not importing')) \
               and not e.startswith(b('obsolete feature not enabled'))]
     if err:
-        print >> sys.stderr, "stderr from '%s':" % (' '.join(cmd))
-        print >> sys.stderr, '\n'.join(['  ' + e for e in err])
+        printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr)
+        printf(b('\n').join([b('  ') + e for e in err]), file=sys.stderr)
         return ''
     return out
 
@@ -402,7 +409,7 @@ 
             if b('\0') in data:
                 continue
 
-            data = data.replace('@LIBDIR@', libdir.encode('string_escape'))
+            data = data.replace(b('@LIBDIR@'), libdir.encode(libdir_escape))
             fp = open(outfile, 'wb')
             fp.write(data)
             fp.close()