##// END OF EJS Templates
Fixes, plus complete example....
Matthias Bussonnier -
Show More
@@ -88,9 +88,9 b' IPython object:'
88
88
89 def load_ipython_extension(ipython):
89 def load_ipython_extension(ipython):
90 """
90 """
91 Any nodule file that define a function named load_ipython_extension can
91 Any module file that define a function named `load_ipython_extension`
92 be loaded via `load_ext` or be configured to be autoloaded by IPython at
92 can be loaded via `%load_ext module.path` or be configured to be
93 startup time.
93 autoloaded by IPython at startup time.
94 """
94 """
95 # You can register the class itself without instantiating it. IPython will
95 # You can register the class itself without instantiating it. IPython will
96 # call the default constructor on it.
96 # call the default constructor on it.
@@ -115,13 +115,13 b' instantiate the class yourself before registration:'
115
115
116 def load_ipython_extension(ipython):
116 def load_ipython_extension(ipython):
117 """
117 """
118 Any nodule file that define a function named load_ipython_extension can
118 Any module file that define a function named `load_ipython_extension`
119 be loaded via `load_ext` or be configured to be autoloaded by IPython at
119 can be loaded via `%load_ext module.path` or be configured to be
120 startup time.
120 autoloaded by IPython at startup time.
121 """
121 """
122 # This class must then be registered with a manually created instance,
122 # This class must then be registered with a manually created instance,
123 # since its constructor has different arguments from the default:
123 # since its constructor has different arguments from the default:
124 magics = StatefulMagics(ip, some_data)
124 magics = StatefulMagics(ipython, some_data)
125 ipython.register_magics(magics)
125 ipython.register_magics(magics)
126
126
127
127
@@ -133,3 +133,47 b' instantiate the class yourself before registration:'
133 in IPython 5. Maintainers of IPython extensions that still use the
133 in IPython 5. Maintainers of IPython extensions that still use the
134 :func:`define_magic` function are advised to adjust their code
134 :func:`define_magic` function are advised to adjust their code
135 for the current API.
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