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