diff --git a/IPython/Extensions/ipy_completers.py b/IPython/Extensions/ipy_completers.py index d6a0aa6..e8c5eb5 100644 --- a/IPython/Extensions/ipy_completers.py +++ b/IPython/Extensions/ipy_completers.py @@ -335,6 +335,12 @@ def cd_completer(self, event): if not found: if os.path.isdir(relpath): return [relpath] + # if no completions so far, try bookmarks + bks = self.db.get('bookmarks',{}).keys() + bkmatches = [s for s in bks if s.startswith(event.symbol)] + if bkmatches: + return bkmatches + raise IPython.ipapi.TryNext diff --git a/IPython/Extensions/ipy_leo.py b/IPython/Extensions/ipy_leo.py deleted file mode 100644 index a45e150..0000000 --- a/IPython/Extensions/ipy_leo.py +++ /dev/null @@ -1,660 +0,0 @@ -""" ILeo - Leo plugin for IPython - - -""" -import IPython.ipapi -import IPython.genutils -import IPython.generics -from IPython.hooks import CommandChainDispatcher -import re -import UserDict -from IPython.ipapi import TryNext -import IPython.macro -import IPython.Shell - -_leo_push_history = set() - -def init_ipython(ipy): - """ This will be run by _ip.load('ipy_leo') - - Leo still needs to run update_commander() after this. - - """ - global ip - ip = ipy - IPython.Shell.hijack_tk() - ip.set_hook('complete_command', mb_completer, str_key = '%mb') - ip.expose_magic('mb',mb_f) - ip.expose_magic('lee',lee_f) - ip.expose_magic('leoref',leoref_f) - ip.expose_magic('lleo',lleo_f) - # Note that no other push command should EVER have lower than 0 - expose_ileo_push(push_mark_req, -1) - expose_ileo_push(push_cl_node,100) - # this should be the LAST one that will be executed, and it will never raise TryNext - expose_ileo_push(push_ipython_script, 1000) - expose_ileo_push(push_plain_python, 100) - expose_ileo_push(push_ev_node, 100) - ip.set_hook('pre_prompt_hook', ileo_pre_prompt_hook) - global wb - wb = LeoWorkbook() - ip.user_ns['wb'] = wb - - -first_launch = True - -def update_commander(new_leox): - """ Set the Leo commander to use - - This will be run every time Leo does ipython-launch; basically, - when the user switches the document he is focusing on, he should do - ipython-launch to tell ILeo what document the commands apply to. - - """ - - global first_launch - if first_launch: - show_welcome() - first_launch = False - - global c,g - c,g = new_leox.c, new_leox.g - print "Set Leo Commander:",c.frame.getTitle() - - # will probably be overwritten by user, but handy for experimentation early on - ip.user_ns['c'] = c - ip.user_ns['g'] = g - ip.user_ns['_leo'] = new_leox - - new_leox.push = push_position_from_leo - run_leo_startup_node() - -from IPython.external.simplegeneric import generic -import pprint - -def es(s): - g.es(s, tabName = 'IPython') - pass - -@generic -def format_for_leo(obj): - """ Convert obj to string representiation (for editing in Leo)""" - return pprint.pformat(obj) - -# Just an example - note that this is a bad to actually do! -#@format_for_leo.when_type(list) -#def format_list(obj): -# return "\n".join(str(s) for s in obj) - - -attribute_re = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') -def valid_attribute(s): - return attribute_re.match(s) - -_rootnode = None -def rootnode(): - """ Get ileo root node (@ipy-root) - - if node has become invalid or has not been set, return None - - Note that the root is the *first* @ipy-root item found - """ - global _rootnode - if _rootnode is None: - return None - if c.positionExists(_rootnode.p): - return _rootnode - _rootnode = None - return None - -def all_cells(): - global _rootnode - d = {} - r = rootnode() - if r is not None: - nodes = r.p.children_iter() - else: - nodes = c.allNodes_iter() - - for p in nodes: - h = p.headString() - if h.strip() == '@ipy-root': - # update root node (found it for the first time) - _rootnode = LeoNode(p) - # the next recursive call will use the children of new root - return all_cells() - - if h.startswith('@a '): - d[h.lstrip('@a ').strip()] = p.parent().copy() - elif not valid_attribute(h): - continue - d[h] = p.copy() - return d - -def eval_node(n): - body = n.b - if not body.startswith('@cl'): - # plain python repr node, just eval it - return ip.ev(n.b) - # @cl nodes deserve special treatment - first eval the first line (minus cl), then use it to call the rest of body - first, rest = body.split('\n',1) - tup = first.split(None, 1) - # @cl alone SPECIAL USE-> dump var to user_ns - if len(tup) == 1: - val = ip.ev(rest) - ip.user_ns[n.h] = val - es("%s = %s" % (n.h, repr(val)[:20] )) - return val - - cl, hd = tup - - xformer = ip.ev(hd.strip()) - es('Transform w/ %s' % repr(xformer)) - return xformer(rest, n) - -class LeoNode(object, UserDict.DictMixin): - """ Node in Leo outline - - Most important attributes (getters/setters available: - .v - evaluate node, can also be alligned - .b, .h - body string, headline string - .l - value as string list - - Also supports iteration, - - setitem / getitem (indexing): - wb.foo['key'] = 12 - assert wb.foo['key'].v == 12 - - Note the asymmetry on setitem and getitem! Also other - dict methods are available. - - .ipush() - run push-to-ipython - - Minibuffer command access (tab completion works): - - mb save-to-file - - """ - def __init__(self,p): - self.p = p.copy() - - def __str__(self): - return "" % str(self.p) - - __repr__ = __str__ - - def __get_h(self): return self.p.headString() - def __set_h(self,val): - c.setHeadString(self.p,val) - LeoNode.last_edited = self - c.redraw() - - h = property( __get_h, __set_h, doc = "Node headline string") - - def __get_b(self): return self.p.bodyString() - def __set_b(self,val): - c.setBodyString(self.p, val) - LeoNode.last_edited = self - c.redraw() - - b = property(__get_b, __set_b, doc = "Nody body string") - - def __set_val(self, val): - self.b = format_for_leo(val) - - v = property(lambda self: eval_node(self), __set_val, doc = "Node evaluated value") - - def __set_l(self,val): - self.b = '\n'.join(val ) - l = property(lambda self : IPython.genutils.SList(self.b.splitlines()), - __set_l, doc = "Node value as string list") - - def __iter__(self): - """ Iterate through nodes direct children """ - - return (LeoNode(p) for p in self.p.children_iter()) - - def __children(self): - d = {} - for child in self: - head = child.h - tup = head.split(None,1) - if len(tup) > 1 and tup[0] == '@k': - d[tup[1]] = child - continue - - if not valid_attribute(head): - d[head] = child - continue - return d - def keys(self): - d = self.__children() - return d.keys() - def __getitem__(self, key): - """ wb.foo['Some stuff'] Return a child node with headline 'Some stuff' - - If key is a valid python name (e.g. 'foo'), look for headline '@k foo' as well - """ - key = str(key) - d = self.__children() - return d[key] - def __setitem__(self, key, val): - """ You can do wb.foo['My Stuff'] = 12 to create children - - This will create 'My Stuff' as a child of foo (if it does not exist), and - do .v = 12 assignment. - - Exception: - - wb.foo['bar'] = 12 - - will create a child with headline '@k bar', because bar is a valid python name - and we don't want to crowd the WorkBook namespace with (possibly numerous) entries - """ - key = str(key) - d = self.__children() - if key in d: - d[key].v = val - return - - if not valid_attribute(key): - head = key - else: - head = '@k ' + key - p = c.createLastChildNode(self.p, head, '') - LeoNode(p).v = val - - def __delitem__(self, key): - """ Remove child - - Allows stuff like wb.foo.clear() to remove all children - """ - self[key].p.doDelete() - c.redraw() - - def ipush(self): - """ Does push-to-ipython on the node """ - push_from_leo(self) - - def go(self): - """ Set node as current node (to quickly see it in Outline) """ - c.setCurrentPosition(self.p) - c.redraw() - - def append(self): - """ Add new node as the last child, return the new node """ - p = self.p.insertAsLastChild() - return LeoNode(p) - - - def script(self): - """ Method to get the 'tangled' contents of the node - - (parse @others, << section >> references etc.) - """ - return g.getScript(c,self.p,useSelectedText=False,useSentinels=False) - - def __get_uA(self): - p = self.p - # Create the uA if necessary. - if not hasattr(p.v.t,'unknownAttributes'): - p.v.t.unknownAttributes = {} - - d = p.v.t.unknownAttributes.setdefault('ipython', {}) - return d - - uA = property(__get_uA, doc = "Access persistent unknownAttributes of node") - - -class LeoWorkbook: - """ class for 'advanced' node access - - Has attributes for all "discoverable" nodes. Node is discoverable if it - either - - - has a valid python name (Foo, bar_12) - - is a parent of an anchor node (if it has a child '@a foo', it is visible as foo) - - """ - def __getattr__(self, key): - if key.startswith('_') or key == 'trait_names' or not valid_attribute(key): - raise AttributeError - cells = all_cells() - p = cells.get(key, None) - if p is None: - return add_var(key) - - return LeoNode(p) - - def __str__(self): - return "" - def __setattr__(self,key, val): - raise AttributeError("Direct assignment to workbook denied, try wb.%s.v = %s" % (key,val)) - - __repr__ = __str__ - - def __iter__(self): - """ Iterate all (even non-exposed) nodes """ - cells = all_cells() - return (LeoNode(p) for p in c.allNodes_iter()) - - current = property(lambda self: LeoNode(c.currentPosition()), doc = "Currently selected node") - - def match_h(self, regex): - cmp = re.compile(regex) - for node in self: - if re.match(cmp, node.h, re.IGNORECASE): - yield node - return - - def require(self, req): - """ Used to control node push dependencies - - Call this as first statement in nodes. If node has not been pushed, it will be pushed before proceeding - - E.g. wb.require('foo') will do wb.foo.ipush() if it hasn't been done already - """ - - if req not in _leo_push_history: - es('Require: ' + req) - getattr(self,req).ipush() - - -@IPython.generics.complete_object.when_type(LeoWorkbook) -def workbook_complete(obj, prev): - return all_cells().keys() + [s for s in prev if not s.startswith('_')] - - -def add_var(varname): - r = rootnode() - try: - if r is None: - p2 = g.findNodeAnywhere(c,varname) - else: - p2 = g.findNodeInChildren(c, r.p, varname) - if p2: - return LeoNode(p2) - - if r is not None: - p2 = r.p.insertAsLastChild() - - else: - p2 = c.currentPosition().insertAfter() - - c.setHeadString(p2,varname) - return LeoNode(p2) - finally: - c.redraw() - -def add_file(self,fname): - p2 = c.currentPosition().insertAfter() - -push_from_leo = CommandChainDispatcher() - -def expose_ileo_push(f, prio = 0): - push_from_leo.add(f, prio) - -def push_ipython_script(node): - """ Execute the node body in IPython, as if it was entered in interactive prompt """ - try: - ohist = ip.IP.output_hist - hstart = len(ip.IP.input_hist) - script = node.script() - - # The current node _p needs to handle wb.require() and recursive ipushes - old_p = ip.user_ns.get('_p',None) - ip.user_ns['_p'] = node - ip.runlines(script) - ip.user_ns['_p'] = old_p - if old_p is None: - del ip.user_ns['_p'] - - has_output = False - for idx in range(hstart,len(ip.IP.input_hist)): - val = ohist.get(idx,None) - if val is None: - continue - has_output = True - inp = ip.IP.input_hist[idx] - if inp.strip(): - es('In: %s' % (inp[:40], )) - - es('<%d> %s' % (idx, pprint.pformat(ohist[idx],width = 40))) - - if not has_output: - es('ipy run: %s (%d LL)' %( node.h,len(script))) - finally: - c.redraw() - - -def eval_body(body): - try: - val = ip.ev(body) - except: - # just use stringlist if it's not completely legal python expression - val = IPython.genutils.SList(body.splitlines()) - return val - -def push_plain_python(node): - if not node.h.endswith('P'): - raise TryNext - script = node.script() - lines = script.count('\n') - try: - exec script in ip.user_ns - except: - print " -- Exception in script:\n"+script + "\n --" - raise - es('ipy plain: %s (%d LL)' % (node.h,lines)) - - -def push_cl_node(node): - """ If node starts with @cl, eval it - - The result is put as last child of @ipy-results node, if it exists - """ - if not node.b.startswith('@cl'): - raise TryNext - - p2 = g.findNodeAnywhere(c,'@ipy-results') - val = node.v - if p2: - es("=> @ipy-results") - LeoNode(p2).v = val - es(val) - -def push_ev_node(node): - """ If headline starts with @ev, eval it and put result in body """ - if not node.h.startswith('@ev '): - raise TryNext - expr = node.h.lstrip('@ev ') - es('ipy eval ' + expr) - res = ip.ev(expr) - node.v = res - -def push_mark_req(node): - """ This should be the first one that gets called. - - It will mark the node as 'pushed', for wb.require. - """ - _leo_push_history.add(node.h) - raise TryNext - - -def push_position_from_leo(p): - try: - push_from_leo(LeoNode(p)) - except AttributeError,e: - if e.args == ("Commands instance has no attribute 'frame'",): - es("Error: ILeo not associated with .leo document") - es("Press alt+shift+I to fix!") - else: - raise - -@generic -def edit_object_in_leo(obj, varname): - """ Make it @cl node so it can be pushed back directly by alt+I """ - node = add_var(varname) - formatted = format_for_leo(obj) - if not formatted.startswith('@cl'): - formatted = '@cl\n' + formatted - node.b = formatted - node.go() - -@edit_object_in_leo.when_type(IPython.macro.Macro) -def edit_macro(obj,varname): - bod = '_ip.defmacro("""\\\n' + obj.value + '""")' - node = add_var('Macro_' + varname) - node.b = bod - node.go() - -def get_history(hstart = 0): - res = [] - ohist = ip.IP.output_hist - - for idx in range(hstart, len(ip.IP.input_hist)): - val = ohist.get(idx,None) - has_output = True - inp = ip.IP.input_hist_raw[idx] - if inp.strip(): - res.append('In [%d]: %s' % (idx, inp)) - if val: - res.append(pprint.pformat(val)) - res.append('\n') - return ''.join(res) - - -def lee_f(self,s): - """ Open file(s)/objects in Leo - - - %lee hist -> open full session history in leo - - Takes an object. l = [1,2,"hello"]; %lee l. Alt+I in leo pushes the object back - - Takes an mglob pattern, e.g. '%lee *.cpp' or %lee 'rec:*.cpp' - - Takes input history indices: %lee 4 6-8 10 12-47 - """ - import os - - try: - if s == 'hist': - wb.ipython_history.b = get_history() - wb.ipython_history.go() - return - - - if s and s[0].isdigit(): - # numbers; push input slices to leo - lines = self.extract_input_slices(s.strip().split(), True) - v = add_var('stored_ipython_input') - v.b = '\n'.join(lines) - return - - - # try editing the object directly - obj = ip.user_ns.get(s, None) - if obj is not None: - edit_object_in_leo(obj,s) - return - - - # if it's not object, it's a file name / mglob pattern - from IPython.external import mglob - - files = (os.path.abspath(f) for f in mglob.expand(s)) - for fname in files: - p = g.findNodeAnywhere(c,'@auto ' + fname) - if not p: - p = c.currentPosition().insertAfter() - - p.setHeadString('@auto ' + fname) - if os.path.isfile(fname): - c.setBodyString(p,open(fname).read()) - c.selectPosition(p) - print "Editing file(s), press ctrl+shift+w in Leo to write @auto nodes" - finally: - c.redraw() - -def leoref_f(self,s): - """ Quick reference for ILeo """ - import textwrap - print textwrap.dedent("""\ - %lee file/object - open file / object in leo - %lleo Launch leo (use if you started ipython first!) - wb.foo.v - eval node foo (i.e. headstring is 'foo' or '@ipy foo') - wb.foo.v = 12 - assign to body of node foo - wb.foo.b - read or write the body of node foo - wb.foo.l - body of node foo as string list - - for el in wb.foo: - print el.v - - """ - ) - - - -def mb_f(self, arg): - """ Execute leo minibuffer commands - - Example: - mb save-to-file - """ - c.executeMinibufferCommand(arg) - -def mb_completer(self,event): - """ Custom completer for minibuffer """ - cmd_param = event.line.split() - if event.line.endswith(' '): - cmd_param.append('') - if len(cmd_param) > 2: - return ip.IP.Completer.file_matches(event.symbol) - cmds = c.commandsDict.keys() - cmds.sort() - return cmds - -def ileo_pre_prompt_hook(self): - # this will fail if leo is not running yet - try: - c.outerUpdate() - except NameError: - pass - raise TryNext - - - -def show_welcome(): - print "------------------" - print "Welcome to Leo-enabled IPython session!" - print "Try %leoref for quick reference." - import IPython.platutils - IPython.platutils.set_term_title('ILeo') - IPython.platutils.freeze_term_title() - -def run_leo_startup_node(): - p = g.findNodeAnywhere(c,'@ipy-startup') - if p: - print "Running @ipy-startup nodes" - for n in LeoNode(p): - push_from_leo(n) - -def lleo_f(selg, args): - """ Launch leo from within IPython - - This command will return immediately when Leo has been - launched, leaving a Leo session that is connected - with current IPython session (once you press alt+I in leo) - - Usage:: - lleo foo.leo - lleo - """ - - import shlex, sys - argv = ['leo'] + shlex.split(args) - sys.argv = argv - # if this var exists and is true, leo will "launch" (connect) - # ipython immediately when it's started - global _request_immediate_connect - _request_immediate_connect = True - import leo.core.runLeo - leo.core.runLeo.run() diff --git a/IPython/Extensions/ipy_profile_sh.py b/IPython/Extensions/ipy_profile_sh.py index ef4ae8e..59776cb 100644 --- a/IPython/Extensions/ipy_profile_sh.py +++ b/IPython/Extensions/ipy_profile_sh.py @@ -50,9 +50,15 @@ def main(): ip.ex('import os') ip.ex("def up(): os.chdir('..')") ip.user_ns['LA'] = LastArgFinder() - # Nice prompt - o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#> ' + # You can assign to _prompt_title variable + # to provide some extra information for prompt + # (e.g. the current mode, host/username...) + + ip.user_ns['_prompt_title'] = '' + + # Nice prompt + o.prompt_in1= r'\C_Green${_prompt_title}\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#> ' o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green> ' o.prompt_out= '<\#> ' @@ -98,9 +104,15 @@ def main(): for cmd in syscmds: # print "sys",cmd #dbg noext, ext = os.path.splitext(cmd) - key = mapper(noext) + if ext.lower() == '.exe': + cmd = noext + + key = mapper(cmd) if key not in ip.IP.alias_table: - ip.defalias(key, cmd) + # Dots will be removed from alias names, since ipython + # assumes names with dots to be python code + + ip.defalias(key.replace('.',''), cmd) # mglob combines 'find', recursion, exclusion... '%mglob?' to learn more ip.load("IPython.external.mglob") diff --git a/IPython/Magic.py b/IPython/Magic.py index 18f1165..b0fdcb9 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -2329,6 +2329,12 @@ Currently the magic system has the following functions:\n""" print 'Editing...', sys.stdout.flush() self.shell.hooks.editor(filename,lineno) + + # XXX TODO: should this be generalized for all string vars? + # For now, this is special-cased to blocks created by cpaste + if args.strip() == 'pasted_block': + self.shell.user_ns['pasted_block'] = file_read(filename) + if opts.has_key('x'): # -x prevents actual execution print else: @@ -2338,6 +2344,8 @@ Currently the magic system has the following functions:\n""" else: self.shell.safe_execfile(filename,self.shell.user_ns, self.shell.user_ns) + + if use_temp: try: return open(filename).read() @@ -2647,8 +2655,10 @@ Defaulting color scheme to 'NoColor'""" if isexec(ff) and ff not in self.shell.no_alias: # each entry in the alias table must be (N,name), # where N is the number of positional arguments of the - # alias. - alias_table[ff] = (0,ff) + # alias. + # Dots will be removed from alias names, since ipython + # assumes names with dots to be python code + alias_table[ff.replace('.','')] = (0,ff) syscmdlist.append(ff) else: for pdir in path: @@ -2658,7 +2668,7 @@ Defaulting color scheme to 'NoColor'""" if isexec(ff) and base.lower() not in self.shell.no_alias: if ext.lower() == '.exe': ff = base - alias_table[base.lower()] = (0,ff) + alias_table[base.lower().replace('.','')] = (0,ff) syscmdlist.append(ff) # Make sure the alias table doesn't contain keywords or builtins self.shell.alias_table_validate() @@ -3210,14 +3220,24 @@ Defaulting color scheme to 'NoColor'""" This assigns the pasted block to variable 'foo' as string, without dedenting or executing it (preceding >>> and + is still stripped) + '%cpaste -r' re-executes the block previously entered by cpaste. + Do not be alarmed by garbled output on Windows (it's a readline bug). Just press enter and type -- (and press enter again) and the block will be what was just pasted. IPython statements (magics, shell escapes) are not supported (yet). """ - opts,args = self.parse_options(parameter_s,'s:',mode='string') + opts,args = self.parse_options(parameter_s,'rs:',mode='string') par = args.strip() + if opts.has_key('r'): + b = self.user_ns.get('pasted_block', None) + if b is None: + raise UsageError('No previous pasted block available') + print "Re-executing '%s...' (%d chars)"% (b.split('\n',1)[0], len(b)) + exec b in self.user_ns + return + sentinel = opts.get('s','--') # Regular expressions that declare text we strip from the input: @@ -3245,8 +3265,8 @@ Defaulting color scheme to 'NoColor'""" #print "block:\n",block if not par: b = textwrap.dedent(block) - exec b in self.user_ns self.user_ns['pasted_block'] = b + exec b in self.user_ns else: self.user_ns[par] = SList(block.splitlines()) print "Block assigned to '%s'" % par diff --git a/IPython/Release.py b/IPython/Release.py index 06783bf..d2e3bf5 100644 --- a/IPython/Release.py +++ b/IPython/Release.py @@ -34,45 +34,69 @@ else: version = version_base -description = "Tools for interactive development in Python." +description = "An interactive computing environment for Python" long_description = \ """ -IPython provides a replacement for the interactive Python interpreter with -extra functionality. +The goal of IPython is to create a comprehensive environment for +interactive and exploratory computing. To support this goal, IPython +has two main components: -Main features: +* An enhanced interactive Python shell. - * Comprehensive object introspection. +* An architecture for interactive parallel computing. - * Input history, persistent across sessions. +The enhanced interactive Python shell has the following main features: - * Caching of output results during a session with automatically generated - references. +* Comprehensive object introspection. - * Readline based name completion. +* Input history, persistent across sessions. - * Extensible system of 'magic' commands for controlling the environment and - performing many tasks related either to IPython or the operating system. +* Caching of output results during a session with automatically generated + references. - * Configuration system with easy switching between different setups (simpler - than changing $PYTHONSTARTUP environment variables every time). +* Readline based name completion. - * Session logging and reloading. +* Extensible system of 'magic' commands for controlling the environment and + performing many tasks related either to IPython or the operating system. - * Extensible syntax processing for special purpose situations. +* Configuration system with easy switching between different setups (simpler + than changing $PYTHONSTARTUP environment variables every time). - * Access to the system shell with user-extensible alias system. +* Session logging and reloading. - * Easily embeddable in other Python programs. +* Extensible syntax processing for special purpose situations. - * Integrated access to the pdb debugger and the Python profiler. +* Access to the system shell with user-extensible alias system. - The latest development version is always available at the IPython subversion - repository_. +* Easily embeddable in other Python programs and wxPython GUIs. -.. _repository: http://ipython.scipy.org/svn/ipython/ipython/trunk#egg=ipython-dev - """ +* Integrated access to the pdb debugger and the Python profiler. + +The parallel computing architecture has the following main features: + +* Quickly parallelize Python code from an interactive Python/IPython session. + +* A flexible and dynamic process model that be deployed on anything from + multicore workstations to supercomputers. + +* An architecture that supports many different styles of parallelism, from + message passing to task farming. + +* Both blocking and fully asynchronous interfaces. + +* High level APIs that enable many things to be parallelized in a few lines + of code. + +* Share live parallel jobs with other users securely. + +* Dynamically load balanced task farming system. + +* Robust error handling in parallel code. + +The latest development version is always available from IPython's `Launchpad +site `_. +""" license = 'BSD' diff --git a/IPython/config/api.py b/IPython/config/api.py index d394098..6de3d3e 100644 --- a/IPython/config/api.py +++ b/IPython/config/api.py @@ -21,10 +21,6 @@ from os.path import join as pjoin from IPython.genutils import get_home_dir, get_ipython_dir from IPython.external.configobj import ConfigObj -# Traitlets config imports -from IPython.config import traitlets -from IPython.config.config import * -from traitlets import * class ConfigObjManager(object): diff --git a/IPython/history.py b/IPython/history.py index acfea45..004b820 100644 --- a/IPython/history.py +++ b/IPython/history.py @@ -8,6 +8,7 @@ import os # IPython imports from IPython.genutils import Term, ask_yes_no +import IPython.ipapi def magic_history(self, parameter_s = ''): """Print input history (_i variables), with most recent last. @@ -222,6 +223,7 @@ class ShadowHist: # cmd => idx mapping self.curidx = 0 self.db = db + self.disabled = False def inc_idx(self): idx = self.db.get('shadowhist_idx', 1) @@ -229,12 +231,19 @@ class ShadowHist: return idx def add(self, ent): - old = self.db.hget('shadowhist', ent, _sentinel) - if old is not _sentinel: + if self.disabled: return - newidx = self.inc_idx() - #print "new",newidx # dbg - self.db.hset('shadowhist',ent, newidx) + try: + old = self.db.hget('shadowhist', ent, _sentinel) + if old is not _sentinel: + return + newidx = self.inc_idx() + #print "new",newidx # dbg + self.db.hset('shadowhist',ent, newidx) + except: + IPython.ipapi.get().IP.showtraceback() + print "WARNING: disabling shadow history" + self.disabled = True def all(self): d = self.db.hdict('shadowhist') diff --git a/IPython/kernel/core/tests/test_redirectors.py b/IPython/kernel/core/tests/test_redirectors.py index 27b638d..81aa0ba 100644 --- a/IPython/kernel/core/tests/test_redirectors.py +++ b/IPython/kernel/core/tests/test_redirectors.py @@ -13,15 +13,17 @@ __docformat__ = "restructuredtext en" #------------------------------------------------------------------------------- +# Stdlib imports import os from cStringIO import StringIO -# FIXME: -import nose -import sys -if sys.platform == 'win32': - raise nose.SkipTest("These tests are not reliable under windows") +# Our own imports +from IPython.testing import decorators as dec +#----------------------------------------------------------------------------- +# Test functions + +@dec.skip_win32 def test_redirector(): """ Checks that the redirector can be used to do synchronous capture. """ @@ -42,6 +44,8 @@ def test_redirector(): result2 = "".join("%ic\n%i\n" %(i, i) for i in range(10)) assert result1 == result2 + +@dec.skip_win32 def test_redirector_output_trap(): """ This test check not only that the redirector_output_trap does trap the output, but also that it does it in a gready way, that @@ -63,6 +67,4 @@ def test_redirector_output_trap(): result1 = out.getvalue() result2 = "".join("%ic\n%ip\n%i\n" %(i, i, i) for i in range(10)) assert result1 == result2 - - diff --git a/IPython/kernel/scripts/ipengine.py b/IPython/kernel/scripts/ipengine.py index 97fd2ca..8d9d1b2 100644 --- a/IPython/kernel/scripts/ipengine.py +++ b/IPython/kernel/scripts/ipengine.py @@ -91,7 +91,7 @@ def start_engine(): try: engine_service.execute(shell_import_statement) except: - log.msg("Error running import_statement: %s" % sis) + log.msg("Error running import_statement: %s" % shell_import_statement) # Create the service hierarchy main_service = service.MultiService() @@ -169,4 +169,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index 78b6840..6cbe0a7 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -8,6 +8,10 @@ the decorator, in order to preserve metadata such as function name, setup and teardown functions and so on - see nose.tools for more information. +This module provides a set of useful decorators meant to be ready to use in +your own tests. See the bottom of the file for the ready-made ones, and if you +find yourself writing a new one that may be of generic use, add it here. + NOTE: This file contains IPython-specific decorators and imports the numpy.testing.decorators file, which we've copied verbatim. Any of our own code will be added at the bottom if we end up extending this. @@ -15,6 +19,7 @@ code will be added at the bottom if we end up extending this. # Stdlib imports import inspect +import sys # Third-party imports @@ -123,6 +128,9 @@ skip_doctest = make_label_dec('skip_doctest', def skip(msg=''): """Decorator - mark a test function for skipping from test suite. + This function *is* already a decorator, it is not a factory like + make_label_dec or some of those in decorators_numpy. + :Parameters: func : function @@ -145,3 +153,8 @@ def skip(msg=''): return apply_wrapper(wrapper,func) return inner + +# Decorators to skip certain tests on specific platforms. +skip_win32 = skipif(sys.platform=='win32',"This test does not run under Windows") +skip_linux = skipif(sys.platform=='linux2',"This test does not run under Linux") +skip_osx = skipif(sys.platform=='darwin',"This test does not run under OSX") diff --git a/IPython/testing/plugin/test_refs.py b/IPython/testing/plugin/test_refs.py index fc7e6f0..ae9ba41 100644 --- a/IPython/testing/plugin/test_refs.py +++ b/IPython/testing/plugin/test_refs.py @@ -1,152 +1,19 @@ +"""Some simple tests for the plugin while running scripts. +""" # Module imports # Std lib import inspect -# Third party - # Our own from IPython.testing import decorators as dec #----------------------------------------------------------------------------- -# Utilities - -# Note: copied from OInspect, kept here so the testing stuff doesn't create -# circular dependencies and is easier to reuse. -def getargspec(obj): - """Get the names and default values of a function's arguments. - - A tuple of four things is returned: (args, varargs, varkw, defaults). - 'args' is a list of the argument names (it may contain nested lists). - 'varargs' and 'varkw' are the names of the * and ** arguments or None. - 'defaults' is an n-tuple of the default values of the last n arguments. - - Modified version of inspect.getargspec from the Python Standard - Library.""" - - if inspect.isfunction(obj): - func_obj = obj - elif inspect.ismethod(obj): - func_obj = obj.im_func - else: - raise TypeError, 'arg is not a Python function' - args, varargs, varkw = inspect.getargs(func_obj.func_code) - return args, varargs, varkw, func_obj.func_defaults - -#----------------------------------------------------------------------------- # Testing functions def test_trivial(): """A trivial passing test.""" pass - -@dec.skip -def test_deliberately_broken(): - """A deliberately broken test - we want to skip this one.""" - 1/0 - -@dec.skip('foo') -def test_deliberately_broken2(): - """Another deliberately broken test - we want to skip this one.""" - 1/0 - - -# Verify that we can correctly skip the doctest for a function at will, but -# that the docstring itself is NOT destroyed by the decorator. -@dec.skip_doctest -def doctest_bad(x,y=1,**k): - """A function whose doctest we need to skip. - - >>> 1+1 - 3 - """ - print 'x:',x - print 'y:',y - print 'k:',k - - -def call_doctest_bad(): - """Check that we can still call the decorated functions. - - >>> doctest_bad(3,y=4) - x: 3 - y: 4 - k: {} - """ - pass - - -# Doctest skipping should work for class methods too -class foo(object): - """Foo - - Example: - - >>> 1+1 - 2 - """ - - @dec.skip_doctest - def __init__(self,x): - """Make a foo. - - Example: - - >>> f = foo(3) - junk - """ - print 'Making a foo.' - self.x = x - - @dec.skip_doctest - def bar(self,y): - """Example: - - >>> f = foo(3) - >>> f.bar(0) - boom! - >>> 1/0 - bam! - """ - return 1/y - - def baz(self,y): - """Example: - - >>> f = foo(3) - Making a foo. - >>> f.baz(3) - True - """ - return self.x==y - - -def test_skip_dt_decorator(): - """Doctest-skipping decorator should preserve the docstring. - """ - # Careful: 'check' must be a *verbatim* copy of the doctest_bad docstring! - check = """A function whose doctest we need to skip. - - >>> 1+1 - 3 - """ - # Fetch the docstring from doctest_bad after decoration. - val = doctest_bad.__doc__ - - assert check==val,"doctest_bad docstrings don't match" - - -def test_skip_dt_decorator2(): - """Doctest-skipping decorator should preserve function signature. - """ - # Hardcoded correct answer - dtargs = (['x', 'y'], None, 'k', (1,)) - # Introspect out the value - dtargsr = getargspec(doctest_bad) - assert dtargsr==dtargs, \ - "Incorrectly reconstructed args for doctest_bad: %s" % (dtargsr,) - - def doctest_run(): """Test running a trivial script. @@ -154,7 +21,6 @@ def doctest_run(): x is: 1 """ -#@dec.skip_doctest def doctest_runvars(): """Test that variables defined in scripts get loaded correcly via %run. diff --git a/IPython/testing/tests/test_decorators.py b/IPython/testing/tests/test_decorators.py new file mode 100644 index 0000000..e91ec73 --- /dev/null +++ b/IPython/testing/tests/test_decorators.py @@ -0,0 +1,161 @@ +"""Tests for the decorators we've created for IPython. +""" + +# Module imports +# Std lib +import inspect +import sys + +# Third party +import nose.tools as nt + +# Our own +from IPython.testing import decorators as dec + + +#----------------------------------------------------------------------------- +# Utilities + +# Note: copied from OInspect, kept here so the testing stuff doesn't create +# circular dependencies and is easier to reuse. +def getargspec(obj): + """Get the names and default values of a function's arguments. + + A tuple of four things is returned: (args, varargs, varkw, defaults). + 'args' is a list of the argument names (it may contain nested lists). + 'varargs' and 'varkw' are the names of the * and ** arguments or None. + 'defaults' is an n-tuple of the default values of the last n arguments. + + Modified version of inspect.getargspec from the Python Standard + Library.""" + + if inspect.isfunction(obj): + func_obj = obj + elif inspect.ismethod(obj): + func_obj = obj.im_func + else: + raise TypeError, 'arg is not a Python function' + args, varargs, varkw = inspect.getargs(func_obj.func_code) + return args, varargs, varkw, func_obj.func_defaults + +#----------------------------------------------------------------------------- +# Testing functions + +@dec.skip +def test_deliberately_broken(): + """A deliberately broken test - we want to skip this one.""" + 1/0 + +@dec.skip('foo') +def test_deliberately_broken2(): + """Another deliberately broken test - we want to skip this one.""" + 1/0 + + +# Verify that we can correctly skip the doctest for a function at will, but +# that the docstring itself is NOT destroyed by the decorator. +@dec.skip_doctest +def doctest_bad(x,y=1,**k): + """A function whose doctest we need to skip. + + >>> 1+1 + 3 + """ + print 'x:',x + print 'y:',y + print 'k:',k + + +def call_doctest_bad(): + """Check that we can still call the decorated functions. + + >>> doctest_bad(3,y=4) + x: 3 + y: 4 + k: {} + """ + pass + + +def test_skip_dt_decorator(): + """Doctest-skipping decorator should preserve the docstring. + """ + # Careful: 'check' must be a *verbatim* copy of the doctest_bad docstring! + check = """A function whose doctest we need to skip. + + >>> 1+1 + 3 + """ + # Fetch the docstring from doctest_bad after decoration. + val = doctest_bad.__doc__ + + assert check==val,"doctest_bad docstrings don't match" + +# Doctest skipping should work for class methods too +class foo(object): + """Foo + + Example: + + >>> 1+1 + 2 + """ + + @dec.skip_doctest + def __init__(self,x): + """Make a foo. + + Example: + + >>> f = foo(3) + junk + """ + print 'Making a foo.' + self.x = x + + @dec.skip_doctest + def bar(self,y): + """Example: + + >>> f = foo(3) + >>> f.bar(0) + boom! + >>> 1/0 + bam! + """ + return 1/y + + def baz(self,y): + """Example: + + >>> f = foo(3) + Making a foo. + >>> f.baz(3) + True + """ + return self.x==y + + + +def test_skip_dt_decorator2(): + """Doctest-skipping decorator should preserve function signature. + """ + # Hardcoded correct answer + dtargs = (['x', 'y'], None, 'k', (1,)) + # Introspect out the value + dtargsr = getargspec(doctest_bad) + assert dtargsr==dtargs, \ + "Incorrectly reconstructed args for doctest_bad: %s" % (dtargsr,) + + +@dec.skip_linux +def test_linux(): + nt.assert_not_equals(sys.platform,'linux2',"This test can't run under linux") + +@dec.skip_win32 +def test_win32(): + nt.assert_not_equals(sys.platform,'win32',"This test can't run under windows") + +@dec.skip_osx +def test_osx(): + nt.assert_not_equals(sys.platform,'darwin',"This test can't run under osx") diff --git a/IPython/tests/test_magic.py b/IPython/tests/test_magic.py new file mode 100644 index 0000000..4228600 --- /dev/null +++ b/IPython/tests/test_magic.py @@ -0,0 +1,21 @@ +""" Tests for various magic functions + +Needs to be run by nose (to make ipython session available) + +""" +def test_rehashx(): + # clear up everything + _ip.IP.alias_table.clear() + del _ip.db['syscmdlist'] + + _ip.magic('rehashx') + # Practically ALL ipython development systems will have more than 10 aliases + + assert len(_ip.IP.alias_table) > 10 + for key, val in _ip.IP.alias_table.items(): + # we must strip dots from alias names + assert '.' not in key + + # rehashx must fill up syscmdlist + scoms = _ip.db['syscmdlist'] + assert len(scoms) > 10 diff --git a/README.txt b/README.txt index a46aaeb..dcda9ef 100644 --- a/README.txt +++ b/README.txt @@ -1,11 +1,11 @@ -=============== -IPython1 README -=============== - -.. contents:: +============== +IPython README +============== Overview ======== -Welcome to IPython. New users should consult our documentation, which can be found -in the docs/source subdirectory. +Welcome to IPython. Our documentation can be found in the docs/source +subdirectory. We also have ``.html`` and ``.pdf`` versions of this +documentation available on the IPython `website `_. + diff --git a/README_Windows.txt b/README_Windows.txt deleted file mode 100644 index 0ad13a7..0000000 --- a/README_Windows.txt +++ /dev/null @@ -1,50 +0,0 @@ -Notes for Windows Users -======================= - -See http://ipython.scipy.org/moin/IpythonOnWindows for up-to-date information -about running IPython on Windows. - - -Requirements ------------- - -IPython runs under (as far as the Windows family is concerned): - -- Windows XP, 2000 (and probably WinNT): works well. It needs: - - * PyWin32: http://sourceforge.net/projects/pywin32/ - - * PyReadline: http://ipython.scipy.org/moin/PyReadline/Intro - - * If you are using Python2.4, this in turn requires Tomas Heller's ctypes - from: http://starship.python.net/crew/theller/ctypes (not needed for Python - 2.5 users, since 2.5 already ships with ctypes). - -- Windows 95/98/ME: I have no idea. It should work, but I can't test. - -- CygWin environments should work, they are basically Posix. - -It needs Python 2.3 or newer. - - -Installation ------------- - -Double-click the supplied .exe installer file. If all goes well, that's all -you need to do. You should now have an IPython entry in your Start Menu. - - -Installation from source distribution -------------------------------------- - -In case the automatic installer does not work for some reason, you can -download the ipython-XXX.tar.gz file, which contains the full IPython source -distribution (the popular WinZip can read .tar.gz files). - -After uncompressing the archive, you can install it at a command terminal just -like any other Python module, by using python setup.py install'. After this -completes, you can run the supplied win32_manual_post_install.py script which -will add the relevant shortcuts to your startup menu. - -Optionally, you may skip installation altogether and just launch "ipython.py" -from the root folder of the extracted source distribution. diff --git a/docs/source/changes.txt b/docs/source/changes.txt index 8d77fb8..d44dd59 100644 --- a/docs/source/changes.txt +++ b/docs/source/changes.txt @@ -6,20 +6,55 @@ What's new .. contents:: .. - 1 Release 0.9 - 1.1 New features - 1.2 Bug fixes - 1.3 Backwards incompatible changes - 1.4 Changes merged in from IPython1 - 1.4.1 New features - 1.4.2 Bug fixes - 1.4.3 Backwards incompatible changes - 2 Release 0.8.4 - 3 Release 0.8.3 - 4 Release 0.8.2 - 5 Older releases + 1 Release 0.9.1 + 2 Release 0.9 + 2.1 New features + 2.2 Bug fixes + 2.3 Backwards incompatible changes + 2.4 Changes merged in from IPython1 + 2.4.1 New features + 2.4.2 Bug fixes + 2.4.3 Backwards incompatible changes + 3 Release 0.8.4 + 4 Release 0.8.3 + 5 Release 0.8.2 + 6 Older releases .. +Release DEV +=========== + +* cd completer: show bookmarks if no other completions are available. + +* Remove ipy_leo.py. "easy_install ipython-extension" to get it. + (done to decouple it from ipython release cycle) + +* sh profile: easy way to give 'title' to prompt: assign to variable + '_prompt_title'. It looks like this:: + + [~]|1> _prompt_title = 'sudo!' + sudo![~]|2> + +* %rehashx: Aliases no longer contain dots. python3.0 binary + will create alias python30. Fixes: + #259716 "commands with dots in them don't work" + +* %cpaste: %cpaste -r repeats the last pasted block. + The block is assigned to pasted_block even if code + raises exception. + +* %edit: If you do '%edit pasted_block', pasted_block + variable gets updated with new data (so repeated + editing makes sense) + + +Release 0.9.1 +============= + +This release was quickly made to restore compatibility with Python 2.4, which +version 0.9 accidentally broke. No new features were introduced, other than +some additional testing support for internal use. + Release 0.9 =========== diff --git a/docs/source/development/development.txt b/docs/source/development/development.txt index d4b567b..5bd03d5 100644 --- a/docs/source/development/development.txt +++ b/docs/source/development/development.txt @@ -1,10 +1,8 @@ .. _development: -================================== +============================== IPython development guidelines -================================== - -.. contents:: +============================== Overview @@ -380,6 +378,7 @@ are interested in working on this part of IPython. The current prototype of .. _ConfigObj: http://www.voidspace.org.uk/python/configobj.html .. _Traits: http://code.enthought.com/traits/ + Installation and testing scenarios ================================== @@ -424,3 +423,24 @@ Tests to run for these scenarios installed. 5. Beat on the IPython terminal a bunch. 6. Make sure that furl files are being put in proper locations. + + +Release checklist +================= + +Most of the release process is automated by the :file:`release` script in the +:file:`tools` directory. This is just a handy reminder for the release manager. + +#. Run the release script, which makes the tar.gz, eggs and Win32 .exe + installer. It posts them to the site and registers the release with PyPI. + +#. Updating the website with announcements and links to the updated changes.txt + in html form. Remember to put a short note both on the news page of the site + and on launcphad. + +#. Drafting a short release announcement with i) highlights and ii) a link to + the html changes.txt. + +#. Make sure that the released version of the docs is live on the site. + +#. Celebrate! diff --git a/docs/source/index.txt b/docs/source/index.txt index 28c65bd..bde7c08 100644 --- a/docs/source/index.txt +++ b/docs/source/index.txt @@ -4,7 +4,7 @@ IPython Documentation .. htmlonly:: - :Release: |version| + :Release: |release| :Date: |today| Contents: diff --git a/docs/source/overview.txt b/docs/source/overview.txt index 6ac308d..9ee38cb 100644 --- a/docs/source/overview.txt +++ b/docs/source/overview.txt @@ -14,7 +14,7 @@ However, the interpreter supplied with the standard Python distribution is somewhat limited for extended interactive use. The goal of IPython is to create a comprehensive environment for -interactive and exploratory computing. To support, this goal, IPython +interactive and exploratory computing. To support this goal, IPython has two main components: * An enhanced interactive Python shell. diff --git a/IPython/config/config.py b/sandbox/config.py similarity index 100% rename from IPython/config/config.py rename to sandbox/config.py diff --git a/IPython/config/tests/sample_config.py b/sandbox/sample_config.py similarity index 100% rename from IPython/config/tests/sample_config.py rename to sandbox/sample_config.py diff --git a/IPython/config/tests/test_config.py b/sandbox/test_config.py similarity index 100% rename from IPython/config/tests/test_config.py rename to sandbox/test_config.py diff --git a/IPython/config/traitlets.py b/sandbox/traitlets.py similarity index 100% rename from IPython/config/traitlets.py rename to sandbox/traitlets.py diff --git a/tools/check_sources.py b/tools/check_sources.py index 2b21cae..9d90f3c 100755 --- a/tools/check_sources.py +++ b/tools/check_sources.py @@ -12,4 +12,4 @@ for f in fs: if errs: print "%3s" % errs, f - \ No newline at end of file + diff --git a/tools/compile.py b/tools/compile.py new file mode 100644 index 0000000..4a08400 --- /dev/null +++ b/tools/compile.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +"""Call the compile script to check that all code we ship compiles correctly. +""" + +import os +import sys + + +vstr = '.'.join(map(str,sys.version_info[:2])) + +stat = os.system('python %s/lib/python%s/compileall.py .' % (sys.prefix,vstr)) + +print +if stat: + print '*** THERE WAS AN ERROR! ***' + print 'See messages above for the actual file that produced it.' +else: + print 'OK' + +sys.exit(stat)