Patchwork [6,of,7] py3: have bytes version of sys.executable

login
register
mail settings
Submitter Pulkit Goyal
Date Dec. 21, 2016, 10:03 p.m.
Message ID <11739d0ee458863d90e4.1482357831@pulkit-goyal>
Download mbox | patch
Permalink /patch/17999/
State Accepted
Headers show

Comments

Pulkit Goyal - Dec. 21, 2016, 10:03 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1482172344 -19800
#      Tue Dec 20 00:02:24 2016 +0530
# Node ID 11739d0ee458863d90e44c258b9773ca2e0a605a
# Parent  0c2fad895ac20844fe2947fa1a7b59280cc2698c
py3: have bytes version of sys.executable

sys.executable on Python 3 returns unicodes and we want bytes. So this patch
adds a new pycompat.sysexecutable which returns bytes by encoding using
os.fsencode() since it is path variable.

Patch

diff -r 0c2fad895ac2 -r 11739d0ee458 mercurial/pycompat.py
--- a/mercurial/pycompat.py	Thu Dec 22 01:54:17 2016 +0530
+++ b/mercurial/pycompat.py	Tue Dec 20 00:02:24 2016 +0530
@@ -52,6 +52,9 @@ 
     # returns bytes.
     getcwd = os.getcwdb
     sysplatform = sys.platform.encode('ascii')
+    sysexecutable = sys.executable
+    if sysexecutable:
+        sysexecutable = os.fsencode(sysexecutable)
 
     # TODO: .buffer might not exist if std streams were replaced; we'll need
     # a silly wrapper to make a bytes stream backed by a unicode one.
@@ -158,6 +161,7 @@ 
     sysplatform = sys.platform
     getcwd = os.getcwd
     osgetenv = os.getenv
+    sysexecutable = sys.executable
 
 stringio = io.StringIO
 empty = _queue.Empty