Show More
@@ -88,9 +88,9 b' IPython object:' | |||
|
88 | 88 | |
|
89 | 89 | def load_ipython_extension(ipython): |
|
90 | 90 | """ |
|
91 |
Any |
|
|
92 |
be loaded via `load_ext` or be configured to be |
|
|
93 | startup time. | |
|
91 | Any module file that define a function named `load_ipython_extension` | |
|
92 | can be loaded via `%load_ext module.path` or be configured to be | |
|
93 | autoloaded by IPython at startup time. | |
|
94 | 94 | """ |
|
95 | 95 | # You can register the class itself without instantiating it. IPython will |
|
96 | 96 | # call the default constructor on it. |
@@ -115,13 +115,13 b' instantiate the class yourself before registration:' | |||
|
115 | 115 | |
|
116 | 116 | def load_ipython_extension(ipython): |
|
117 | 117 | """ |
|
118 |
Any |
|
|
119 |
be loaded via `load_ext` or be configured to be |
|
|
120 | startup time. | |
|
118 | Any module file that define a function named `load_ipython_extension` | |
|
119 | can be loaded via `%load_ext module.path` or be configured to be | |
|
120 | autoloaded by IPython at startup time. | |
|
121 | 121 | """ |
|
122 | 122 | # This class must then be registered with a manually created instance, |
|
123 | 123 | # since its constructor has different arguments from the default: |
|
124 | magics = StatefulMagics(ip, some_data) | |
|
124 | magics = StatefulMagics(ipython, some_data) | |
|
125 | 125 | ipython.register_magics(magics) |
|
126 | 126 | |
|
127 | 127 | |
@@ -133,3 +133,47 b' instantiate the class yourself before registration:' | |||
|
133 | 133 | in IPython 5. Maintainers of IPython extensions that still use the |
|
134 | 134 | :func:`define_magic` function are advised to adjust their code |
|
135 | 135 | for the current API. |
|
136 | ||
|
137 | Complete Example | |
|
138 | ================ | |
|
139 | ||
|
140 | Here is a full example of a magic package. You can distribute magics using | |
|
141 | setuptools, distutils, or any other distribution tools like `flit | |
|
142 | <http://flit.readthedocs.io>` for pure Python packages. | |
|
143 | ||
|
144 | ||
|
145 | .. sourcecode:: | |
|
146 | ||
|
147 | . | |
|
148 | ├── example_magic | |
|
149 | │ ├── __init__.py | |
|
150 | │ └── abracadabra.py | |
|
151 | └── setup.py | |
|
152 | ||
|
153 | .. sourcecode:: | |
|
154 | ||
|
155 | $ cat example_magic/__init__.py | |
|
156 | """An example magic""" | |
|
157 | __version__ = '0.0.1' | |
|
158 | ||
|
159 | from .abracadabra import Abracadabra | |
|
160 | ||
|
161 | def load_ipython_extension(ipython): | |
|
162 | ipython.register_magics(Abracadabra) | |
|
163 | ||
|
164 | .. sourcecode:: | |
|
165 | ||
|
166 | $ cat example_magic/abracadabra.py | |
|
167 | from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic) | |
|
168 | ||
|
169 | @magics_class | |
|
170 | class Abracadabra(Magics): | |
|
171 | ||
|
172 | @line_magic | |
|
173 | def abra(self, line): | |
|
174 | return line | |
|
175 | ||
|
176 | @cell_magic | |
|
177 | def cadabra(self, line, cell): | |
|
178 | return line, cell | |
|
179 |
General Comments 0
You need to be logged in to leave comments.
Login now