Patchwork [6,of,6,py3,v4] policy: try and always have a bytes for module policy

login
register
mail settings
Submitter Augie Fackler
Date March 11, 2017, 7:39 p.m.
Message ID <8d5ff388fd05e5792221.1489261158@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/19107/
State Accepted
Headers show

Comments

Augie Fackler - March 11, 2017, 7:39 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1489014701 18000
#      Wed Mar 08 18:11:41 2017 -0500
# Node ID 8d5ff388fd05e57922214f3d6e9a80020ad34970
# Parent  f4179c62dc3fee6dadd8451214ad565986c3b149
policy: try and always have a bytes for module policy

debuginstall now runs cleanly in Python 3.
Yuya Nishihara - March 11, 2017, 8:24 p.m.
On Sat, 11 Mar 2017 14:39:18 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1489014701 18000
> #      Wed Mar 08 18:11:41 2017 -0500
> # Node ID 8d5ff388fd05e57922214f3d6e9a80020ad34970
> # Parent  f4179c62dc3fee6dadd8451214ad565986c3b149
> policy: try and always have a bytes for module policy
> 
> debuginstall now runs cleanly in Python 3.

Great. Queued, thanks.

> --- a/mercurial/policy.py
> +++ b/mercurial/policy.py
> @@ -39,7 +39,7 @@ if '__pypy__' in sys.builtin_module_name
>  # Our C extensions aren't yet compatible with Python 3. So use pure Python
>  # on Python 3 for now.
>  if sys.version_info[0] >= 3:
> -    policy = 'py'
> +    policy = b'py'

Foozy noticed __init__.py should be eventually updated as well, but that isn't
a blocker.

Just for reference, __init__.py and policy.py are loaded before our custom
importer is enabled.

Patch

diff --git a/mercurial/policy.py b/mercurial/policy.py
--- a/mercurial/policy.py
+++ b/mercurial/policy.py
@@ -39,7 +39,7 @@  if '__pypy__' in sys.builtin_module_name
 # Our C extensions aren't yet compatible with Python 3. So use pure Python
 # on Python 3 for now.
 if sys.version_info[0] >= 3:
-    policy = 'py'
+    policy = b'py'
 
 # Environment variable can always force settings.
 policy = os.environ.get('HGMODULEPOLICY', policy)
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -370,7 +370,7 @@  class hgbuildpy(build_py):
             modulepolicy = 'c'
         with open("mercurial/__modulepolicy__.py", "w") as f:
             f.write('# this file is autogenerated by setup.py\n')
-            f.write('modulepolicy = "%s"\n' % modulepolicy)
+            f.write('modulepolicy = b"%s"\n' % modulepolicy)
 
         build_py.run(self)
 
diff --git a/tests/test-check-py3-commands.t b/tests/test-check-py3-commands.t
--- a/tests/test-check-py3-commands.t
+++ b/tests/test-check-py3-commands.t
@@ -11,7 +11,7 @@  The full traceback is hidden to have a s
   version
   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   debuginstall
-  TypeError: Can't convert 'bytes' object to str implicitly
+  no problems detected
 
   $ cat > included-hgrc <<EOF
   > [extensions]