##// END OF EJS Templates
Fix grammar and spacing in a warning message
Aaron Meurer -
Show More
@@ -1,96 +1,96 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=''):
33 def install_ext(self, parameter_s=''):
34 """Download and install an extension from a URL, e.g.::
34 """Download and install an extension from a URL, e.g.::
35
35
36 %install_ext https://bitbucket.org/birkenfeld/ipython-physics/raw/d1310a2ab15d/physics.py
36 %install_ext https://bitbucket.org/birkenfeld/ipython-physics/raw/d1310a2ab15d/physics.py
37
37
38 The URL should point to an importable Python module - either a .py file
38 The URL should point to an importable Python module - either a .py file
39 or a .zip file.
39 or a .zip file.
40
40
41 Parameters:
41 Parameters:
42
42
43 -n filename : Specify a name for the file, rather than taking it from
43 -n filename : Specify a name for the file, rather than taking it from
44 the URL.
44 the URL.
45 """
45 """
46 warn("%install_ext` is deprecated, please distribute your extension(s)"
46 warn("%install_ext` is deprecated, please distribute your extension "
47 "as a python packages.", UserWarning)
47 "as a python package.", UserWarning)
48 opts, args = self.parse_options(parameter_s, 'n:')
48 opts, args = self.parse_options(parameter_s, 'n:')
49 try:
49 try:
50 filename = self.shell.extension_manager.install_extension(args,
50 filename = self.shell.extension_manager.install_extension(args,
51 opts.get('n'))
51 opts.get('n'))
52 except ValueError as e:
52 except ValueError as e:
53 print(e)
53 print(e)
54 return
54 return
55
55
56 filename = os.path.basename(filename)
56 filename = os.path.basename(filename)
57 print("Installed %s. To use it, type:" % filename)
57 print("Installed %s. To use it, type:" % filename)
58 print(" %%load_ext %s" % os.path.splitext(filename)[0])
58 print(" %%load_ext %s" % os.path.splitext(filename)[0])
59
59
60
60
61 @line_magic
61 @line_magic
62 def load_ext(self, module_str):
62 def load_ext(self, module_str):
63 """Load an IPython extension by its module name."""
63 """Load an IPython extension by its module name."""
64 if not module_str:
64 if not module_str:
65 raise UsageError('Missing module name.')
65 raise UsageError('Missing module name.')
66 res = self.shell.extension_manager.load_extension(module_str)
66 res = self.shell.extension_manager.load_extension(module_str)
67
67
68 if res == 'already loaded':
68 if res == 'already loaded':
69 print("The %s extension is already loaded. To reload it, use:" % module_str)
69 print("The %s extension is already loaded. To reload it, use:" % module_str)
70 print(" %reload_ext", module_str)
70 print(" %reload_ext", module_str)
71 elif res == 'no load function':
71 elif res == 'no load function':
72 print("The %s module is not an IPython extension." % module_str)
72 print("The %s module is not an IPython extension." % module_str)
73
73
74 @line_magic
74 @line_magic
75 def unload_ext(self, module_str):
75 def unload_ext(self, module_str):
76 """Unload an IPython extension by its module name.
76 """Unload an IPython extension by its module name.
77
77
78 Not all extensions can be unloaded, only those which define an
78 Not all extensions can be unloaded, only those which define an
79 ``unload_ipython_extension`` function.
79 ``unload_ipython_extension`` function.
80 """
80 """
81 if not module_str:
81 if not module_str:
82 raise UsageError('Missing module name.')
82 raise UsageError('Missing module name.')
83
83
84 res = self.shell.extension_manager.unload_extension(module_str)
84 res = self.shell.extension_manager.unload_extension(module_str)
85
85
86 if res == 'no unload function':
86 if res == 'no unload function':
87 print("The %s extension doesn't define how to unload it." % module_str)
87 print("The %s extension doesn't define how to unload it." % module_str)
88 elif res == "not loaded":
88 elif res == "not loaded":
89 print("The %s extension is not loaded." % module_str)
89 print("The %s extension is not loaded." % module_str)
90
90
91 @line_magic
91 @line_magic
92 def reload_ext(self, module_str):
92 def reload_ext(self, module_str):
93 """Reload an IPython extension by its module name."""
93 """Reload an IPython extension by its module name."""
94 if not module_str:
94 if not module_str:
95 raise UsageError('Missing module name.')
95 raise UsageError('Missing module name.')
96 self.shell.extension_manager.reload_extension(module_str)
96 self.shell.extension_manager.reload_extension(module_str)
General Comments 0
You need to be logged in to leave comments. Login now