From 3eae1372ccbb69baaed5a33c4ad4c745615ba9a8 2010-01-30 00:24:13 From: Brian Granger Date: 2010-01-30 00:24:13 Subject: [PATCH] Work to address the review comments on Fernando's branch. * Added comment about Magic(object) (r1224) * Moved InteractiveTB.set_mode from IPythonApp -> InteractiveShell (r1229) * Moved pylabtools.py to IPython/lib (r1229) * Cleaned up comments and copyrights in testing (r1233) * Added comment about ip.shell._ofind (r1237) * Removed "Bye." from quitter (r1240). * Refactored and removed :mod:`IPython.utils.genutils` and :mod:`IPython.utils.platutils`. These modules have been replaced by topical focused modules in :mod:`IPython.utils`. * Refactored tests in :mod:`IPython.utils.tests`. * Moved :func:`IPython.testing.tools.temp_pyfile` to :mod:`IPython.utils.io`. * Moved :func:`IPython.testing.tools.cmd2argv` to :func:`IPython.testing.tools.pycmd2argv` and documented the fact that this only works with Python based command line programs. * Created a new :func:`IPython.utils.path.get_ipython_module_path` to use in finding paths to IPython modules. --- diff --git a/IPython/__init__.py b/IPython/__init__.py index 90d7565..759f958 100755 --- a/IPython/__init__.py +++ b/IPython/__init__.py @@ -30,14 +30,14 @@ if sys.version[0:3] < '2.5': # Make it easy to import extensions - they are always directly on pythonpath. -# Therefore, non-IPython modules can be added to extensions directory +# Therefore, non-IPython modules can be added to extensions directory. +# This should probably be in ipapp.py. sys.path.append(os.path.join(os.path.dirname(__file__), "extensions")) #----------------------------------------------------------------------------- # Setup the top level names #----------------------------------------------------------------------------- -# In some cases, these are causing circular imports. from .config.loader import Config from .core import release from .core.application import Application diff --git a/IPython/config/default/kernel_config.py b/IPython/config/default/kernel_config.py deleted file mode 100644 index 0eec0dd..0000000 --- a/IPython/config/default/kernel_config.py +++ /dev/null @@ -1,62 +0,0 @@ -from os.path import join -pjoin = join - -from IPython.utils.genutils import get_ipython_dir, get_security_dir -security_dir = get_security_dir() - - -ENGINE_LOGFILE = '' - -ENGINE_FURL_FILE = 'ipcontroller-engine.furl' - -MPI_CONFIG_MPI4PY = """from mpi4py import MPI as mpi -mpi.size = mpi.COMM_WORLD.Get_size() -mpi.rank = mpi.COMM_WORLD.Get_rank() -""" - -MPI_CONFIG_PYTRILINOS = """from PyTrilinos import Epetra -class SimpleStruct: -pass -mpi = SimpleStruct() -mpi.rank = 0 -mpi.size = 0 -""" - -MPI_DEFAULT = '' - -CONTROLLER_LOGFILE = '' -CONTROLLER_IMPORT_STATEMENT = '' -CONTROLLER_REUSE_FURLS = False - -ENGINE_TUB_IP = '' -ENGINE_TUB_PORT = 0 -ENGINE_TUB_LOCATION = '' -ENGINE_TUB_SECURE = True -ENGINE_TUB_CERT_FILE = 'ipcontroller-engine.pem' -ENGINE_FC_INTERFACE = 'IPython.kernel.enginefc.IFCControllerBase' -ENGINE_FURL_FILE = 'ipcontroller-engine.furl' - -CONTROLLER_INTERFACES = dict( - TASK = dict( - CONTROLLER_INTERFACE = 'IPython.kernel.task.ITaskController', - FC_INTERFACE = 'IPython.kernel.taskfc.IFCTaskController', - FURL_FILE = pjoin(security_dir, 'ipcontroller-tc.furl') - ), - MULTIENGINE = dict( - CONTROLLER_INTERFACE = 'IPython.kernel.multiengine.IMultiEngine', - FC_INTERFACE = 'IPython.kernel.multienginefc.IFCSynchronousMultiEngine', - FURL_FILE = pjoin(security_dir, 'ipcontroller-mec.furl') - ) -) - -CLIENT_TUB_IP = '' -CLIENT_TUB_PORT = 0 -CLIENT_TUB_LOCATION = '' -CLIENT_TUB_SECURE = True -CLIENT_TUB_CERT_FILE = 'ipcontroller-client.pem' - -CLIENT_INTERFACES = dict( - TASK = dict(FURL_FILE = 'ipcontroller-tc.furl'), - MULTIENGINE = dict(FURLFILE='ipcontroller-mec.furl') -) - diff --git a/IPython/config/loader.py b/IPython/config/loader.py index 9198c37..0b521a9 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -23,7 +23,7 @@ import os import sys from IPython.external import argparse -from IPython.utils.genutils import filefind +from IPython.utils.path import filefind #----------------------------------------------------------------------------- # Exceptions diff --git a/IPython/core/alias.py b/IPython/core/alias.py index 3dbb8cd..1afe854 100644 --- a/IPython/core/alias.py +++ b/IPython/core/alias.py @@ -28,9 +28,9 @@ import sys from IPython.core.component import Component from IPython.core.splitinput import split_user_input -from IPython.utils.traitlets import CBool, List, Instance -from IPython.utils.genutils import error +from IPython.utils.traitlets import List from IPython.utils.autoattr import auto_attr +from IPython.utils.warn import warn, error #----------------------------------------------------------------------------- # Utilities diff --git a/IPython/core/application.py b/IPython/core/application.py index 9a88ccc..cc0c08c 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -33,7 +33,7 @@ import os import sys from IPython.core import release, crashhandler -from IPython.utils.genutils import get_ipython_dir, get_ipython_package_dir +from IPython.utils.path import get_ipython_dir, get_ipython_package_dir from IPython.config.loader import ( PyFileConfigLoader, ArgParseConfigLoader, diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 049e982..07fd037 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -69,19 +69,20 @@ used, and this module (and the readline module) are silently inactive. import __builtin__ import __main__ import glob +import inspect import itertools import keyword import os import re import shlex import sys -import types -import IPython.utils.rlineimpl as readline from IPython.core.error import TryNext from IPython.core.prefilter import ESC_MAGIC from IPython.utils import generics -from IPython.utils.genutils import debugx, dir2 +from IPython.utils.frame import debugx +from IPython.utils.dir2 import dir2 +import IPython.utils.rlineimpl as readline #----------------------------------------------------------------------------- # Globals @@ -216,7 +217,6 @@ class Completer: with a __getattr__ hook is evaluated. """ - import re #print 'Completer->attr_matches, txt=%r' % text # dbg # Another option, seems to work great. Catches things like ''. diff --git a/IPython/core/component.py b/IPython/core/component.py index 42c6118..1ee9509 100644 --- a/IPython/core/component.py +++ b/IPython/core/component.py @@ -27,7 +27,7 @@ from weakref import WeakValueDictionary from IPython.utils.importstring import import_item from IPython.config.loader import Config from IPython.utils.traitlets import ( - HasTraitlets, TraitletError, MetaHasTraitlets, Instance, This + HasTraitlets, MetaHasTraitlets, Instance, This ) diff --git a/IPython/core/crashhandler.py b/IPython/core/crashhandler.py index f5c80b8..df15f10 100644 --- a/IPython/core/crashhandler.py +++ b/IPython/core/crashhandler.py @@ -26,7 +26,7 @@ from pprint import pformat # Our own from IPython.core import release from IPython.core import ultratb -from IPython.utils.genutils import sys_info +from IPython.utils.sysinfo import sys_info from IPython.external.Itpl import itpl diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py index 45fe177..151a4b1 100644 --- a/IPython/core/debugger.py +++ b/IPython/core/debugger.py @@ -26,15 +26,13 @@ http://www.python.org/2.2.3/license.html""" #***************************************************************************** import bdb -import cmd import linecache -import os import sys from IPython.utils import PyColorize from IPython.core import ipapi from IPython.utils import coloransi -from IPython.utils.genutils import Term +from IPython.utils.io import Term from IPython.core.excolors import exception_colors # See if we can use pydb. diff --git a/IPython/core/display_trap.py b/IPython/core/display_trap.py index c0f0834..d5e5e83 100644 --- a/IPython/core/display_trap.py +++ b/IPython/core/display_trap.py @@ -24,8 +24,6 @@ import sys from IPython.core.component import Component -from IPython.utils.autoattr import auto_attr - #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- diff --git a/IPython/core/embed.py b/IPython/core/embed.py index a43342a..16d6c78 100644 --- a/IPython/core/embed.py +++ b/IPython/core/embed.py @@ -24,6 +24,7 @@ Notes #----------------------------------------------------------------------------- from __future__ import with_statement +import __main__ import sys from contextlib import nested @@ -33,7 +34,7 @@ from IPython.core.iplib import InteractiveShell from IPython.core.ipapp import load_default_config from IPython.utils.traitlets import Bool, Str, CBool -from IPython.utils.genutils import ask_yes_no +from IPython.utils.io import ask_yes_no #----------------------------------------------------------------------------- diff --git a/IPython/core/excolors.py b/IPython/core/excolors.py index f36186b..14451d5 100644 --- a/IPython/core/excolors.py +++ b/IPython/core/excolors.py @@ -10,8 +10,6 @@ Color schemes for exception handling code in IPython. # the file COPYING, distributed as part of this software. #***************************************************************************** -#**************************************************************************** -# Required modules from IPython.utils.coloransi import ColorSchemeTable, TermColors, ColorScheme def exception_colors(): diff --git a/IPython/core/history.py b/IPython/core/history.py index a508f9c..e21a197 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -5,7 +5,8 @@ import fnmatch import os -from IPython.utils.genutils import Term, ask_yes_no, warn +from IPython.utils.io import Term, ask_yes_no +from IPython.utils.warn import warn from IPython.core import ipapi def magic_history(self, parameter_s = ''): diff --git a/IPython/core/hooks.py b/IPython/core/hooks.py index 79eb5ba..97990c8 100644 --- a/IPython/core/hooks.py +++ b/IPython/core/hooks.py @@ -43,9 +43,12 @@ somewhere in your configuration files or ipython command line. import os, bisect import sys -from IPython.utils.genutils import Term, shell + from pprint import PrettyPrinter +from IPython.utils.io import Term +from IPython.utils.process import shell + from IPython.core.error import TryNext # List here all the default hooks. For now it's just the editor functions diff --git a/IPython/core/ipapi.py b/IPython/core/ipapi.py index 8ee88a2..461aa5a 100644 --- a/IPython/core/ipapi.py +++ b/IPython/core/ipapi.py @@ -18,8 +18,6 @@ has been made into a component, this module will be sent to deathrow. # Imports #----------------------------------------------------------------------------- -from IPython.core.error import TryNext, UsageError, IPythonCoreError - #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- diff --git a/IPython/core/ipapp.py b/IPython/core/ipapp.py index 95dd2c1..ce0e9db 100755 --- a/IPython/core/ipapp.py +++ b/IPython/core/ipapp.py @@ -36,7 +36,7 @@ from IPython.config.loader import ( # NoConfigDefault, ) from IPython.lib import inputhook -from IPython.utils.genutils import filefind, get_ipython_dir +from IPython.utils.path import filefind, get_ipython_dir from . import usage #----------------------------------------------------------------------------- @@ -499,7 +499,6 @@ class IPythonApp(Application): self._run_exec_lines() self._run_exec_files() self._run_cmd_line_code() - self._configure_xmode() def _enable_gui_pylab(self): """Enable GUI event loop integration, taking pylab into account.""" @@ -624,11 +623,6 @@ class IPythonApp(Application): self.log.warn("Error in executing file in user namespace: %s" % fname) self.shell.showtraceback() - def _configure_xmode(self): - # XXX - shouldn't this be read from the config? I'm still a little - # lost with all the details of handling the new config guys... - self.shell.InteractiveTB.set_mode(mode=self.shell.xmode) - def start_app(self): if self.master_config.Global.interact: self.log.debug("Starting IPython's mainloop...") diff --git a/IPython/core/iplib.py b/IPython/core/iplib.py index 7fc2f8b..db47ba5 100644 --- a/IPython/core/iplib.py +++ b/IPython/core/iplib.py @@ -20,7 +20,6 @@ from __future__ import with_statement from __future__ import absolute_import import __builtin__ -import StringIO import bdb import codeop import exceptions @@ -47,29 +46,35 @@ from IPython.core.logger import Logger from IPython.core.magic import Magic from IPython.core.prefilter import PrefilterManager from IPython.core.prompts import CachedOutput -from IPython.core.pylabtools import pylab_activate from IPython.core.usage import interactive_usage, default_banner +import IPython.core.hooks from IPython.external.Itpl import ItplNS from IPython.lib.inputhook import enable_gui from IPython.lib.backgroundjobs import BackgroundJobManager +from IPython.lib.pylabtools import pylab_activate from IPython.utils import PyColorize from IPython.utils import pickleshare -from IPython.utils.genutils import get_ipython_dir +from IPython.utils.doctestreload import doctest_reload from IPython.utils.ipstruct import Struct -from IPython.utils.platutils import toggle_set_term_title, set_term_title +from IPython.utils.io import Term, ask_yes_no +from IPython.utils.path import get_home_dir, get_ipython_dir, HomeDirError +from IPython.utils.process import ( + abbrev_cwd, + getoutput, + getoutputerror +) +# import IPython.utils.rlineimpl as readline from IPython.utils.strdispatch import StrDispatch from IPython.utils.syspathcontext import prepended_to_syspath - -# XXX - need to clean up this import * line -from IPython.utils.genutils import * - -# from IPython.utils import growl -# growl.start("IPython") - +from IPython.utils.terminal import toggle_set_term_title, set_term_title +from IPython.utils.warn import warn, error, fatal from IPython.utils.traitlets import ( Int, Str, CBool, CaselessStrEnum, Enum, List, Unicode ) +# from IPython.utils import growl +# growl.start("IPython") + #----------------------------------------------------------------------------- # Globals #----------------------------------------------------------------------------- @@ -658,7 +663,6 @@ class InteractiveShell(Component, Magic): self.strdispatchers = {} # Set all default hooks, defined in the IPython.hooks module. - import IPython.core.hooks hooks = IPython.core.hooks for hook_name in hooks.__all__: # default hooks have priority 100, i.e. low; user hooks should have @@ -1164,7 +1168,9 @@ class InteractiveShell(Component, Magic): Convert func into callable that saves & restores history around the call """ - if not self.has_readline: + if self.has_readline: + from IPython.utils import rlineimpl as readline + else: return func def wrapper(): @@ -1198,6 +1204,9 @@ class InteractiveShell(Component, Magic): # and add any custom exception handlers the user may have specified self.set_custom_exc(*custom_exceptions) + # Set the exception mode + self.InteractiveTB.set_mode(mode=self.xmode) + def set_custom_exc(self,exc_tuple,handler): """set_custom_exc(exc_tuple,handler) diff --git a/IPython/core/macro.py b/IPython/core/macro.py index 7ca39ed..8fb52a6 100644 --- a/IPython/core/macro.py +++ b/IPython/core/macro.py @@ -7,7 +7,7 @@ # the file COPYING, distributed as part of this software. #***************************************************************************** -from IPython.utils.genutils import Term +from IPython.utils.io import Term from IPython.core.autocall import IPyAutocall class Macro(IPyAutocall): diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 615f545..5c581c0 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -1,35 +1,33 @@ -# -*- coding: utf-8 -*- +# encoding: utf-8 """Magic functions for InteractiveShell. """ -#***************************************************************************** -# Copyright (C) 2001 Janko Hauser and -# Copyright (C) 2001-2006 Fernando Perez -# +#----------------------------------------------------------------------------- +# Copyright (C) 2001 Janko Hauser and +# Copyright (C) 2001-2007 Fernando Perez +# Copyright (C) 2008-2009 The IPython Development Team + # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. -#***************************************************************************** +#----------------------------------------------------------------------------- -#**************************************************************************** -# Modules and globals +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- -# Python standard modules import __builtin__ import bdb import inspect import os -import pdb -import pydoc import sys import shutil import re -import tempfile import time -import cPickle as pickle import textwrap +import types from cStringIO import StringIO from getopt import getopt,GetoptError -from pprint import pprint, pformat +from pprint import pformat # cProfile was added in Python2.5 try: @@ -42,10 +40,7 @@ except ImportError: except ImportError: profile = pstats = None -# Homebrewed import IPython -import IPython.utils.generics - from IPython.core import debugger, oinspect from IPython.core.error import TryNext from IPython.core.error import UsageError @@ -53,20 +48,24 @@ from IPython.core.fakemodule import FakeModule from IPython.core.macro import Macro from IPython.core.page import page from IPython.core.prefilter import ESC_MAGIC -from IPython.core.pylabtools import mpl_runner +from IPython.lib.pylabtools import mpl_runner from IPython.lib.inputhook import enable_gui -from IPython.external.Itpl import Itpl, itpl, printpl,itplns +from IPython.external.Itpl import itpl, printpl from IPython.testing import decorators as testdec -from IPython.utils import platutils -from IPython.utils import wildcard -from IPython.utils.PyColorize import Parser +from IPython.utils.io import Term, file_read, nlprint +from IPython.utils.path import get_py_filename +from IPython.utils.process import arg_split, abbrev_cwd +from IPython.utils.terminal import set_term_title +from IPython.utils.text import LSString, SList, StringTypes +from IPython.utils.timing import clock, clock2 +from IPython.utils.warn import warn, error from IPython.utils.ipstruct import Struct +import IPython.utils.generics -# XXX - We need to switch to explicit imports here with genutils -from IPython.utils.genutils import * - -#*************************************************************************** +#----------------------------------------------------------------------------- # Utility functions +#----------------------------------------------------------------------------- + def on_off(tag): """Return an ON/OFF string for a 1/0 input. Simple utility function.""" return ['OFF','ON'][tag] @@ -94,6 +93,9 @@ def compress_dhist(dh): # on construction of the main InteractiveShell object. Something odd is going # on with super() calls, Component and the MRO... For now leave it as-is, but # eventually this needs to be clarified. +# BG: This is because InteractiveShell inherits from this, but is itself a +# Component. This messes up the MRO in some way. The fix is that we need to +# make Magic a component that InteractiveShell does not subclass. class Magic: """Magic functions for InteractiveShell. @@ -277,7 +279,7 @@ python-profiler package from non-free.""") def arg_err(self,func): """Print docstring if incorrect arguments were passed""" print 'Error in arguments:' - print OInspect.getdoc(func) + print oinspect.getdoc(func) def format_latex(self,strng): """Format a string for latex inclusion.""" @@ -1170,7 +1172,7 @@ Currently the magic system has the following functions:\n""" started = logger.logstart(logfname,loghead,logmode, log_output,timestamp,log_raw_input) except: - rc.opts.logfile = old_logfile + self.shell.logfile = old_logfile warn("Couldn't start log: %s" % sys.exc_info()[1]) else: # log input history up to this point, optionally interleaving @@ -2811,7 +2813,7 @@ Defaulting color scheme to 'NoColor'""" try: os.chdir(os.path.expanduser(ps)) if self.shell.term_title: - platutils.set_term_title('IPython: ' + abbrev_cwd()) + set_term_title('IPython: ' + abbrev_cwd()) except OSError: print sys.exc_info()[1] else: @@ -2824,7 +2826,7 @@ Defaulting color scheme to 'NoColor'""" else: os.chdir(self.shell.home_dir) if self.shell.term_title: - platutils.set_term_title('IPython: ' + '~') + set_term_title('IPython: ' + '~') cwd = os.getcwd() dhist = self.shell.user_ns['_dh'] diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index a0cfb54..91ac5a5 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -27,10 +27,11 @@ import sys import types # IPython's own -from IPython.utils import PyColorize -from IPython.utils.genutils import indent, Term from IPython.core.page import page from IPython.external.Itpl import itpl +from IPython.utils import PyColorize +from IPython.utils.io import Term +from IPython.utils.text import indent from IPython.utils.wildcard import list_namespace from IPython.utils.coloransi import * diff --git a/IPython/core/page.py b/IPython/core/page.py index f07c1b5..7226db7 100644 --- a/IPython/core/page.py +++ b/IPython/core/page.py @@ -30,15 +30,15 @@ rid of that dependency, we could move it there. import os import re import sys +import tempfile from IPython.core import ipapi from IPython.core.error import TryNext -from IPython.utils.genutils import ( - chop, Term, USE_CURSES -) - -if os.name == "nt": - from IPython.utils.winconsole import get_console_size +from IPython.utils.cursesimport import use_curses +from IPython.utils.data import chop +from IPython.utils.io import Term +from IPython.utils.process import xsys +from IPython.utils.terminal import get_terminal_size #----------------------------------------------------------------------------- @@ -47,7 +47,7 @@ if os.name == "nt": esc_re = re.compile(r"(\x1b[^m]+m)") -def page_dumb(strng,start=0,screen_lines=25): +def page_dumb(strng, start=0, screen_lines=25): """Very dumb 'pager' in Python, for when nothing else works. Only moves forward, same interface as page(), except for pager_cmd and @@ -69,8 +69,8 @@ def page_dumb(strng,start=0,screen_lines=25): last_escape = esc_list[-1] print >>Term.cout, last_escape + os.linesep.join(screens[-1]) -#---------------------------------------------------------------------------- -def page(strng,start=0,screen_lines=0,pager_cmd = None): + +def page(strng, start=0, screen_lines=0, pager_cmd=None): """Print a string, piping through a pager after a certain length. The screen_lines parameter specifies the number of *usable* lines of your @@ -93,7 +93,7 @@ def page(strng,start=0,screen_lines=0,pager_cmd = None): # Some routines may auto-compute start offsets incorrectly and pass a # negative value. Offset to 0 for robustness. - start = max(0,start) + start = max(0, start) # first, try the hook ip = ipapi.get() @@ -120,19 +120,16 @@ def page(strng,start=0,screen_lines=0,pager_cmd = None): # terminals. If someone later feels like refining it, it's not hard. numlines = max(num_newlines,int(len_str/80)+1) - if os.name == "nt": - screen_lines_def = get_console_size(defaulty=25)[1] - else: - screen_lines_def = 25 # default value if we can't auto-determine + screen_lines_def = get_terminal_size()[1] # auto-determine screen size if screen_lines <= 0: if TERM=='xterm' or TERM=='xterm-color': - use_curses = USE_CURSES + local_use_curses = use_curses else: # curses causes problems on many terminals other than xterm. - use_curses = False - if use_curses: + local_use_curses = False + if local_use_curses: import termios import curses # There is a bug in curses, where *sometimes* it fails to properly @@ -201,8 +198,8 @@ def page(strng,start=0,screen_lines=0,pager_cmd = None): if retval is not None: page_dumb(strng,screen_lines=screen_lines) -#---------------------------------------------------------------------------- -def page_file(fname,start = 0, pager_cmd = None): + +def page_file(fname, start=0, pager_cmd=None): """Page a file, using an optional pager command and starting line. """ @@ -221,12 +218,12 @@ def page_file(fname,start = 0, pager_cmd = None): except: print 'Unable to show file',`fname` -#---------------------------------------------------------------------------- -def get_pager_cmd(pager_cmd = None): - """Return a pager command. - Makes some attempts at finding an OS-correct one.""" +def get_pager_cmd(pager_cmd=None): + """Return a pager command. + Makes some attempts at finding an OS-correct one. + """ if os.name == 'posix': default_pager_cmd = 'less -r' # -r for color control sequences elif os.name in ['nt','dos']: @@ -239,8 +236,8 @@ def get_pager_cmd(pager_cmd = None): pager_cmd = default_pager_cmd return pager_cmd -#----------------------------------------------------------------------------- -def get_pager_start(pager,start): + +def get_pager_start(pager, start): """Return the string for paging files with an offset. This is the '+N' argument which less and more (under Unix) accept. @@ -255,8 +252,8 @@ def get_pager_start(pager,start): start_string = '' return start_string -#---------------------------------------------------------------------------- -# (X)emacs on W32 doesn't like to be bypassed with msvcrt.getch() + +# (X)emacs on win32 doesn't like to be bypassed with msvcrt.getch() if os.name == 'nt' and os.environ.get('TERM','dumb') != 'emacs': import msvcrt def page_more(): @@ -280,7 +277,7 @@ else: else: return True -#---------------------------------------------------------------------------- + def snip_print(str,width = 75,print_full = 0,header = ''): """Print a string snipping the midsection to fit in width. @@ -305,4 +302,5 @@ def snip_print(str,width = 75,print_full = 0,header = ''): if snip and print_full == 2: if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': page(str) - return snip \ No newline at end of file + return snip + diff --git a/IPython/core/prefilter.py b/IPython/core/prefilter.py index a7a4f10..d77fa69 100755 --- a/IPython/core/prefilter.py +++ b/IPython/core/prefilter.py @@ -27,10 +27,7 @@ Authors: import __builtin__ import codeop -import keyword -import os import re -import sys from IPython.core.alias import AliasManager from IPython.core.autocall import IPyAutocall @@ -39,7 +36,8 @@ from IPython.core.splitinput import split_user_input from IPython.core.page import page from IPython.utils.traitlets import List, Int, Any, Str, CBool, Bool -from IPython.utils.genutils import make_quoted_expr, Term +from IPython.utils.io import Term +from IPython.utils.text import make_quoted_expr from IPython.utils.autoattr import auto_attr #----------------------------------------------------------------------------- @@ -158,11 +156,12 @@ class LineInfo(object): without worrying about *further* damaging state. """ if not self._oinfo: + # ip.shell._ofind is actually on the Magic class! self._oinfo = ip.shell._ofind(self.ifun) return self._oinfo def __str__(self): - return "Lineinfo [%s|%s|%s]" %(self.pre,self.ifun,self.the_rest) + return "Lineinfo [%s|%s|%s]" %(self.pre, self.ifun, self.the_rest) #----------------------------------------------------------------------------- diff --git a/IPython/core/prompts.py b/IPython/core/prompts.py index 16aa422..2220fdb 100644 --- a/IPython/core/prompts.py +++ b/IPython/core/prompts.py @@ -12,23 +12,20 @@ Classes for handling input/output prompts. #***************************************************************************** #**************************************************************************** -# Required modules + import __builtin__ import os +import re import socket import sys -import time -# IPython's own -from IPython.utils import coloransi from IPython.core import release from IPython.external.Itpl import ItplNS from IPython.core.error import TryNext -from IPython.utils.ipstruct import Struct -from IPython.core.macro import Macro +from IPython.utils import coloransi import IPython.utils.generics - -from IPython.utils.genutils import * +from IPython.utils.warn import warn +from IPython.utils.io import Term #**************************************************************************** #Color schemes for Prompts. diff --git a/IPython/core/quitter.py b/IPython/core/quitter.py index 0bdaffb..19f7da0 100755 --- a/IPython/core/quitter.py +++ b/IPython/core/quitter.py @@ -19,7 +19,11 @@ Authors # Imports #----------------------------------------------------------------------------- -import sys + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + class Quitter(object): """Simple class to handle exit, similar to Python 2.5's. @@ -40,4 +44,4 @@ class Quitter(object): # Repr MUST return a string, else display like pprint hooks get confused def __repr__(self): self.shell.ask_exit() - return 'Bye.' + return '' diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 758d6c3..efcecf7 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -8,19 +8,15 @@ from __future__ import absolute_import # Imports #----------------------------------------------------------------------------- -# stdlib import os import sys import tempfile import types from cStringIO import StringIO -# third-party import nose.tools as nt -# our own -from IPython.utils import genutils -from IPython.utils.platutils import find_cmd, get_long_path_name +from IPython.utils.path import get_long_path_name from IPython.testing import decorators as dec from IPython.testing import tools as tt diff --git a/IPython/core/tests/test_run.py b/IPython/core/tests/test_run.py index 79c167a..35d49ac 100644 --- a/IPython/core/tests/test_run.py +++ b/IPython/core/tests/test_run.py @@ -12,17 +12,12 @@ from __future__ import absolute_import # Imports #----------------------------------------------------------------------------- -# stdlib import os import sys import tempfile -# third-party import nose.tools as nt -# our own -from IPython.utils.platutils import find_cmd -from IPython.utils import genutils from IPython.testing import decorators as dec from IPython.testing import tools as tt @@ -142,10 +137,10 @@ class TestMagicRunSimple(tt.TempFileMixin): _ip.runlines('t = isinstance(f(), foo)') nt.assert_true(_ip.user_ns['t']) - # We have to skip these in win32 because genutils.getoutputerr() crashes, + # We have to skip these in win32 because getoutputerr() crashes, # due to the fact that subprocess does not support close_fds when # redirecting stdout/err. So unless someone who knows more tells us how to - # implement genutils.getoutputerr() in win32, we're stuck avoiding these. + # implement getoutputerr() in win32, we're stuck avoiding these. @dec.skip_win32 def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index c32fad9..404559f 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -93,9 +93,10 @@ from inspect import getsourcefile, getfile, getmodule,\ from IPython.utils import PyColorize from IPython.core import debugger, ipapi from IPython.core.display_trap import DisplayTrap -from IPython.utils.ipstruct import Struct from IPython.core.excolors import exception_colors -from IPython.utils.genutils import Term, uniq_stable, error, info +from IPython.utils.data import uniq_stable +from IPython.utils.io import Term +from IPython.utils.warn import info, error # Globals # amount of space to put line numbers before verbose tracebacks diff --git a/IPython/deathrow/GnuplotRuntime.py b/IPython/deathrow/GnuplotRuntime.py index e03cfe3..8d524e3 100644 --- a/IPython/deathrow/GnuplotRuntime.py +++ b/IPython/deathrow/GnuplotRuntime.py @@ -53,7 +53,7 @@ __all__ = ['Gnuplot','gp','gp_new','Data','File','Func','GridData', 'pm3d_config','eps_fix_bbox'] import os,tempfile,sys -from IPython.utils.genutils import getoutput +from IPython.utils.process import getoutput #--------------------------------------------------------------------------- # Notes on mouse support for Gnuplot.py diff --git a/IPython/deathrow/ipipe.py b/IPython/deathrow/ipipe.py index 74215bc..c440e6e 100644 --- a/IPython/deathrow/ipipe.py +++ b/IPython/deathrow/ipipe.py @@ -133,10 +133,10 @@ from IPython.external import simplegeneric from IPython.external import path try: - from IPython.utils import genutils + from IPython.utils.io import Term from IPython.utils import generics except ImportError: - genutils = None + Term = None generics = None from IPython.core import ipapi @@ -2168,7 +2168,7 @@ class idump(Display): self.datasepchar = "|" def display(self): - stream = genutils.Term.cout + stream = Term.cout allattrs = [] attrset = set() colwidths = {} diff --git a/IPython/deathrow/ipy_traits_completer.py b/IPython/deathrow/ipy_traits_completer.py index 2dfe620..ccf6d49 100644 --- a/IPython/deathrow/ipy_traits_completer.py +++ b/IPython/deathrow/ipy_traits_completer.py @@ -54,7 +54,7 @@ from enthought.traits import api as T # IPython imports from IPython.core.error import TryNext from IPython.core.ipapi import get as ipget -from IPython.utils.genutils import dir2 +from IPython.utils.dir2 import dir2 try: set except: diff --git a/IPython/deathrow/twshell.py b/IPython/deathrow/twshell.py index 6ad78fe..3270d65 100644 --- a/IPython/deathrow/twshell.py +++ b/IPython/deathrow/twshell.py @@ -14,7 +14,9 @@ from IPython.core.iplib import InteractiveShell from IPython.utils.ipstruct import Struct import Queue,thread,threading,signal from signal import signal, SIGINT -from IPython.utils.genutils import Term,warn,error,flag_calls, ask_yes_no +from IPython.utils.io import Term, ask_yes_no +from IPython.utils.warn import warn, error +from IPython.utils.decorators import flag_calls from IPython.core import shellglobals def install_gtk2(): diff --git a/IPython/extensions/pretty.py b/IPython/extensions/pretty.py index f6448e0..bb25c98 100644 --- a/IPython/extensions/pretty.py +++ b/IPython/extensions/pretty.py @@ -39,7 +39,7 @@ from IPython.core.error import TryNext from IPython.external import pretty from IPython.core.component import Component from IPython.utils.traitlets import Bool, List -from IPython.utils.genutils import Term +from IPython.utils.io import Term from IPython.utils.autoattr import auto_attr from IPython.utils.importstring import import_item diff --git a/IPython/external/mglob.py b/IPython/external/mglob.py index 1212c05..08f4194 100755 --- a/IPython/external/mglob.py +++ b/IPython/external/mglob.py @@ -213,7 +213,7 @@ def main(): print "\n".join(expand(sys.argv[1:])), def mglob_f(self, arg): - from IPython.utils.genutils import SList + from IPython.utils.text import SList if arg.strip(): return SList(expand(arg)) print "Please specify pattern!" diff --git a/IPython/frontend/prefilterfrontend.py b/IPython/frontend/prefilterfrontend.py index 6cb2997..f9e0aec 100644 --- a/IPython/frontend/prefilterfrontend.py +++ b/IPython/frontend/prefilterfrontend.py @@ -31,7 +31,7 @@ from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap -from IPython.utils.genutils import Term +from IPython.utils.io import Term from linefrontendbase import LineFrontEndBase, common_prefix diff --git a/IPython/gui/wx/ipshell_nonblocking.py b/IPython/gui/wx/ipshell_nonblocking.py index ee962b5..5e81216 100755 --- a/IPython/gui/wx/ipshell_nonblocking.py +++ b/IPython/gui/wx/ipshell_nonblocking.py @@ -25,7 +25,7 @@ from thread_ex import ThreadEx import IPython from IPython.core import iplib, ipapp -from IPython.utils import genutils +from IPython.utils.io import Term ############################################################################## class _Helper(object): @@ -141,11 +141,11 @@ class NonBlockingIPShell(object): #only one instance can be instanciated else tehre will be #cin/cout/cerr clash... if cin: - genutils.Term.cin = cin + Term.cin = cin if cout: - genutils.Term.cout = cout + Term.cout = cout if cerr: - genutils.Term.cerr = cerr + Term.cerr = cerr excepthook = sys.excepthook @@ -471,7 +471,7 @@ class NonBlockingIPShell(object): ''' orig_stdout = sys.stdout - sys.stdout = genutils.Term.cout + sys.stdout = Term.cout #self.sys_displayhook_ori = sys.displayhook #sys.displayhook = self.displayhook diff --git a/IPython/kernel/client.py b/IPython/kernel/client.py index 872ec3a..acb3cfa 100644 --- a/IPython/kernel/client.py +++ b/IPython/kernel/client.py @@ -27,7 +27,6 @@ The main classes in this module are: # Imports #----------------------------------------------------------------------------- -from cStringIO import StringIO import sys import warnings diff --git a/IPython/kernel/clientconnector.py b/IPython/kernel/clientconnector.py index ffa55d4..fca7e19 100644 --- a/IPython/kernel/clientconnector.py +++ b/IPython/kernel/clientconnector.py @@ -33,7 +33,7 @@ from IPython.kernel.twistedutil import ( sleep_deferred ) from IPython.utils.importstring import import_item -from IPython.utils.genutils import get_ipython_dir +from IPython.utils.path import get_ipython_dir from twisted.internet import defer from twisted.internet.defer import inlineCallbacks, returnValue diff --git a/IPython/kernel/clientinterfaces.py b/IPython/kernel/clientinterfaces.py index 248e511..362ae99 100644 --- a/IPython/kernel/clientinterfaces.py +++ b/IPython/kernel/clientinterfaces.py @@ -15,7 +15,7 @@ __docformat__ = "restructuredtext en" # Imports #------------------------------------------------------------------------------- -from zope.interface import Interface, implements +from zope.interface import Interface class IFCClientInterfaceProvider(Interface): diff --git a/IPython/kernel/clusterdir.py b/IPython/kernel/clusterdir.py index dcda0c6..7ed28ae 100755 --- a/IPython/kernel/clusterdir.py +++ b/IPython/kernel/clusterdir.py @@ -24,13 +24,14 @@ import warnings from twisted.python import log -from IPython.core import release from IPython.config.loader import PyFileConfigLoader from IPython.core.application import Application from IPython.core.component import Component -from IPython.utils.genutils import get_ipython_dir, get_ipython_package_dir -from IPython.utils.traitlets import Unicode, Bool -from IPython.utils import genutils +from IPython.utils.path import ( + get_ipython_package_dir, + expand_path +) +from IPython.utils.traitlets import Unicode #----------------------------------------------------------------------------- # Warnings control @@ -225,7 +226,7 @@ class ClusterDir(Component): The path of the cluster directory. This is expanded using :func:`IPython.utils.genutils.expand_path`. """ - cluster_dir = genutils.expand_path(cluster_dir) + cluster_dir = expand_path(cluster_dir) if not os.path.isdir(cluster_dir): raise ClusterDirError('Cluster directory not found: %s' % cluster_dir) return ClusterDir(cluster_dir) @@ -316,7 +317,7 @@ class ApplicationWithClusterDir(Application): cluster_dir = self.command_line_config.Global.cluster_dir except AttributeError: cluster_dir = self.default_config.Global.cluster_dir - cluster_dir = genutils.expand_path(cluster_dir) + cluster_dir = expand_path(cluster_dir) try: self.cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir) except ClusterDirError: @@ -389,7 +390,7 @@ class ApplicationWithClusterDir(Application): pdir = self.cluster_dir_obj.pid_dir self.pid_dir = config.Global.pid_dir = pdir self.log.info("Cluster directory set to: %s" % self.cluster_dir) - config.Global.work_dir = unicode(genutils.expand_path(config.Global.work_dir)) + config.Global.work_dir = unicode(expand_path(config.Global.work_dir)) # Change to the working directory. We do this just before construct # is called so all the components there have the right working dir. self.to_work_dir() diff --git a/IPython/kernel/contexts.py b/IPython/kernel/contexts.py index 2e9daa3..e8ccc8e 100644 --- a/IPython/kernel/contexts.py +++ b/IPython/kernel/contexts.py @@ -24,9 +24,7 @@ __docformat__ = "restructuredtext en" import linecache import sys -from twisted.internet.error import ConnectionRefusedError - -from IPython.core.ultratb import _fixed_getinnerframes, findsource +from IPython.core.ultratb import findsource from IPython.core import ipapi from IPython.kernel import error diff --git a/IPython/kernel/controllerservice.py b/IPython/kernel/controllerservice.py index 10ad03b..e8e30f4 100644 --- a/IPython/kernel/controllerservice.py +++ b/IPython/kernel/controllerservice.py @@ -37,20 +37,18 @@ __docformat__ = "restructuredtext en" # Imports #------------------------------------------------------------------------------- -import os, sys +import os from twisted.application import service -from twisted.internet import defer, reactor -from twisted.python import log, components +from twisted.python import log from zope.interface import Interface, implements, Attribute -import zope.interface as zi from IPython.kernel.engineservice import \ IEngineCore, \ IEngineSerialized, \ IEngineQueued -from IPython.utils.genutils import get_ipython_dir +from IPython.utils.path import get_ipython_dir from IPython.kernel import codeutil #------------------------------------------------------------------------------- diff --git a/IPython/kernel/core/prompts.py b/IPython/kernel/core/prompts.py index 1759df7..fc583ea 100644 --- a/IPython/kernel/core/prompts.py +++ b/IPython/kernel/core/prompts.py @@ -21,6 +21,8 @@ __docformat__ = "restructuredtext en" # Required modules import __builtin__ +import os +import re import socket import sys @@ -30,7 +32,8 @@ from IPython.external.Itpl import ItplNS from IPython.utils import coloransi from IPython.core import release from IPython.core.error import TryNext -from IPython.utils.genutils import * +from IPython.utils.io import Term +from IPython.utils.warn import warn import IPython.utils.generics #**************************************************************************** @@ -240,7 +243,7 @@ class BasePrompt(object): This must be called every time the color settings change, because the prompt_specials global may have changed.""" - import os,time # needed in locals for prompt string handling + import os, time # needed in locals for prompt string handling loc = locals() self.p_str = ItplNS('%s%s%s' % ('${self.sep}${self.col_p}', diff --git a/IPython/kernel/engineconnector.py b/IPython/kernel/engineconnector.py index dfa983f..36a12c4 100644 --- a/IPython/kernel/engineconnector.py +++ b/IPython/kernel/engineconnector.py @@ -17,8 +17,7 @@ import os import cPickle as pickle -from twisted.python import log, failure -from twisted.internet import defer +from twisted.python import log from twisted.internet.defer import inlineCallbacks, returnValue from IPython.kernel.fcutil import find_furl, validate_furl_or_file diff --git a/IPython/kernel/enginefc.py b/IPython/kernel/enginefc.py index ebeff5c..0439fdc 100644 --- a/IPython/kernel/enginefc.py +++ b/IPython/kernel/enginefc.py @@ -19,14 +19,11 @@ __docformat__ = "restructuredtext en" # Imports #------------------------------------------------------------------------------- -import os, time import cPickle as pickle from twisted.python import components, log, failure -from twisted.python.failure import Failure -from twisted.internet import defer, reactor, threads -from twisted.internet.interfaces import IProtocolFactory -from zope.interface import Interface, implements, Attribute +from twisted.internet import defer, threads +from zope.interface import Interface, implements from twisted.internet.base import DelayedCall DelayedCall.debug = True @@ -35,24 +32,20 @@ from foolscap import Referenceable, DeadReferenceError from foolscap.referenceable import RemoteReference from IPython.kernel.pbutil import packageFailure, unpackageFailure -from IPython.kernel.util import printer -from IPython.kernel.twistedutil import gatherBoth -from IPython.kernel import newserialized -from IPython.kernel.error import ProtocolError -from IPython.kernel import controllerservice from IPython.kernel.controllerservice import IControllerBase -from IPython.kernel.engineservice import \ - IEngineBase, \ - IEngineQueued, \ - EngineService, \ +from IPython.kernel.engineservice import ( + IEngineBase, + IEngineQueued, StrictDict -from IPython.kernel.pickleutil import \ - can, \ - canDict, \ - canSequence, \ - uncan, \ - uncanDict, \ +) +from IPython.kernel.pickleutil import ( + can, + canDict, + canSequence, + uncan, + uncanDict, uncanSequence +) #------------------------------------------------------------------------------- diff --git a/IPython/kernel/ipcontrollerapp.py b/IPython/kernel/ipcontrollerapp.py index 7a2e9d2..7cffb54 100755 --- a/IPython/kernel/ipcontrollerapp.py +++ b/IPython/kernel/ipcontrollerapp.py @@ -18,20 +18,18 @@ The IPython controller application. from __future__ import with_statement import copy -import os import sys from twisted.application import service from twisted.internet import reactor from twisted.python import log -from IPython.config.loader import Config, NoConfigDefault -from IPython.core import release +from IPython.config.loader import Config from IPython.core.application import Application from IPython.kernel import controllerservice from IPython.kernel.clusterdir import ApplicationWithClusterDir from IPython.kernel.fcutil import FCServiceFactory -from IPython.utils.traitlets import Str, Instance, Unicode +from IPython.utils.traitlets import Instance, Unicode #----------------------------------------------------------------------------- # Default interfaces diff --git a/IPython/kernel/launcher.py b/IPython/kernel/launcher.py index 2f41211..cfbb82d 100644 --- a/IPython/kernel/launcher.py +++ b/IPython/kernel/launcher.py @@ -21,11 +21,15 @@ import sys from IPython.core.component import Component from IPython.external import Itpl -from IPython.utils.traitlets import Str, Int, List, Unicode, Enum -from IPython.utils.platutils import find_cmd -from IPython.kernel.twistedutil import gatherBoth, make_deferred, sleep_deferred +from IPython.utils.traitlets import Str, Int, List, Unicode +from IPython.utils.path import get_ipython_module_path +from IPython.utils.process import find_cmd, pycmd2argv +from IPython.kernel.twistedutil import ( + gatherBoth, + make_deferred, + sleep_deferred +) from IPython.kernel.winhpcjob import ( - WinHPCJob, WinHPCTask, IPControllerTask, IPEngineTask, IPControllerJob, IPEngineSetJob ) @@ -38,46 +42,23 @@ from twisted.internet.error import ProcessDone, ProcessTerminated from twisted.python import log from twisted.python.failure import Failure + #----------------------------------------------------------------------------- -# Utilities +# Paths to the kernel apps #----------------------------------------------------------------------------- -def find_controller_cmd(): - """Find the command line ipcontroller program in a cross platform way.""" - if sys.platform == 'win32': - # This logic is needed because the ipcontroller script doesn't - # always get installed in the same way or in the same location. - from IPython.kernel import ipcontrollerapp - script_location = ipcontrollerapp.__file__.replace('.pyc', '.py') - # The -u option here turns on unbuffered output, which is required - # on Win32 to prevent wierd conflict and problems with Twisted. - # Also, use sys.executable to make sure we are picking up the - # right python exe. - cmd = [sys.executable, '-u', script_location] - else: - # ipcontroller has to be on the PATH in this case. - cmd = ['ipcontroller'] - return cmd - - -def find_engine_cmd(): - """Find the command line ipengine program in a cross platform way.""" - if sys.platform == 'win32': - # This logic is needed because the ipengine script doesn't - # always get installed in the same way or in the same location. - from IPython.kernel import ipengineapp - script_location = ipengineapp.__file__.replace('.pyc', '.py') - # The -u option here turns on unbuffered output, which is required - # on Win32 to prevent wierd conflict and problems with Twisted. - # Also, use sys.executable to make sure we are picking up the - # right python exe. - cmd = [sys.executable, '-u', script_location] - else: - # ipcontroller has to be on the PATH in this case. - cmd = ['ipengine'] - return cmd +ipcluster_cmd_argv = pycmd2argv(get_ipython_module_path( + 'IPython.kernel.ipclusterapp' +)) +ipengine_cmd_argv = pycmd2argv(get_ipython_module_path( + 'IPython.kernel.ipengineapp' +)) + +ipcontroller_cmd_argv = pycmd2argv(get_ipython_module_path( + 'IPython.kernel.ipcontrollerapp' +)) #----------------------------------------------------------------------------- # Base launchers and errors @@ -333,7 +314,7 @@ class LocalProcessLauncher(BaseLauncher): class LocalControllerLauncher(LocalProcessLauncher): """Launch a controller as a regular external process.""" - controller_cmd = List(find_controller_cmd(), config=True) + controller_cmd = List(ipcontroller_cmd_argv, config=True) # Command line arguments to ipcontroller. controller_args = List(['--log-to-file','--log-level', '40'], config=True) @@ -351,7 +332,7 @@ class LocalControllerLauncher(LocalProcessLauncher): class LocalEngineLauncher(LocalProcessLauncher): """Launch a single engine as a regular externall process.""" - engine_cmd = List(find_engine_cmd(), config=True) + engine_cmd = List(ipengine_cmd_argv, config=True) # Command line arguments for ipengine. engine_args = List( ['--log-to-file','--log-level', '40'], config=True @@ -462,7 +443,7 @@ class MPIExecLauncher(LocalProcessLauncher): class MPIExecControllerLauncher(MPIExecLauncher): """Launch a controller using mpiexec.""" - controller_cmd = List(find_controller_cmd(), config=True) + controller_cmd = List(ipcontroller_cmd_argv, config=True) # Command line arguments to ipcontroller. controller_args = List(['--log-to-file','--log-level', '40'], config=True) n = Int(1, config=False) @@ -481,7 +462,7 @@ class MPIExecControllerLauncher(MPIExecLauncher): class MPIExecEngineSetLauncher(MPIExecLauncher): - engine_cmd = List(find_engine_cmd(), config=True) + engine_cmd = List(ipengine_cmd_argv, config=True) # Command line arguments for ipengine. engine_args = List( ['--log-to-file','--log-level', '40'], config=True @@ -831,28 +812,10 @@ class PBSEngineSetLauncher(PBSLauncher): #----------------------------------------------------------------------------- -def find_ipcluster_cmd(): - """Find the command line ipcluster program in a cross platform way.""" - if sys.platform == 'win32': - # This logic is needed because the ipcluster script doesn't - # always get installed in the same way or in the same location. - from IPython.kernel import ipclusterapp - script_location = ipclusterapp.__file__.replace('.pyc', '.py') - # The -u option here turns on unbuffered output, which is required - # on Win32 to prevent wierd conflict and problems with Twisted. - # Also, use sys.executable to make sure we are picking up the - # right python exe. - cmd = [sys.executable, '-u', script_location] - else: - # ipcontroller has to be on the PATH in this case. - cmd = ['ipcluster'] - return cmd - - class IPClusterLauncher(LocalProcessLauncher): """Launch the ipcluster program in an external process.""" - ipcluster_cmd = List(find_ipcluster_cmd(), config=True) + ipcluster_cmd = List(ipcluster_cmd_argv, config=True) # Command line arguments to pass to ipcluster. ipcluster_args = List( ['--clean-logs', '--log-to-file', '--log-level', '40'], config=True) diff --git a/IPython/kernel/map.py b/IPython/kernel/map.py index f9ce2f8..6d2d9ea 100644 --- a/IPython/kernel/map.py +++ b/IPython/kernel/map.py @@ -21,7 +21,7 @@ __docformat__ = "restructuredtext en" import types -from IPython.utils.genutils import flatten as genutil_flatten +from IPython.utils.data import flatten as utils_flatten #------------------------------------------------------------------------------- # Figure out which array packages are present and their array types @@ -87,7 +87,7 @@ class Map: return m['module'].concatenate(listOfPartitions) # Next try for Python sequence types if isinstance(testObject, (types.ListType, types.TupleType)): - return genutil_flatten(listOfPartitions) + return utils_flatten(listOfPartitions) # If we have scalars, just return listOfPartitions return listOfPartitions diff --git a/IPython/kernel/mapper.py b/IPython/kernel/mapper.py index e732b53..28f2545 100644 --- a/IPython/kernel/mapper.py +++ b/IPython/kernel/mapper.py @@ -18,8 +18,7 @@ __docformat__ = "restructuredtext en" from types import FunctionType from zope.interface import Interface, implements from IPython.kernel.task import MapTask -from IPython.kernel.twistedutil import DeferredList, gatherBoth -from IPython.kernel.util import printer +from IPython.kernel.twistedutil import gatherBoth from IPython.kernel.error import collect_exceptions #---------------------------------------------------------------------------- diff --git a/IPython/kernel/multiengine.py b/IPython/kernel/multiengine.py index bdeba67..bb520b6 100644 --- a/IPython/kernel/multiengine.py +++ b/IPython/kernel/multiengine.py @@ -27,24 +27,17 @@ __docformat__ = "restructuredtext en" # Imports #------------------------------------------------------------------------------- -from new import instancemethod -from types import FunctionType - -from twisted.application import service from twisted.internet import defer, reactor from twisted.python import log, components, failure -from zope.interface import Interface, implements, Attribute +from zope.interface import Interface, implements -from IPython.utils import growl -from IPython.kernel.util import printer from IPython.kernel.twistedutil import gatherBoth -from IPython.kernel import map as Map from IPython.kernel import error from IPython.kernel.pendingdeferred import PendingDeferredManager, two_phase -from IPython.kernel.controllerservice import \ - ControllerAdapterBase, \ - ControllerService, \ +from IPython.kernel.controllerservice import ( + ControllerAdapterBase, IControllerBase +) #------------------------------------------------------------------------------- diff --git a/IPython/kernel/multienginefc.py b/IPython/kernel/multienginefc.py index 30de28d..1af1edf 100644 --- a/IPython/kernel/multienginefc.py +++ b/IPython/kernel/multienginefc.py @@ -22,12 +22,11 @@ from types import FunctionType from zope.interface import Interface, implements from twisted.internet import defer -from twisted.python import components, failure, log +from twisted.python import components, failure from foolscap import Referenceable from IPython.kernel import error -from IPython.kernel.util import printer from IPython.kernel import map as Map from IPython.kernel.parallelfunction import ParallelFunction from IPython.kernel.mapper import ( @@ -36,14 +35,15 @@ from IPython.kernel.mapper import ( IMapper ) from IPython.kernel.twistedutil import gatherBoth -from IPython.kernel.multiengine import (MultiEngine, +from IPython.kernel.multiengine import ( IMultiEngine, IFullSynchronousMultiEngine, ISynchronousMultiEngine) -from IPython.kernel.multiengineclient import wrapResultList from IPython.kernel.pendingdeferred import PendingDeferredManager -from IPython.kernel.pickleutil import (can, canDict, - canSequence, uncan, uncanDict, uncanSequence) +from IPython.kernel.pickleutil import ( + canDict, + canSequence, uncanDict, uncanSequence +) from IPython.kernel.clientinterfaces import ( IFCClientInterfaceProvider, diff --git a/IPython/kernel/pbutil.py b/IPython/kernel/pbutil.py index 6ce8050..da98b82 100644 --- a/IPython/kernel/pbutil.py +++ b/IPython/kernel/pbutil.py @@ -19,7 +19,6 @@ import cPickle as pickle from twisted.python.failure import Failure from twisted.python import failure -import threading, sys from IPython.kernel import pbconfig from IPython.kernel.error import PBMessageSizeError, UnpickleableException @@ -58,7 +57,7 @@ def unpackageFailure(r): result = pickle.loads(r[8:]) except pickle.PickleError: return failure.Failure( \ - FailureUnpickleable("Could not unpickle failure.")) + UnpickleableException("Could not unpickle failure.")) else: return result return r diff --git a/IPython/kernel/pendingdeferred.py b/IPython/kernel/pendingdeferred.py index 91abdfb..b741f36 100644 --- a/IPython/kernel/pendingdeferred.py +++ b/IPython/kernel/pendingdeferred.py @@ -22,15 +22,11 @@ __docformat__ = "restructuredtext en" # Imports #------------------------------------------------------------------------------- -from twisted.application import service -from twisted.internet import defer, reactor -from twisted.python import log, components, failure -from zope.interface import Interface, implements, Attribute +from twisted.internet import defer +from twisted.python import failure -from IPython.kernel.twistedutil import gatherBoth from IPython.kernel import error from IPython.external import guid -from IPython.utils import growl class PendingDeferredManager(object): """A class to track pending deferreds. diff --git a/IPython/kernel/pickleutil.py b/IPython/kernel/pickleutil.py index 087a61c..faed1c5 100644 --- a/IPython/kernel/pickleutil.py +++ b/IPython/kernel/pickleutil.py @@ -16,7 +16,6 @@ __docformat__ = "restructuredtext en" #------------------------------------------------------------------------------- from types import FunctionType -from twisted.python import log class CannedObject(object): pass diff --git a/IPython/kernel/task.py b/IPython/kernel/task.py index 924d052..ec0c70d 100644 --- a/IPython/kernel/task.py +++ b/IPython/kernel/task.py @@ -19,19 +19,18 @@ __docformat__ = "restructuredtext en" # Tell nose to skip the testing of this module __test__ = {} -import copy, time +import time from types import FunctionType -import zope.interface as zi, string +import zope.interface as zi from twisted.internet import defer, reactor from twisted.python import components, log, failure -from IPython.kernel.util import printer from IPython.kernel import engineservice as es, error from IPython.kernel import controllerservice as cs -from IPython.kernel.twistedutil import gatherBoth, DeferredList +from IPython.kernel.twistedutil import DeferredList -from IPython.kernel.pickleutil import can, uncan, CannedFunction +from IPython.kernel.pickleutil import can, uncan #----------------------------------------------------------------------------- # Definition of the Task objects diff --git a/IPython/kernel/taskclient.py b/IPython/kernel/taskclient.py index 69225fb..3215da4 100644 --- a/IPython/kernel/taskclient.py +++ b/IPython/kernel/taskclient.py @@ -19,10 +19,10 @@ __docformat__ = "restructuredtext en" #------------------------------------------------------------------------------- from zope.interface import Interface, implements -from twisted.python import components, log +from twisted.python import components from IPython.kernel.twistedutil import blockingCallFromThread -from IPython.kernel import task, error +from IPython.kernel import task from IPython.kernel.mapper import ( SynchronousTaskMapper, ITaskMapperFactory, diff --git a/IPython/kernel/taskfc.py b/IPython/kernel/taskfc.py index c559f64..69726a5 100644 --- a/IPython/kernel/taskfc.py +++ b/IPython/kernel/taskfc.py @@ -19,17 +19,14 @@ __docformat__ = "restructuredtext en" #------------------------------------------------------------------------------- import cPickle as pickle -import xmlrpclib, copy from zope.interface import Interface, implements from twisted.internet import defer -from twisted.python import components, failure +from twisted.python import components from foolscap import Referenceable -from IPython.kernel.twistedutil import blockingCallFromThread -from IPython.kernel import error, task as taskmodule, taskclient -from IPython.kernel.pickleutil import can, uncan +from IPython.kernel import task as taskmodule from IPython.kernel.clientinterfaces import ( IFCClientInterfaceProvider, IBlockingClientAdaptor diff --git a/IPython/kernel/twistedutil.py b/IPython/kernel/twistedutil.py index 712a83b..ff73438 100644 --- a/IPython/kernel/twistedutil.py +++ b/IPython/kernel/twistedutil.py @@ -15,7 +15,7 @@ #----------------------------------------------------------------------------- import os, sys -import threading, Queue, atexit +import threading, Queue import twisted from twisted.internet import defer, reactor diff --git a/IPython/kernel/winhpcjob.py b/IPython/kernel/winhpcjob.py index de1680d..c7dc1c9 100644 --- a/IPython/kernel/winhpcjob.py +++ b/IPython/kernel/winhpcjob.py @@ -23,12 +23,10 @@ import re import uuid from xml.etree import ElementTree as ET -from xml.dom import minidom from IPython.core.component import Component -from IPython.external import Itpl from IPython.utils.traitlets import ( - Str, Int, List, Unicode, Instance, + Str, Int, List, Instance, Enum, Bool, CStr ) diff --git a/IPython/lib/backgroundjobs.py b/IPython/lib/backgroundjobs.py index 6f49522..aec4526 100644 --- a/IPython/lib/backgroundjobs.py +++ b/IPython/lib/backgroundjobs.py @@ -31,7 +31,7 @@ import sys import threading from IPython.core.ultratb import AutoFormattedTB -from IPython.utils.genutils import warn,error +from IPython.utils.warn import warn, error class BackgroundJobManager: """Class to manage a pool of backgrounded threaded jobs. diff --git a/IPython/lib/demo.py b/IPython/lib/demo.py index d5989e6..53a3ea0 100644 --- a/IPython/lib/demo.py +++ b/IPython/lib/demo.py @@ -176,7 +176,8 @@ import shlex import sys from IPython.utils.PyColorize import Parser -from IPython.utils.genutils import marquee, file_read, file_readlines, Term +from IPython.utils.io import file_read, file_readlines, Term +from IPython.utils.text import marquee __all__ = ['Demo','IPythonDemo','LineDemo','IPythonLineDemo','DemoError'] @@ -543,7 +544,7 @@ class ClearMixin(object): """Method called before executing each block. This one simply clears the screen.""" - from IPython.utils.platutils import term_clear + from IPython.utils.terminal import term_clear term_clear() class ClearDemo(ClearMixin,Demo): diff --git a/IPython/core/pylabtools.py b/IPython/lib/pylabtools.py similarity index 99% rename from IPython/core/pylabtools.py rename to IPython/lib/pylabtools.py index f56131a..73a27cf 100644 --- a/IPython/core/pylabtools.py +++ b/IPython/lib/pylabtools.py @@ -12,10 +12,12 @@ Fernando Perez. # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. #----------------------------------------------------------------------------- + #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- -from IPython.utils.genutils import flag_calls + +from IPython.utils.decorators import flag_calls #----------------------------------------------------------------------------- # Main classes and functions diff --git a/IPython/quarantine/InterpreterExec.py b/IPython/quarantine/InterpreterExec.py index 70bebac..9faba79 100644 --- a/IPython/quarantine/InterpreterExec.py +++ b/IPython/quarantine/InterpreterExec.py @@ -50,7 +50,7 @@ del InteractiveShell,prefilter_shell # Provide pysh and further shell-oriented services import os,sys,shutil -from IPython.utils.genutils import system,shell,getoutput,getoutputerror +from IPython.utils.process import system,shell,getoutput,getoutputerror # Short aliases for getting shell output as a string and a list sout = getoutput diff --git a/IPython/quarantine/ext_rescapture.py b/IPython/quarantine/ext_rescapture.py index 6f5731a..eb0c391 100644 --- a/IPython/quarantine/ext_rescapture.py +++ b/IPython/quarantine/ext_rescapture.py @@ -10,6 +10,7 @@ var = !ls from IPython.core import ipapi from IPython.core.error import TryNext +from IPython.utils.text import make_quoted_expr from IPython.utils.genutils import * ip = ipapi.get() diff --git a/IPython/quarantine/ipy_greedycompleter.py b/IPython/quarantine/ipy_greedycompleter.py index f928e45..1804338 100644 --- a/IPython/quarantine/ipy_greedycompleter.py +++ b/IPython/quarantine/ipy_greedycompleter.py @@ -12,7 +12,7 @@ do the same in default completer. from IPython.core import ipapi from IPython.core.error import TryNext from IPython.utils import generics -from IPython.utils.genutils import dir2 +from IPython.utils.dir2 import dir2 def attr_matches(self, text): """Compute matches when text contains a dot. diff --git a/IPython/quarantine/ipy_jot.py b/IPython/quarantine/ipy_jot.py index 5b2e65e..16fd4f2 100644 --- a/IPython/quarantine/ipy_jot.py +++ b/IPython/quarantine/ipy_jot.py @@ -16,6 +16,7 @@ import pickleshare import inspect,pickle,os,sys,textwrap from IPython.core.fakemodule import FakeModule from IPython.utils.ipstruct import Struct +from IPython.utils.warn import error def refresh_variables(ip, key=None): diff --git a/IPython/quarantine/ipy_pydb.py b/IPython/quarantine/ipy_pydb.py index 278a336..67b45f0 100644 --- a/IPython/quarantine/ipy_pydb.py +++ b/IPython/quarantine/ipy_pydb.py @@ -1,6 +1,6 @@ import inspect from IPython.core import ipapi -from IPython.utils.genutils import arg_split +from IPython.utils.process import arg_split ip = ipapi.get() from IPython.core import debugger diff --git a/IPython/quarantine/jobctrl.py b/IPython/quarantine/jobctrl.py index 9a38ce5..7518a52 100644 --- a/IPython/quarantine/jobctrl.py +++ b/IPython/quarantine/jobctrl.py @@ -45,10 +45,9 @@ from subprocess import * import os,shlex,sys,time import threading,Queue -from IPython.utils import genutils - from IPython.core import ipapi from IPython.core.error import TryNext +from IPython.utils.text import make_quoted_expr if os.name == 'nt': def kill_process(pid): @@ -126,8 +125,8 @@ def jobctrl_prefilter_f(self,line): line = ip.expand_aliases(fn,rest) if not _jobq: - return 'get_ipython().startjob(%s)' % genutils.make_quoted_expr(line) - return 'get_ipython().jobq(%s)' % genutils.make_quoted_expr(line) + return 'get_ipython().startjob(%s)' % make_quoted_expr(line) + return 'get_ipython().jobq(%s)' % make_quoted_expr(line) raise TryNext diff --git a/IPython/testing/__init__.py b/IPython/testing/__init__.py index 830585c..ea70b45 100644 --- a/IPython/testing/__init__.py +++ b/IPython/testing/__init__.py @@ -1,6 +1,17 @@ """Testing support (tools to test IPython itself). """ +#----------------------------------------------------------------------------- +# Copyright (C) 2009 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Functions +#----------------------------------------------------------------------------- + # User-level entry point for testing def test(): """Run the entire IPython test suite. diff --git a/IPython/testing/_doctest26.py b/IPython/testing/_doctest26.py index b3b3e5f..e30c024 100644 --- a/IPython/testing/_doctest26.py +++ b/IPython/testing/_doctest26.py @@ -4,6 +4,17 @@ This is just so we can use 2.6 features when running in 2.5, the code below is copied verbatim from the stdlib's collections and doctest modules. """ +#----------------------------------------------------------------------------- +# Copyright (C) 2009 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + from keyword import iskeyword as _iskeyword from operator import itemgetter as _itemgetter import sys as _sys diff --git a/IPython/testing/_paramtestpy2.py b/IPython/testing/_paramtestpy2.py index 07e3a9a..d9a05d9 100644 --- a/IPython/testing/_paramtestpy2.py +++ b/IPython/testing/_paramtestpy2.py @@ -1,10 +1,17 @@ """Implementation of the parametric test support for Python 2.x """ + +#----------------------------------------------------------------------------- +# Copyright (C) 2009 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- -# Stdlib import unittest from compiler.consts import CO_GENERATOR diff --git a/IPython/testing/_paramtestpy3.py b/IPython/testing/_paramtestpy3.py index 0e16a36..200ca0d 100644 --- a/IPython/testing/_paramtestpy3.py +++ b/IPython/testing/_paramtestpy3.py @@ -3,11 +3,18 @@ Thanks for the py3 version to Robert Collins, from the Testing in Python mailing list. """ + +#----------------------------------------------------------------------------- +# Copyright (C) 2009 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- -# Stdlib import unittest from unittest import TestSuite diff --git a/IPython/testing/globalipapp.py b/IPython/testing/globalipapp.py index cd3c235..55067df 100644 --- a/IPython/testing/globalipapp.py +++ b/IPython/testing/globalipapp.py @@ -9,18 +9,22 @@ done. from __future__ import absolute_import #----------------------------------------------------------------------------- -# Module imports +# Copyright (C) 2009 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports #----------------------------------------------------------------------------- -# From the standard library import __builtin__ import commands -import new import os import sys from . import tools -from IPython.utils.genutils import Term #----------------------------------------------------------------------------- # Functions @@ -35,7 +39,7 @@ class py_file_finder(object): self.test_filename = test_filename def __call__(self,name): - from IPython.utils.genutils import get_py_filename + from IPython.utils.path import get_py_filename try: return get_py_filename(name) except IOError: diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 946d2c0..593f46f 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -17,13 +17,19 @@ will change in the future. """ #----------------------------------------------------------------------------- -# Module imports +# Copyright (C) 2009 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports #----------------------------------------------------------------------------- # Stdlib import os import os.path as path -import platform import signal import sys import subprocess @@ -50,11 +56,11 @@ import nose.plugins.builtin from nose.core import TestProgram # Our own imports -from IPython.core import release -from IPython.utils import genutils -from IPython.utils.platutils import find_cmd, FindCmdError +from IPython.utils.path import get_ipython_module_path +from IPython.utils.process import find_cmd, pycmd2argv +from IPython.utils.sysinfo import sys_info + from IPython.testing import globalipapp -from IPython.testing import tools from IPython.testing.plugin.ipdoctest import IPythonDoctest pjoin = path.join @@ -124,7 +130,7 @@ have['gobject'] = test_for('gobject') def report(): """Return a string with a summary report of test-related variables.""" - out = [ genutils.sys_info() ] + out = [ sys_info() ] out.append('\nRunning from an installed IPython: %s\n' % INSTALLED) @@ -198,18 +204,12 @@ def make_exclude(): if not have['objc']: exclusions.append(ipjoin('frontend', 'cocoa')) - if not sys.platform == 'win32': - exclusions.append(ipjoin('utils', 'platutils_win32')) - # These have to be skipped on win32 because the use echo, rm, cd, etc. # See ticket https://bugs.launchpad.net/bugs/366982 if sys.platform == 'win32': exclusions.append(ipjoin('testing', 'plugin', 'test_exampleip')) exclusions.append(ipjoin('testing', 'plugin', 'dtexample')) - if not os.name == 'posix': - exclusions.append(ipjoin('utils', 'platutils_posix')) - if not have['pexpect']: exclusions.extend([ipjoin('scripts', 'irunner'), ipjoin('lib', 'irunner')]) @@ -256,19 +256,19 @@ class IPTester(object): p = os.path if runner == 'iptest': if INSTALLED: - self.runner = tools.cmd2argv( - p.abspath(find_cmd('iptest'))) + sys.argv[1:] + iptest_app = get_ipython_module_path('IPython.testing.iptest') + self.runner = pycmd2argv(iptest_app) + sys.argv[1:] else: # Find our own 'iptest' script OS-level entry point. Don't # look system-wide, so we are sure we pick up *this one*. And # pass through to subprocess call our own sys.argv ippath = p.abspath(p.join(p.dirname(__file__),'..','..')) script = p.join(ippath, 'iptest.py') - self.runner = tools.cmd2argv(script) + sys.argv[1:] + self.runner = pycmd2argv(script) + sys.argv[1:] else: # For trial, it needs to be installed system-wide - self.runner = tools.cmd2argv(p.abspath(find_cmd('trial'))) + self.runner = pycmd2argv(p.abspath(find_cmd('trial'))) if params is None: params = [] if isinstance(params, str): diff --git a/IPython/testing/ipunittest.py b/IPython/testing/ipunittest.py index d4a7609..e593c74 100644 --- a/IPython/testing/ipunittest.py +++ b/IPython/testing/ipunittest.py @@ -31,7 +31,6 @@ from __future__ import absolute_import # the file COPYING, distributed as part of this software. #----------------------------------------------------------------------------- - #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- diff --git a/IPython/testing/mkdoctests.py b/IPython/testing/mkdoctests.py index 4ea9335..bfec99e 100644 --- a/IPython/testing/mkdoctests.py +++ b/IPython/testing/mkdoctests.py @@ -38,7 +38,7 @@ import tempfile # IPython-specific libraries from IPython.lib import irunner -from IPython.utils.genutils import fatal +from IPython.utils.warn import fatal class IndentOut(object): """A simple output stream that indents all output by a fixed amount. diff --git a/IPython/testing/nosepatch.py b/IPython/testing/nosepatch.py index 1065a3e..2458e39 100644 --- a/IPython/testing/nosepatch.py +++ b/IPython/testing/nosepatch.py @@ -5,10 +5,25 @@ Once this is fixed in upstream nose we can disable it. Note: merely importing this module causes the monkeypatch to be applied.""" +#----------------------------------------------------------------------------- +# Copyright (C) 2009 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + import unittest import nose.loader from inspect import ismethod, isfunction +#----------------------------------------------------------------------------- +# Classes and functions +#----------------------------------------------------------------------------- + def getTestCaseNames(self, testCaseClass): """Override to select with selector, unless config.getTestCaseNamesCompat is True diff --git a/IPython/testing/parametric.py b/IPython/testing/parametric.py index b1bf243..fe8a52a 100644 --- a/IPython/testing/parametric.py +++ b/IPython/testing/parametric.py @@ -5,10 +5,27 @@ parametric code. We just need to double-check that the new code doesn't clash with Twisted (we know it works with nose and unittest). """ -__all__ = ['parametric','Parametric'] +#----------------------------------------------------------------------------- +# Copyright (C) 2009 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + from twisted.trial.unittest import TestCase +#----------------------------------------------------------------------------- +# Classes and functions +#----------------------------------------------------------------------------- + +__all__ = ['parametric','Parametric'] + + def partial(f, *partial_args, **partial_kwargs): """Generate a partial class method. @@ -20,6 +37,7 @@ def partial(f, *partial_args, **partial_kwargs): return partial_func + def parametric(f): """Mark f as a parametric test. @@ -27,6 +45,7 @@ def parametric(f): f._parametric = True return classmethod(f) + def Parametric(cls): """Register parametric tests with a class. @@ -56,3 +75,4 @@ def Parametric(cls): # rename test generator so it isn't called again by nose test_gen.im_func.func_name = '__done_' + test_name + diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py index ab08cff..c29528b 100644 --- a/IPython/testing/tools.py +++ b/IPython/testing/tools.py @@ -15,22 +15,22 @@ Authors - Fernando Perez """ -#***************************************************************************** -# Copyright (C) 2009 The IPython Development Team +from __future__ import absolute_import + +#----------------------------------------------------------------------------- +# Copyright (C) 2009 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. -#***************************************************************************** +#----------------------------------------------------------------------------- #----------------------------------------------------------------------------- -# Required modules and packages +# Imports #----------------------------------------------------------------------------- -from __future__ import absolute_import import os import re import sys -import tempfile try: # These tools are used by parts of the runtime, so we make the nose @@ -41,7 +41,9 @@ try: except ImportError: has_nose = False -from IPython.utils import genutils, platutils +from IPython.utils.process import find_cmd, getoutputerror +from IPython.utils.text import list_strings +from IPython.utils.io import temp_pyfile from . import decorators as dec @@ -107,7 +109,7 @@ def full_path(startPath,files): ['/a.txt'] """ - files = genutils.list_strings(files) + files = list_strings(files) base = os.path.split(startPath)[0] return [ os.path.join(base,f) for f in files ] @@ -156,63 +158,6 @@ def parse_test_output(txt): parse_test_output.__test__ = False -def cmd2argv(cmd): - r"""Take the path of a command and return a list (argv-style). - - For a given path ``cmd``, this returns [cmd] if cmd's extension is .exe, - .com or .bat, and ['python', cmd] otherwise. - - This is mostly a Windows utility, to deal with the fact that the scripts in - Windows get wrapped in .exe entry points, so we have to call them - differently. - - Parameters - ---------- - cmd : string - The path of the command. - - Returns - ------- - argv-style list. - - Examples - -------- - In [2]: cmd2argv('/usr/bin/ipython') - Out[2]: ['python', '/usr/bin/ipython'] - - In [3]: cmd2argv(r'C:\Python26\Scripts\ipython.exe') - Out[3]: ['C:\\Python26\\Scripts\\ipython.exe'] - """ - ext = os.path.splitext(cmd)[1] - if ext in ['.exe', '.com', '.bat']: - return [cmd] - else: - return ['python', cmd] - - -def temp_pyfile(src, ext='.py'): - """Make a temporary python file, return filename and filehandle. - - Parameters - ---------- - src : string or list of strings (no need for ending newlines if list) - Source code to be written to the file. - - ext : optional, string - Extension for the generated file. - - Returns - ------- - (filename, open filehandle) - It is the caller's responsibility to close the open file and unlink it. - """ - fname = tempfile.mkstemp(ext)[1] - f = open(fname,'w') - f.write(src) - f.flush() - return fname, f - - def default_argv(): """Return a valid default argv for creating testing instances of ipython""" @@ -256,7 +201,7 @@ def ipexec(fname, options=None): # suite can be run from the source tree without an installed IPython p = os.path if INSTALLED: - ipython_cmd = platutils.find_cmd('ipython') + ipython_cmd = find_cmd('ipython') else: ippath = p.abspath(p.join(p.dirname(__file__),'..','..')) ipython_script = p.join(ippath, 'ipython.py') @@ -265,7 +210,7 @@ def ipexec(fname, options=None): full_fname = p.join(test_dir, fname) full_cmd = '%s %s %s' % (ipython_cmd, cmdargs, full_fname) #print >> sys.stderr, 'FULL CMD:', full_cmd # dbg - return genutils.getoutputerror(full_cmd) + return getoutputerror(full_cmd) def ipexec_validate(fname, expected_out, expected_err='', diff --git a/IPython/testing/util.py b/IPython/testing/util.py index 5c4253f..b8de077 100644 --- a/IPython/testing/util.py +++ b/IPython/testing/util.py @@ -1,23 +1,24 @@ # encoding: utf-8 """This file contains utility classes for performing tests with Deferreds. """ -__docformat__ = "restructuredtext en" -#------------------------------------------------------------------------------- -# Copyright (C) 2005 Fernando Perez -# Brian E Granger -# Benjamin Ragan-Kelley +#----------------------------------------------------------------------------- +# Copyright (C) 2009 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. -#------------------------------------------------------------------------------- +#----------------------------------------------------------------------------- -#------------------------------------------------------------------------------- +#----------------------------------------------------------------------------- # Imports -#------------------------------------------------------------------------------- +#----------------------------------------------------------------------------- from twisted.trial import unittest from twisted.internet import defer +#----------------------------------------------------------------------------- +# Classes and functions +#----------------------------------------------------------------------------- + class DeferredTestCase(unittest.TestCase): def assertDeferredEquals(self, deferred, expectedResult, diff --git a/IPython/utils/DPyGetOpt.py b/IPython/utils/DPyGetOpt.py deleted file mode 100644 index f4b918e..0000000 --- a/IPython/utils/DPyGetOpt.py +++ /dev/null @@ -1,690 +0,0 @@ -# -*- coding: utf-8 -*- -"""DPyGetOpt -- Demiurge Python GetOptions Module - -This module is modeled after perl's Getopt::Long module-- which -is, in turn, modeled after GNU's extended getopt() function. - -Upon instantiation, the option specification should be a sequence -(list) of option definitions. - -Options that take no arguments should simply contain the name of -the option. If a ! is post-pended, the option can be negated by -prepending 'no'; ie 'debug!' specifies that -debug and -nodebug -should be accepted. - -Mandatory arguments to options are specified using a postpended -'=' + a type specifier. '=s' specifies a mandatory string -argument, '=i' specifies a mandatory integer argument, and '=f' -specifies a mandatory real number. In all cases, the '=' can be -substituted with ':' to specify that the argument is optional. - -Dashes '-' in option names are allowed. - -If an option has the character '@' postpended (after the -argumentation specification), it can appear multiple times within -each argument list that is processed. The results will be stored -in a list. - -The option name can actually be a list of names separated by '|' -characters; ie-- 'foo|bar|baz=f@' specifies that all -foo, -bar, -and -baz options that appear on within the parsed argument list -must have a real number argument and that the accumulated list -of values will be available under the name 'foo' -""" - -#***************************************************************************** -# -# Copyright (c) 2001 Bill Bumgarner -# -# -# Published under the terms of the MIT license, hereby reproduced: -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. -# -#***************************************************************************** - -__author__ = 'Bill Bumgarner ' -__license__ = 'MIT' -__version__ = '1.2' - -# Modified to use re instead of regex and regsub modules. -# 2001/5/7, Jonathan Hogg - -import re -import string -import sys -import types - -class Error(Exception): - """Base class for exceptions in the DPyGetOpt module.""" - -class ArgumentError(Error): - """Exception indicating an error in the arguments passed to - DPyGetOpt.processArguments.""" - -class SpecificationError(Error): - """Exception indicating an error with an option specification.""" - -class TerminationError(Error): - """Exception indicating an error with an option processing terminator.""" - -specificationExpr = re.compile('(?P.)(?P.)(?P@?)') - -ArgRequired = 'Requires an Argument' -ArgOptional = 'Argument Optional' - -# The types modules is not used for these identifiers because there -# is no identifier for 'boolean' or 'generic' -StringArgType = 'String Argument Type' -IntegerArgType = 'Integer Argument Type' -RealArgType = 'Real Argument Type' -BooleanArgType = 'Boolean Argument Type' -GenericArgType = 'Generic Argument Type' - -# dictionary of conversion functions-- boolean and generic options -# do not accept arguments and do not need conversion functions; -# the identity function is used purely for convenience. -ConversionFunctions = { - StringArgType : lambda x: x, - IntegerArgType : string.atoi, - RealArgType : string.atof, - BooleanArgType : lambda x: x, - GenericArgType : lambda x: x, - } - -class DPyGetOpt: - - def __init__(self, spec = None, terminators = ['--']): - """ - Declare and intialize instance variables - - Yes, declaration is not necessary... but one of the things - I sorely miss from C/Obj-C is the concept of having an - interface definition that clearly declares all instance - variables and methods without providing any implementation - details. it is a useful reference! - - all instance variables are initialized to 0/Null/None of - the appropriate type-- not even the default value... - """ - -# sys.stderr.write(string.join(spec) + "\n") - - self.allowAbbreviations = 1 # boolean, 1 if abbreviations will - # be expanded - self.freeValues = [] # list, contains free values - self.ignoreCase = 0 # boolean, YES if ignoring case - self.needsParse = 0 # boolean, YES if need to reparse parameter spec - self.optionNames = {} # dict, all option names-- value is index of tuple - self.optionStartExpr = None # regexp defining the start of an option (ie; '-', '--') - self.optionTuples = [] # list o' tuples containing defn of options AND aliases - self.optionValues = {} # dict, option names (after alias expansion) -> option value(s) - self.orderMixed = 0 # boolean, YES if options can be mixed with args - self.posixCompliance = 0 # boolean, YES indicates posix like behaviour - self.spec = [] # list, raw specs (in case it must be reparsed) - self.terminators = terminators # list, strings that terminate argument processing - self.termValues = [] # list, values after terminator - self.terminator = None # full name of terminator that ended - # option processing - - # set up defaults - self.setPosixCompliance() - self.setIgnoreCase() - self.setAllowAbbreviations() - - # parse spec-- if present - if spec: - self.parseConfiguration(spec) - - def setPosixCompliance(self, aFlag = 0): - """ - Enables and disables posix compliance. - - When enabled, '+' can be used as an option prefix and free - values can be mixed with options. - """ - self.posixCompliance = aFlag - self.needsParse = 1 - - if self.posixCompliance: - self.optionStartExpr = re.compile('(--|-)(?P