diff --git a/IPython/core/prompts.py b/IPython/core/prompts.py index 1aeb5c1..473a591 100644 --- a/IPython/core/prompts.py +++ b/IPython/core/prompts.py @@ -147,7 +147,10 @@ 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 "$" + +# IronPython doesn't currently have os.getuid() even if +# os.name == 'posix'; 2/8/2014 +ROOT_SYMBOL = "#" if (os.name=='nt' or sys.platform=='cli' or os.getuid()==0) else "$" prompt_abbreviations = { # Prompt/history count diff --git a/IPython/external/decorator/_decorator.py b/IPython/external/decorator/_decorator.py index ed37b96..ef56922 100644 --- a/IPython/external/decorator/_decorator.py +++ b/IPython/external/decorator/_decorator.py @@ -30,6 +30,9 @@ """ Decorator module, see http://pypi.python.org/pypi/decorator for the documentation. + +NOTE: this is an IPython-patched version to work on IronPython. See + FIXED comment below. """ from __future__ import print_function @@ -139,7 +142,12 @@ class FunctionMaker(object): func.__defaults__ = getattr(self, 'defaults', ()) func.__kwdefaults__ = getattr(self, 'kwonlydefaults', None) func.__annotations__ = getattr(self, 'annotations', None) - callermodule = sys._getframe(3).f_globals.get('__name__', '?') + # FIXED: The following is try/excepted in IPython to work + # with IronPython. + try: + callermodule = sys._getframe(3).f_globals.get('__name__', '?') + except AttributeError: # IronPython _getframe only exists with FullFrames + callermodule = '?' func.__module__ = getattr(self, 'module', callermodule) func.__dict__.update(kw) diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index 44cebbb..a29cec0 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -18,6 +18,8 @@ try: import ctypes except ImportError: ctypes = None +except SystemError: # IronPython issue, 2/8/2014 + 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..eb69d3f --- /dev/null +++ b/IPython/utils/_process_cli.py @@ -0,0 +1,63 @@ +"""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. + +This file is largely untested. To become a full drop-in process +interface for IronPython will probably require you to help fill +in the details. +""" + +# 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.""" + paths = System.Environment.GetEnvironmentVariable("PATH").Split(os.pathsep) + 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