Skip to content

Commit

Permalink
Handling encodings correctly
Browse files Browse the repository at this point in the history
Fixes #457
  • Loading branch information
Yen Chi Hsuan committed May 28, 2016
1 parent 4b707b8 commit 27c8056
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/test_cmdline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
import sys
import subprocess
import virtualenv
Expand All @@ -22,6 +23,14 @@ def test_commandline_explicit_interp(tmpdir):
str(tmpdir.join('venv'))
])

def test_commandline_non_ascii_path(tmpdir):
subprocess.check_call([
sys.executable,
VIRTUALENV_SCRIPT,
'-p', sys.executable,
str(tmpdir.join('venv中文'))
])

# The registry lookups to support the abbreviated "-p 3.5" form of specifying
# a Python interpreter on Windows don't seem to work with Python 3.5. The
# registry layout is not well documented, and it's not clear that the feature
Expand Down
6 changes: 4 additions & 2 deletions virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ def call_subprocess(cmd, show_stdout=True,
part = part.decode(sys.getfilesystemencoding())
cmd_parts.append(part)
cmd_desc = ' '.join(cmd_parts)
cmd_desc = cmd_desc.encode('utf-8')
if show_stdout:
stdout = None
else:
Expand Down Expand Up @@ -1376,8 +1377,9 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
# the value:
py_executable = '"%s"' % py_executable
# NOTE: keep this check as one line, cmd.exe doesn't cope with line breaks
cmd = [py_executable, '-c', 'import sys;out=sys.stdout;'
'getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))']
cmd = [py_executable, '-c', 'import sys;out=sys.stdout;prefix=sys.prefix;'
'prefix=prefix.encode("utf-8") if sys.version_info[0]==3 else prefix;'
'getattr(out, "buffer", out).write(prefix)']
logger.info('Testing executable with %s %s "%s"' % tuple(cmd))
try:
proc = subprocess.Popen(cmd,
Expand Down

0 comments on commit 27c8056

Please sign in to comment.