##// END OF EJS Templates
Create core.magics.extension according to new API.
Fernando Perez -
Show More
@@ -0,0 +1,69 b''
1 """Implementation of magic functions for the extension machinery.
2 """
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2012 The IPython Development Team.
5 #
6 # Distributed under the terms of the Modified BSD License.
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
14
15 # Stdlib
16 import os
17
18 # Our own packages
19 from IPython.core.magic import Magics, register_magics, line_magic
20
21 #-----------------------------------------------------------------------------
22 # Magic implementation classes
23 #-----------------------------------------------------------------------------
24
25 @register_magics
26 class ExtensionMagics(Magics):
27 """Magics to manage the IPython extensions system."""
28
29 @line_magic
30 def install_ext(self, parameter_s=''):
31 """Download and install an extension from a URL, e.g.::
32
33 %install_ext https://bitbucket.org/birkenfeld/ipython-physics/raw/d1310a2ab15d/physics.py
34
35 The URL should point to an importable Python module - either a .py file
36 or a .zip file.
37
38 Parameters:
39
40 -n filename : Specify a name for the file, rather than taking it from
41 the URL.
42 """
43 opts, args = self.parse_options(parameter_s, 'n:')
44 try:
45 filename = self.shell.extension_manager.install_extension(args,
46 opts.get('n'))
47 except ValueError as e:
48 print e
49 return
50
51 filename = os.path.basename(filename)
52 print "Installed %s. To use it, type:" % filename
53 print " %%load_ext %s" % os.path.splitext(filename)[0]
54
55
56 @line_magic
57 def load_ext(self, module_str):
58 """Load an IPython extension by its module name."""
59 return self.shell.extension_manager.load_extension(module_str)
60
61 @line_magic
62 def unload_ext(self, module_str):
63 """Unload an IPython extension by its module name."""
64 self.shell.extension_manager.unload_extension(module_str)
65
66 @line_magic
67 def reload_ext(self, module_str):
68 """Reload an IPython extension by its module name."""
69 self.shell.extension_manager.reload_extension(module_str)
@@ -2007,7 +2007,7 b' class InteractiveShell(SingletonConfigurable):'
2007
2007
2008 self.register_magics(m.AutoMagics, m.BasicMagics, m.CodeMagics,
2008 self.register_magics(m.AutoMagics, m.BasicMagics, m.CodeMagics,
2009 m.ConfigMagics, mf.DeprecatedMagics, m.ExecutionMagics,
2009 m.ConfigMagics, mf.DeprecatedMagics, m.ExecutionMagics,
2010 mf.ExtensionsMagics, m.HistoryMagics, m.LoggingMagics,
2010 m.ExtensionMagics, m.HistoryMagics, m.LoggingMagics,
2011 m.NamespaceMagics, m.OSMagics, mf.PylabMagics )
2011 m.NamespaceMagics, m.OSMagics, mf.PylabMagics )
2012
2012
2013 # FIXME: Move the color initialization to the DisplayHook, which
2013 # FIXME: Move the color initialization to the DisplayHook, which
@@ -14,9 +14,6 b''
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 # Stdlib
18 import os
19
20 # Our own packages
17 # Our own packages
21 from IPython.config.application import Application
18 from IPython.config.application import Application
22 from IPython.core.magic import Magics, register_magics, line_magic
19 from IPython.core.magic import Magics, register_magics, line_magic
@@ -27,53 +24,6 b' from IPython.testing.skipdoctest import skip_doctest'
27 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
28
25
29 @register_magics
26 @register_magics
30 class ExtensionsMagics(Magics):
31 """Magics to manage the IPython extensions system."""
32
33 @line_magic
34 def install_ext(self, parameter_s=''):
35 """Download and install an extension from a URL, e.g.::
36
37 %install_ext https://bitbucket.org/birkenfeld/ipython-physics/raw/d1310a2ab15d/physics.py
38
39 The URL should point to an importable Python module - either a .py file
40 or a .zip file.
41
42 Parameters:
43
44 -n filename : Specify a name for the file, rather than taking it from
45 the URL.
46 """
47 opts, args = self.parse_options(parameter_s, 'n:')
48 try:
49 filename = self.shell.extension_manager.install_extension(args,
50 opts.get('n'))
51 except ValueError as e:
52 print e
53 return
54
55 filename = os.path.basename(filename)
56 print "Installed %s. To use it, type:" % filename
57 print " %%load_ext %s" % os.path.splitext(filename)[0]
58
59
60 @line_magic
61 def load_ext(self, module_str):
62 """Load an IPython extension by its module name."""
63 return self.shell.extension_manager.load_extension(module_str)
64
65 @line_magic
66 def unload_ext(self, module_str):
67 """Unload an IPython extension by its module name."""
68 self.shell.extension_manager.unload_extension(module_str)
69
70 @line_magic
71 def reload_ext(self, module_str):
72 """Reload an IPython extension by its module name."""
73 self.shell.extension_manager.reload_extension(module_str)
74
75
76 @register_magics
77 class PylabMagics(Magics):
27 class PylabMagics(Magics):
78 """Magics related to matplotlib's pylab support"""
28 """Magics related to matplotlib's pylab support"""
79
29
@@ -18,6 +18,7 b' from .basic import BasicMagics'
18 from .code import CodeMagics, MacroToEdit
18 from .code import CodeMagics, MacroToEdit
19 from .config import ConfigMagics
19 from .config import ConfigMagics
20 from .execution import ExecutionMagics
20 from .execution import ExecutionMagics
21 from .extension import ExtensionMagics
21 from .history import HistoryMagics
22 from .history import HistoryMagics
22 from .logging import LoggingMagics
23 from .logging import LoggingMagics
23 from .namespace import NamespaceMagics
24 from .namespace import NamespaceMagics
General Comments 0
You need to be logged in to leave comments. Login now