Show More
@@ -211,9 +211,15 b' class BaseIPythonApplication(Application):' | |||||
211 | return crashhandler.crash_handler_lite(etype, evalue, tb) |
|
211 | return crashhandler.crash_handler_lite(etype, evalue, tb) | |
212 |
|
212 | |||
213 | def _ipython_dir_changed(self, name, old, new): |
|
213 | def _ipython_dir_changed(self, name, old, new): | |
214 | if old in sys.path: |
|
214 | str_old = py3compat.cast_bytes_py2(os.path.abspath(old), | |
215 |
sys. |
|
215 | sys.getfilesystemencoding() | |
216 | sys.path.append(os.path.abspath(new)) |
|
216 | ) | |
|
217 | if str_old in sys.path: | |||
|
218 | sys.path.remove(str_old) | |||
|
219 | str_path = py3compat.cast_bytes_py2(os.path.abspath(new), | |||
|
220 | sys.getfilesystemencoding() | |||
|
221 | ) | |||
|
222 | sys.path.append(str_path) | |||
217 | if not os.path.isdir(new): |
|
223 | if not os.path.isdir(new): | |
218 | os.makedirs(new, mode=0o777) |
|
224 | os.makedirs(new, mode=0o777) | |
219 | readme = os.path.join(new, 'README') |
|
225 | readme = os.path.join(new, 'README') |
@@ -21,6 +21,7 b' import os' | |||||
21 | import sys |
|
21 | import sys | |
22 | from subprocess import Popen, PIPE |
|
22 | from subprocess import Popen, PIPE | |
23 |
|
23 | |||
|
24 | from IPython.utils.encoding import getdefaultencoding | |||
24 | from IPython.utils.py3compat import cast_bytes_py2 |
|
25 | from IPython.utils.py3compat import cast_bytes_py2 | |
25 |
|
26 | |||
26 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
@@ -188,12 +189,14 b' def launch_kernel(cmd, stdin=None, stdout=None, stderr=None,' | |||||
188 | _stderr = PIPE if stderr is None else stderr |
|
189 | _stderr = PIPE if stderr is None else stderr | |
189 | else: |
|
190 | else: | |
190 | _stdout, _stderr = stdout, stderr |
|
191 | _stdout, _stderr = stdout, stderr | |
191 |
|
192 | |||
|
193 | encoding = getdefaultencoding(prefer_stream=False) | |||
|
194 | ||||
192 | # Spawn a kernel. |
|
195 | # Spawn a kernel. | |
193 | if sys.platform == 'win32': |
|
196 | if sys.platform == 'win32': | |
194 |
|
197 | # Popen on Python 2 on Windows cannot handle unicode args or cwd | ||
|
198 | cmd = [ cast_bytes_py2(c, encoding) for c in cmd ] | |||
195 | if cwd: |
|
199 | if cwd: | |
196 | # Popen on Python 2 on Windows cannot handle unicode cwd. |
|
|||
197 | cwd = cast_bytes_py2(cwd, sys.getfilesystemencoding() or 'ascii') |
|
200 | cwd = cast_bytes_py2(cwd, sys.getfilesystemencoding() or 'ascii') | |
198 |
|
201 | |||
199 | from IPython.kernel.zmq.parentpoller import ParentPollerWindows |
|
202 | from IPython.kernel.zmq.parentpoller import ParentPollerWindows |
@@ -35,16 +35,20 b' def get_stream_enc(stream, default=None):' | |||||
35 | # to match the environment. |
|
35 | # to match the environment. | |
36 | # Defined here as central function, so if we find better choices, we |
|
36 | # Defined here as central function, so if we find better choices, we | |
37 | # won't need to make changes all over IPython. |
|
37 | # won't need to make changes all over IPython. | |
38 | def getdefaultencoding(): |
|
38 | def getdefaultencoding(prefer_stream=True): | |
39 | """Return IPython's guess for the default encoding for bytes as text. |
|
39 | """Return IPython's guess for the default encoding for bytes as text. | |
40 |
|
40 | |||
41 | Asks for stdin.encoding first, to match the calling Terminal, but that |
|
41 | If prefer_stream is True (default), asks for stdin.encoding first, | |
42 | is often None for subprocesses. Fall back on locale.getpreferredencoding() |
|
42 | to match the calling Terminal, but that is often None for subprocesses. | |
|
43 | ||||
|
44 | Then fall back on locale.getpreferredencoding(), | |||
43 | which should be a sensible platform default (that respects LANG environment), |
|
45 | which should be a sensible platform default (that respects LANG environment), | |
44 | and finally to sys.getdefaultencoding() which is the most conservative option, |
|
46 | and finally to sys.getdefaultencoding() which is the most conservative option, | |
45 | and usually ASCII. |
|
47 | and usually ASCII on Python 2 or UTF8 on Python 3. | |
46 | """ |
|
48 | """ | |
47 | enc = get_stream_enc(sys.stdin) |
|
49 | enc = None | |
|
50 | if prefer_stream: | |||
|
51 | enc = get_stream_enc(sys.stdin) | |||
48 | if not enc or enc=='ascii': |
|
52 | if not enc or enc=='ascii': | |
49 | try: |
|
53 | try: | |
50 | # There are reports of getpreferredencoding raising errors |
|
54 | # There are reports of getpreferredencoding raising errors |
@@ -66,7 +66,11 b' def check_submodule_status(root=None):' | |||||
66 | for submodule in submodules: |
|
66 | for submodule in submodules: | |
67 | if not os.path.exists(submodule): |
|
67 | if not os.path.exists(submodule): | |
68 | return 'missing' |
|
68 | return 'missing' | |
69 |
|
69 | |||
|
70 | # Popen can't handle unicode cwd on Windows Python 2 | |||
|
71 | if sys.platform == 'win32' and sys.version_info[0] < 3 \ | |||
|
72 | and not isinstance(root, bytes): | |||
|
73 | root = root.encode(sys.getfilesystemencoding() or 'ascii') | |||
70 | # check with git submodule status |
|
74 | # check with git submodule status | |
71 | proc = subprocess.Popen('git submodule status', |
|
75 | proc = subprocess.Popen('git submodule status', | |
72 | stdout=subprocess.PIPE, |
|
76 | stdout=subprocess.PIPE, | |
@@ -75,12 +79,12 b' def check_submodule_status(root=None):' | |||||
75 | cwd=root, |
|
79 | cwd=root, | |
76 | ) |
|
80 | ) | |
77 | status, _ = proc.communicate() |
|
81 | status, _ = proc.communicate() | |
78 | status = status.decode("ascii") |
|
82 | status = status.decode("ascii", "replace") | |
79 |
|
83 | |||
80 | for line in status.splitlines(): |
|
84 | for line in status.splitlines(): | |
81 |
if |
|
85 | if line.startswith('-'): | |
82 | return 'missing' |
|
86 | return 'missing' | |
83 |
elif |
|
87 | elif line.startswith('+'): | |
84 | return 'unclean' |
|
88 | return 'unclean' | |
85 |
|
89 | |||
86 | return 'clean' |
|
90 | return 'clean' |
@@ -20,6 +20,8 b' Authors:' | |||||
20 |
|
20 | |||
21 | import sys |
|
21 | import sys | |
22 |
|
22 | |||
|
23 | from IPython.utils.py3compat import cast_bytes_py2 | |||
|
24 | ||||
23 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
24 | # Code |
|
26 | # Code | |
25 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
@@ -28,7 +30,7 b' class appended_to_syspath(object):' | |||||
28 | """A context for appending a directory to sys.path for a second.""" |
|
30 | """A context for appending a directory to sys.path for a second.""" | |
29 |
|
31 | |||
30 | def __init__(self, dir): |
|
32 | def __init__(self, dir): | |
31 | self.dir = dir |
|
33 | self.dir = cast_bytes_py2(dir, sys.getdefaultencoding()) | |
32 |
|
34 | |||
33 | def __enter__(self): |
|
35 | def __enter__(self): | |
34 | if self.dir not in sys.path: |
|
36 | if self.dir not in sys.path: | |
@@ -50,7 +52,7 b' class prepended_to_syspath(object):' | |||||
50 | """A context for prepending a directory to sys.path for a second.""" |
|
52 | """A context for prepending a directory to sys.path for a second.""" | |
51 |
|
53 | |||
52 | def __init__(self, dir): |
|
54 | def __init__(self, dir): | |
53 | self.dir = dir |
|
55 | self.dir = cast_bytes_py2(dir, sys.getdefaultencoding()) | |
54 |
|
56 | |||
55 | def __enter__(self): |
|
57 | def __enter__(self): | |
56 | if self.dir not in sys.path: |
|
58 | if self.dir not in sys.path: |
General Comments 0
You need to be logged in to leave comments.
Login now