##// END OF EJS Templates
Update setup.py for setuptools support for ipythonqt script.
Update setup.py for setuptools support for ipythonqt script.

File last commit:

r2266:eda4ef85
r2923:895b576c
Show More
clearcmd.py
87 lines | 2.6 KiB | text/x-python | PythonLexer
vivainio
Jorgen's %clean array
r245 # -*- coding: utf-8 -*-
""" IPython extension: add %clear magic """
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
vivainio
Jorgen's %clean array
r245 import gc
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 ip = ipapi.get()
vivainio
Jorgen's %clean array
r245
def clear_f(self,arg):
""" Clear various data (e.g. stored history data)
%clear in - clear input history
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 %clear out - clear output history
vivainio
doc, changelog fixes
r791 %clear shadow_compress - Compresses shadow history (to speed up ipython)
%clear shadow_nuke - permanently erase all entries in shadow history
vivainio
cd -TAB pads zeros, %clear dhist, some doc changes
r839 %clear dhist - clear dir history
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 %clear array - clear only variables that are NumPy arrays
Examples:
In [1]: clear in
Flushing input history
In [2]: clear shadow_compress
Compressing shadow history
In [3]: clear shadow_nuke
Erased all keys from shadow history
In [4]: clear dhist
Clearing directory history
vivainio
Jorgen's %clean array
r245 """
api = self.getapi()
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 user_ns = self.user_ns # local lookup, heavily used
vivainio
Jorgen's %clean array
r245 for target in arg.split():
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844
vivainio
Jorgen's %clean array
r245 if target == 'out':
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 print "Flushing output cache (%d entries)" % len(user_ns['_oh'])
vivainio
Jorgen's %clean array
r245 self.outputcache.flush()
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844
vivainio
Jorgen's %clean array
r245 elif target == 'in':
print "Flushing input history"
vivainio
%clear in now properly pads the history with empty entries
r795 pc = self.outputcache.prompt_count + 1
for n in range(1, pc):
vivainio
Jorgen's %clean array
r245 key = '_i'+`n`
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 user_ns.pop(key,None)
vivainio
Jorgen's %clean array
r245 try:
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 del user_ns[key]
vivainio
Jorgen's %clean array
r245 except: pass
vivainio
%clear in now properly pads the history with empty entries
r795 # must be done in-place
self.input_hist[:] = ['\n'] * pc
self.input_hist_raw[:] = ['\n'] * pc
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844
vivainio
Jorgen's %clean array
r245 elif target == 'array':
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 # Support cleaning up numpy arrays
vivainio
Jorgen's %clean array
r245 try:
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 from numpy import ndarray
# This must be done with items and not iteritems because we're
# going to modify the dict in-place.
for x,val in user_ns.items():
if isinstance(val,ndarray):
del user_ns[x]
vivainio
Jorgen's %clean array
r245 except AttributeError:
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 print "Clear array only works if Numpy is available."
vivainio
completers for %clear magic, add shadow history deletion
r790
elif target == 'shadow_compress':
print "Compressing shadow history"
vivainio
ipy_completers.quick_completer for easy creation of custom completers
r789 api.db.hcompress('shadowhist')
vivainio
Jorgen's %clean array
r245
vivainio
completers for %clear magic, add shadow history deletion
r790 elif target == 'shadow_nuke':
print "Erased all keys from shadow history "
for k in ip.db.keys('shadowhist/*'):
del ip.db[k]
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844
vivainio
cd -TAB pads zeros, %clear dhist, some doc changes
r839 elif target == 'dhist':
print "Clearing directory history"
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 del user_ns['_dh'][:]
vivainio
cd -TAB pads zeros, %clear dhist, some doc changes
r839
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 gc.collect()
# Activate the extension
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.define_magic("clear",clear_f)
vivainio
completers for %clear magic, add shadow history deletion
r790 import ipy_completers
vivainio
cd -TAB pads zeros, %clear dhist, some doc changes
r839 ipy_completers.quick_completer(
Fernando Perez
Add tests and fixes to clearcmd extension, when using numpy.
r1844 '%clear','in out shadow_nuke shadow_compress dhist')