Patchwork [1,of,4] py3: add b'' to some setup.py strings for Windows

login
register
mail settings
Submitter Matt Harbison
Date Sept. 13, 2018, 9:44 p.m.
Message ID <ecbaa8d6b0c2d20b99e8.1536875053@mharbison-pc.attotech.com>
Download mbox | patch
Permalink /patch/34628/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 13, 2018, 9:44 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1536856652 14400
#      Thu Sep 13 12:37:32 2018 -0400
# Node ID ecbaa8d6b0c2d20b99e80e1552f81520edac09bc
# Parent  c5e6c1ba1c79ff771bacafa02706ff062258c330
py3: add b'' to some setup.py strings for Windows

These were things found trying to do `make PYTHON="py -3" local`.  The following
is dumped out, before dying while compiling the C extensions:

C:\Program Files\Python37\lib\site-packages\setuptools\dist.py:406: UserWarning:
  The version specified (b'4.7.1') is an invalid version, this may not work as
  expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440
  for more details.
  "details." % self.metadata.version
running build_py
byte-compiling .\mercurial\thirdparty\concurrent\futures\_base.py to _base.cpython-37.pyc
  File "mercurial\thirdparty\concurrent\futures\_base.py", line 416
    raise exception_type, self._exception, self._traceback
                        ^
SyntaxError: invalid syntax

# skip-blame since these are just converting to bytes literals

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -610,7 +610,7 @@  class buildhgexe(build_ext):
 
         if filelen > 0 and filelen != size:
             dllbasename = os.path.basename(buf.value)
-            if not dllbasename.lower().endswith('.dll'):
+            if not dllbasename.lower().endswith(b'.dll'):
                 raise SystemExit('Python DLL does not end with .dll: %s' %
                                  dllbasename)
             pythonlib = dllbasename[:-4]
@@ -623,8 +623,8 @@  class buildhgexe(build_ext):
 
         log.info('using %s as Python library name' % pythonlib)
         with open('mercurial/hgpythonlib.h', 'wb') as f:
-            f.write('/* this file is autogenerated by setup.py */\n')
-            f.write('#define HGPYTHONLIB "%s"\n' % pythonlib)
+            f.write(b'/* this file is autogenerated by setup.py */\n')
+            f.write(b'#define HGPYTHONLIB "%s"\n' % pythonlib)
         objects = self.compiler.compile(['mercurial/exewrapper.c'],
                                          output_dir=self.build_temp)
         dir = os.path.dirname(self.get_ext_fullpath('dummy'))
@@ -1000,7 +1000,7 @@  if py2exeloaded:
 if os.name == 'nt':
     # Windows binary file versions for exe/dll files must have the
     # form W.X.Y.Z, where W,X,Y,Z are numbers in the range 0..65535
-    setupversion = version.split('+', 1)[0]
+    setupversion = version.split(b'+', 1)[0]
 
 if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'):
     version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[1].splitlines()