Show More
@@ -0,0 +1,1 b'' | |||
|
1 | Deleted the install_ext magic function |
@@ -1,96 +1,67 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 | 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 | 33 | def load_ext(self, module_str): |
|
63 | 34 | """Load an IPython extension by its module name.""" |
|
64 | 35 | if not module_str: |
|
65 | 36 | raise UsageError('Missing module name.') |
|
66 | 37 | res = self.shell.extension_manager.load_extension(module_str) |
|
67 | 38 | |
|
68 | 39 | if res == 'already loaded': |
|
69 | 40 | print("The %s extension is already loaded. To reload it, use:" % module_str) |
|
70 | 41 | print(" %reload_ext", module_str) |
|
71 | 42 | elif res == 'no load function': |
|
72 | 43 | print("The %s module is not an IPython extension." % module_str) |
|
73 | 44 | |
|
74 | 45 | @line_magic |
|
75 | 46 | def unload_ext(self, module_str): |
|
76 | 47 | """Unload an IPython extension by its module name. |
|
77 | 48 | |
|
78 | 49 | Not all extensions can be unloaded, only those which define an |
|
79 | 50 | ``unload_ipython_extension`` function. |
|
80 | 51 | """ |
|
81 | 52 | if not module_str: |
|
82 | 53 | raise UsageError('Missing module name.') |
|
83 | 54 | |
|
84 | 55 | res = self.shell.extension_manager.unload_extension(module_str) |
|
85 | 56 | |
|
86 | 57 | if res == 'no unload function': |
|
87 | 58 | print("The %s extension doesn't define how to unload it." % module_str) |
|
88 | 59 | elif res == "not loaded": |
|
89 | 60 | print("The %s extension is not loaded." % module_str) |
|
90 | 61 | |
|
91 | 62 | @line_magic |
|
92 | 63 | def reload_ext(self, module_str): |
|
93 | 64 | """Reload an IPython extension by its module name.""" |
|
94 | 65 | if not module_str: |
|
95 | 66 | raise UsageError('Missing module name.') |
|
96 | 67 | self.shell.extension_manager.reload_extension(module_str) |
General Comments 0
You need to be logged in to leave comments.
Login now