[PATCH V2] setup: convert setupversion to unicode

Gregory Szorc gregory.szorc at gmail.com
Sat Mar 11 20:14:14 EST 2017

# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1489281242 28800
#      Sat Mar 11 17:14:02 2017 -0800
# Node ID 7aed668a0af18397d6d413b625d019fd5333d081
# Parent  718a57e95a897f4ac407ae3733a7d41e87354acb
setup: convert setupversion to unicode

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)
 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