Patchwork [12,of,13,V2,py3,support] setup: handle more invalid python3 syntax

login
register
mail settings
Submitter Augie Fackler
Date Sept. 20, 2013, 2:23 p.m.
Message ID <f1b096a613612935b9b5.1379687030@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/2560/
State Superseded
Headers show

Comments

Augie Fackler - Sept. 20, 2013, 2:23 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1379619522 14400
#      Thu Sep 19 15:38:42 2013 -0400
# Node ID f1b096a613612935b9b556b25b33c32a29f75f67
# Parent  7f550b19c99c2913fe6ae147ba8e1ce793ddd07f
setup: handle more invalid python3 syntax

This should keep the file portable to both python2 and python3.
Augie Fackler - Sept. 20, 2013, 5:11 p.m.
Drop this series, I'll send a v3 based on crew tip.


On Fri, Sep 20, 2013 at 10:23 AM, Augie Fackler <raf@durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1379619522 14400
> #      Thu Sep 19 15:38:42 2013 -0400
> # Node ID f1b096a613612935b9b556b25b33c32a29f75f67
> # Parent  7f550b19c99c2913fe6ae147ba8e1ce793ddd07f
> setup: handle more invalid python3 syntax
>
> This should keep the file portable to both python2 and python3.
>
> 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:
> @@ -152,8 +159,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
>
> @@ -403,7 +410,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()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

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:
@@ -152,8 +159,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
 
@@ -403,7 +410,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()