Show More
@@ -187,8 +187,7 b' def test_macro_run():' | |||||
187 | @dec.skipif_not_numpy |
|
187 | @dec.skipif_not_numpy | |
188 | def test_numpy_clear_array_undec(): |
|
188 | def test_numpy_clear_array_undec(): | |
189 | "Test '%clear array' functionality" |
|
189 | "Test '%clear array' functionality" | |
190 | from IPython.extensions import clearcmd |
|
190 | _ip.magic("load_ext clearcmd") | |
191 |
|
||||
192 | _ip.ex('import numpy as np') |
|
191 | _ip.ex('import numpy as np') | |
193 | _ip.ex('a = np.empty(2)') |
|
192 | _ip.ex('a = np.empty(2)') | |
194 | yield (nt.assert_true, 'a' in _ip.user_ns) |
|
193 | yield (nt.assert_true, 'a' in _ip.user_ns) | |
@@ -197,8 +196,8 b' def test_numpy_clear_array_undec():' | |||||
197 |
|
196 | |||
198 | def test_clear(): |
|
197 | def test_clear(): | |
199 | "Test '%clear' magic provided by IPython.extensions.clearcmd" |
|
198 | "Test '%clear' magic provided by IPython.extensions.clearcmd" | |
200 | from IPython.extensions import clearcmd |
|
|||
201 | _ip = get_ipython() |
|
199 | _ip = get_ipython() | |
|
200 | _ip.magic("load_ext clearcmd") | |||
202 | _ip.run_cell("parrot = 'dead'", store_history=True) |
|
201 | _ip.run_cell("parrot = 'dead'", store_history=True) | |
203 | # test '%clear out', make an Out prompt |
|
202 | # test '%clear out', make an Out prompt | |
204 | _ip.run_cell("parrot", store_history=True) |
|
203 | _ip.run_cell("parrot", store_history=True) |
@@ -1,9 +1,7 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ IPython extension: add %clear magic """ |
|
2 | """ IPython extension: add %clear magic """ | |
3 |
|
3 | |||
4 | from IPython.core import ipapi |
|
|||
5 | import gc |
|
4 | import gc | |
6 | ip = ipapi.get() |
|
|||
7 |
|
5 | |||
8 | def clear_f(self,arg): |
|
6 | def clear_f(self,arg): | |
9 | """ Clear various data (e.g. stored history data) |
|
7 | """ Clear various data (e.g. stored history data) | |
@@ -30,7 +28,7 b' def clear_f(self,arg):' | |||||
30 | Clearing directory history |
|
28 | Clearing directory history | |
31 | """ |
|
29 | """ | |
32 |
|
30 | |||
33 | api = self.get_ipython() |
|
31 | ip = self.shell | |
34 | user_ns = self.user_ns # local lookup, heavily used |
|
32 | user_ns = self.user_ns # local lookup, heavily used | |
35 |
|
33 | |||
36 |
|
34 | |||
@@ -64,7 +62,7 b' def clear_f(self,arg):' | |||||
64 |
|
62 | |||
65 | elif target == 'shadow_compress': |
|
63 | elif target == 'shadow_compress': | |
66 | print "Compressing shadow history" |
|
64 | print "Compressing shadow history" | |
67 |
|
|
65 | ip.db.hcompress('shadowhist') | |
68 |
|
66 | |||
69 | elif target == 'shadow_nuke': |
|
67 | elif target == 'shadow_nuke': | |
70 | print "Erased all keys from shadow history " |
|
68 | print "Erased all keys from shadow history " | |
@@ -77,7 +75,13 b' def clear_f(self,arg):' | |||||
77 |
|
75 | |||
78 | gc.collect() |
|
76 | gc.collect() | |
79 |
|
77 | |||
|
78 | _loaded = False | |||
|
79 | ||||
80 | # Activate the extension |
|
80 | # Activate the extension | |
81 | ip.define_magic("clear",clear_f) |
|
81 | def load_ipython_extension(ip): | |
82 | from IPython.core.completerlib import quick_completer |
|
82 | """Load the extension in IPython.""" | |
83 | quick_completer('%clear','in out array shadow_nuke shadow_compress dhist') |
|
83 | global _loaded | |
|
84 | if not _loaded: | |||
|
85 | ip.define_magic("clear",clear_f) | |||
|
86 | from IPython.core.completerlib import quick_completer | |||
|
87 | quick_completer('%clear','in out array shadow_nuke shadow_compress dhist') |
General Comments 0
You need to be logged in to leave comments.
Login now