diff --git a/IPython/core/compilerop.py b/IPython/core/compilerop.py index e39ded6..9352375 100644 --- a/IPython/core/compilerop.py +++ b/IPython/core/compilerop.py @@ -45,7 +45,10 @@ import time # this is used as a bitmask to extract future-related code flags. PyCF_MASK = functools.reduce(operator.or_, (getattr(__future__, fname).compiler_flag - for fname in __future__.all_feature_names)) + for fname in __future__.all_feature_names + if (hasattr(__future__, fname) and + hasattr(getattr(__future__, fname), "compiler_flag"))), + 0) #----------------------------------------------------------------------------- # Local utilities diff --git a/IPython/core/completer.py b/IPython/core/completer.py index b1bc646..54f4b45 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -66,7 +66,10 @@ Notes: # Imports #----------------------------------------------------------------------------- -import __main__ +try: + import __main__ +except ImportError: + pass import glob import inspect import itertools diff --git a/IPython/core/prompts.py b/IPython/core/prompts.py index 1aeb5c1..fc8567c 100644 --- a/IPython/core/prompts.py +++ b/IPython/core/prompts.py @@ -147,7 +147,8 @@ HOME = os.path.realpath(HOME) USER = py3compat.str_to_unicode(os.environ.get("USER",'')) HOSTNAME = py3compat.str_to_unicode(socket.gethostname()) HOSTNAME_SHORT = HOSTNAME.split(".")[0] -ROOT_SYMBOL = "#" if (os.name=='nt' or os.getuid()==0) else "$" + +ROOT_SYMBOL = "#" if (os.name=='nt' or sys.platform=='cli' or os.getuid()==0) else "$" prompt_abbreviations = { # Prompt/history count diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index 44cebbb..b175377 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -18,6 +18,8 @@ try: import ctypes except ImportError: ctypes = None +except SystemError: + ctypes = None import os import sys from distutils.version import LooseVersion as V diff --git a/IPython/utils/_process_cli.py b/IPython/utils/_process_cli.py new file mode 100644 index 0000000..9068038 --- /dev/null +++ b/IPython/utils/_process_cli.py @@ -0,0 +1,61 @@ +""" +cli-specific implementation of process utilities. + +cli - Common Language Infrastructure for IronPython. Code + can run on any operating system. Check os.name for os- + specific settings. + +This file is only meant to be imported by process.py, not by end-users. +""" + +# Import cli libraries: +import clr +import System + +# Import Python libraries: +import os + +# Import IPython libraries: +from IPython.utils import py3compat +from ._process_common import arg_split + +def _find_cmd(cmd): + """Find the full path to a command using which.""" + os_path_sep = ":" if os.name == "posix" else ";" + paths = System.Environment.GetEnvironmentVariable("PATH").Split(os_path_sep) + for path in paths: + filename = os.path.join(path, cmd) + if System.IO.File.Exists(filename): + return py3compat.bytes_to_str(filename) + raise OSError("command %r not found" % cmd) + +def system(cmd): + """ + system(cmd) should work in a cli environment on Mac OSX, Linux, + and Windows + """ + psi = System.Diagnostics.ProcessStartInfo(cmd) + psi.RedirectStandardOutput = True + psi.RedirectStandardError = True + psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal + psi.UseShellExecute = False + # Start up process: + reg = System.Diagnostics.Process.Start(psi) + +def getoutput(cmd): + """ + getoutput(cmd) should work in a cli environment on Mac OSX, Linux, + and Windows + """ + psi = System.Diagnostics.ProcessStartInfo(cmd) + psi.RedirectStandardOutput = True + psi.RedirectStandardError = True + psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal + psi.UseShellExecute = False + # Start up process: + reg = System.Diagnostics.Process.Start(psi) + myOutput = reg.StandardOutput + output = myOutput.ReadToEnd() + myError = reg.StandardError + error = myError.ReadToEnd() + return output diff --git a/IPython/utils/io.py b/IPython/utils/io.py index 1932949..c3390ed 100644 --- a/IPython/utils/io.py +++ b/IPython/utils/io.py @@ -81,7 +81,7 @@ class IOStream: pass # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr -devnull = open(os.devnull, 'a') +devnull = open(os.devnull, 'w') stdin = IOStream(sys.stdin, fallback=devnull) stdout = IOStream(sys.stdout, fallback=devnull) stderr = IOStream(sys.stderr, fallback=devnull) diff --git a/IPython/utils/process.py b/IPython/utils/process.py index 826aa51..2e8d0f9 100644 --- a/IPython/utils/process.py +++ b/IPython/utils/process.py @@ -22,11 +22,12 @@ import shlex # Our own if sys.platform == 'win32': - from ._process_win32 import _find_cmd, system, getoutput, AvoidUNCPath, arg_split + from ._process_win32 import _find_cmd, system, getoutput, arg_split +elif sys.platform == 'cli': + from ._process_cli import _find_cmd, system, getoutput, arg_split else: from ._process_posix import _find_cmd, system, getoutput, arg_split - from ._process_common import getoutputerror, get_output_error_code, process_handler from . import py3compat