[PATCH] setup: convert setupversion to unicode on Python

Gregory Szorc gregory.szorc at gmail.com
Sun Mar 12 01:13:47 UTC 2017


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1489281124 28800
#      Sat Mar 11 17:12:04 2017 -0800
# Node ID 8440bd7adf46c6beee6657638f4b349c754322df
# Parent  718a57e95a897f4ac407ae3733a7d41e87354acb
setup: convert setupversion to unicode on Python

Something deep in the bowels of distutils expects "version" passed to
setup() to be a str/unicode. So, convert the type.

This still works on Python 2 because the string is ascii and an
implicit coercion back to str/bytes should work without issue. If
it does cause problems, we can always make the unicode conversion
dependent on running Python 3.

This change makes `python3.5 setup.py install` work.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -660,9 +660,16 @@ for root in ('templates',):
             f = os.path.join(curdir, f)
             packagedata['mercurial'].append(f)
 
 datafiles = []
-setupversion = version
+
+# distutils expects version to be str/unicode. Converting it to
+# unicode on Python 2 still works because it won't contain any
+# non-ascii bytes and will be implicitly converted back to bytes
+# when operated on.
+assert isinstance(version, bytes)
+setupversion = version.decode('ascii')
+
 extra = {}
 
 if py2exeloaded:
     extra['console'] = [


More information about the Mercurial-devel mailing list