##// END OF EJS Templates
Merge branch 'rm-install-ext'
Thomas Kluyver -
r22074:d953069d merge
parent child Browse files
Show More
@@ -0,0 +1,1 b''
1 Deleted the install_ext magic function
@@ -1,96 +1,67 b''
1 """Implementation of magic functions for the extension machinery.
1 """Implementation of magic functions for the extension machinery.
2 """
2 """
3 from __future__ import print_function
3 from __future__ import print_function
4 #-----------------------------------------------------------------------------
4 #-----------------------------------------------------------------------------
5 # Copyright (c) 2012 The IPython Development Team.
5 # Copyright (c) 2012 The IPython Development Team.
6 #
6 #
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8 #
8 #
9 # The full license is in the file COPYING.txt, distributed with this software.
9 # The full license is in the file COPYING.txt, distributed with this software.
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11
11
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13 # Imports
13 # Imports
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15
15
16 # Stdlib
16 # Stdlib
17 import os
17 import os
18
18
19 # Our own packages
19 # Our own packages
20 from IPython.core.error import UsageError
20 from IPython.core.error import UsageError
21 from IPython.core.magic import Magics, magics_class, line_magic
21 from IPython.core.magic import Magics, magics_class, line_magic
22 from warnings import warn
22 from warnings import warn
23
23
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25 # Magic implementation classes
25 # Magic implementation classes
26 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
27
27
28 @magics_class
28 @magics_class
29 class ExtensionMagics(Magics):
29 class ExtensionMagics(Magics):
30 """Magics to manage the IPython extensions system."""
30 """Magics to manage the IPython extensions system."""
31
31
32 @line_magic
32 @line_magic
33 def install_ext(self, parameter_s=''):
34 """Download and install an extension from a URL, e.g.::
35
36 %install_ext https://bitbucket.org/birkenfeld/ipython-physics/raw/d1310a2ab15d/physics.py
37
38 The URL should point to an importable Python module - either a .py file
39 or a .zip file.
40
41 Parameters:
42
43 -n filename : Specify a name for the file, rather than taking it from
44 the URL.
45 """
46 warn("%install_ext` is deprecated, please distribute your extension "
47 "as a python package.", UserWarning)
48 opts, args = self.parse_options(parameter_s, 'n:')
49 try:
50 filename = self.shell.extension_manager.install_extension(args,
51 opts.get('n'))
52 except ValueError as e:
53 print(e)
54 return
55
56 filename = os.path.basename(filename)
57 print("Installed %s. To use it, type:" % filename)
58 print(" %%load_ext %s" % os.path.splitext(filename)[0])
59
60
61 @line_magic
62 def load_ext(self, module_str):
33 def load_ext(self, module_str):
63 """Load an IPython extension by its module name."""
34 """Load an IPython extension by its module name."""
64 if not module_str:
35 if not module_str:
65 raise UsageError('Missing module name.')
36 raise UsageError('Missing module name.')
66 res = self.shell.extension_manager.load_extension(module_str)
37 res = self.shell.extension_manager.load_extension(module_str)
67
38
68 if res == 'already loaded':
39 if res == 'already loaded':
69 print("The %s extension is already loaded. To reload it, use:" % module_str)
40 print("The %s extension is already loaded. To reload it, use:" % module_str)
70 print(" %reload_ext", module_str)
41 print(" %reload_ext", module_str)
71 elif res == 'no load function':
42 elif res == 'no load function':
72 print("The %s module is not an IPython extension." % module_str)
43 print("The %s module is not an IPython extension." % module_str)
73
44
74 @line_magic
45 @line_magic
75 def unload_ext(self, module_str):
46 def unload_ext(self, module_str):
76 """Unload an IPython extension by its module name.
47 """Unload an IPython extension by its module name.
77
48
78 Not all extensions can be unloaded, only those which define an
49 Not all extensions can be unloaded, only those which define an
79 ``unload_ipython_extension`` function.
50 ``unload_ipython_extension`` function.
80 """
51 """
81 if not module_str:
52 if not module_str:
82 raise UsageError('Missing module name.')
53 raise UsageError('Missing module name.')
83
54
84 res = self.shell.extension_manager.unload_extension(module_str)
55 res = self.shell.extension_manager.unload_extension(module_str)
85
56
86 if res == 'no unload function':
57 if res == 'no unload function':
87 print("The %s extension doesn't define how to unload it." % module_str)
58 print("The %s extension doesn't define how to unload it." % module_str)
88 elif res == "not loaded":
59 elif res == "not loaded":
89 print("The %s extension is not loaded." % module_str)
60 print("The %s extension is not loaded." % module_str)
90
61
91 @line_magic
62 @line_magic
92 def reload_ext(self, module_str):
63 def reload_ext(self, module_str):
93 """Reload an IPython extension by its module name."""
64 """Reload an IPython extension by its module name."""
94 if not module_str:
65 if not module_str:
95 raise UsageError('Missing module name.')
66 raise UsageError('Missing module name.')
96 self.shell.extension_manager.reload_extension(module_str)
67 self.shell.extension_manager.reload_extension(module_str)
General Comments 0
You need to be logged in to leave comments. Login now