##// END OF EJS Templates
Simplify parallelmagics by removing unnecessary plugin.
Fernando Perez -
Show More
@@ -24,7 +24,7 b' Usage'
24 """
24 """
25
25
26 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
27 # Copyright (C) 2008-2011 The IPython Development Team
27 # Copyright (C) 2008 The IPython Development Team
28 #
28 #
29 # Distributed under the terms of the BSD License. The full license is in
29 # Distributed under the terms of the BSD License. The full license is in
30 # the file COPYING, distributed as part of this software.
30 # the file COPYING, distributed as part of this software.
@@ -38,9 +38,8 b' import ast'
38 import re
38 import re
39
39
40 from IPython.core.magic import Magics, register_magics, line_magic
40 from IPython.core.magic import Magics, register_magics, line_magic
41 from IPython.core.plugin import Plugin
42 from IPython.testing.skipdoctest import skip_doctest
41 from IPython.testing.skipdoctest import skip_doctest
43 from IPython.utils.traitlets import Bool, Any, Instance
42 from IPython.utils.traitlets import Instance
44
43
45 #-----------------------------------------------------------------------------
44 #-----------------------------------------------------------------------------
46 # Definitions of magic functions for use with IPython
45 # Definitions of magic functions for use with IPython
@@ -51,22 +50,12 b' Use activate() on a DirectView object to activate it for magics.'
51 """
50 """
52
51
53
52
54 class ParallelTricks(Plugin):
55 """A component to manage the %result, %px and %autopx magics."""
56
57 active_view = Instance('IPython.parallel.client.view.DirectView')
58 verbose = Bool(False, config=True)
59 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
60
61 def __init__(self, shell=None, config=None):
62 super(ParallelTricks, self).__init__(shell=shell, config=config)
63 self.shell.register_magics(ParallelMagics)
64
65
66 @register_magics
53 @register_magics
67 class ParallelMagics(Magics):
54 class ParallelMagics(Magics):
68 """A set of magics useful when controlling a parallel IPython cluster.
55 """A set of magics useful when controlling a parallel IPython cluster.
69 """
56 """
57 active_view = Instance('IPython.parallel.client.view.DirectView')
58
70 def __init__(self, shell):
59 def __init__(self, shell):
71 super(ParallelMagics, self).__init__(shell)
60 super(ParallelMagics, self).__init__(shell)
72 # A flag showing if autopx is activated or not
61 # A flag showing if autopx is activated or not
@@ -242,8 +231,9 b' class ParallelMagics(Magics):'
242 cell_name = ipself.compile.cache(cell, ipself.execution_count)
231 cell_name = ipself.compile.cache(cell, ipself.execution_count)
243
232
244 try:
233 try:
245 code_ast = ast.parse(cell, filename=cell_name)
234 ast.parse(cell, filename=cell_name)
246 except (OverflowError, SyntaxError, ValueError, TypeError, MemoryError):
235 except (OverflowError, SyntaxError, ValueError, TypeError,
236 MemoryError):
247 # Case 1
237 # Case 1
248 ipself.showsyntaxerror()
238 ipself.showsyntaxerror()
249 ipself.execution_count += 1
239 ipself.execution_count += 1
@@ -317,7 +307,6 b" __doc__ = __doc__.replace('@PX_DOC@',"
317 __doc__ = __doc__.replace('@RESULT_DOC@',
307 __doc__ = __doc__.replace('@RESULT_DOC@',
318 " " + ParallelMagics.result.__doc__)
308 " " + ParallelMagics.result.__doc__)
319
309
320
321 _loaded = False
310 _loaded = False
322
311
323
312
@@ -325,6 +314,5 b' def load_ipython_extension(ip):'
325 """Load the extension in IPython."""
314 """Load the extension in IPython."""
326 global _loaded
315 global _loaded
327 if not _loaded:
316 if not _loaded:
328 plugin = ParallelTricks(shell=ip, config=ip.config)
317 ip.register_magics(ParallelMagics)
329 ip.plugin_manager.register_plugin('parallelmagic', plugin)
330 _loaded = True
318 _loaded = True
General Comments 0
You need to be logged in to leave comments. Login now