##// END OF EJS Templates
Fix magic directive and role....
Matthias Bussonnier -
Show More
@@ -4,4 +4,6 b''
4 autoreload
4 autoreload
5 ==========
5 ==========
6
6
7 .. magic:: autoreload
8
7 .. automodule:: IPython.extensions.autoreload
9 .. automodule:: IPython.extensions.autoreload
@@ -58,7 +58,7 b' Should behave as expected in the IPython REPL::'
58
58
59 You can use the ``c.InteractiveShell.autoawait`` configuration option and set it
59 You can use the ``c.InteractiveShell.autoawait`` configuration option and set it
60 to :any:`False` to deactivate automatic wrapping of asynchronous code. You can
60 to :any:`False` to deactivate automatic wrapping of asynchronous code. You can
61 also use the :magic:`%autoawait` magic to toggle the behavior at runtime::
61 also use the :magic:`autoawait` magic to toggle the behavior at runtime::
62
62
63 In [1]: %autoawait False
63 In [1]: %autoawait False
64
64
@@ -127,7 +127,7 b' Effects on IPython.embed()'
127 IPython core being asynchronous, the use of ``IPython.embed()`` will now require
127 IPython core being asynchronous, the use of ``IPython.embed()`` will now require
128 a loop to run. By default IPython will use a fake coroutine runner which should
128 a loop to run. By default IPython will use a fake coroutine runner which should
129 allow ``IPython.embed()`` to be nested. Though this will prevent usage of the
129 allow ``IPython.embed()`` to be nested. Though this will prevent usage of the
130 ``autoawait`` feature when using IPython embed.
130 :magic:`autoawait` feature when using IPython embed.
131
131
132 You can set explicitly a coroutine runner for ``embed()`` if you desire to run
132 You can set explicitly a coroutine runner for ``embed()`` if you desire to run
133 asynchronous code, the exact behavior is though undefined.
133 asynchronous code, the exact behavior is though undefined.
@@ -230,11 +230,12 b' Update ipykernel to version 5.0 or greater::'
230 # or
230 # or
231 conda install ipykernel ipython --upgrade
231 conda install ipykernel ipython --upgrade
232
232
233 This should automatically enable ``autoawait`` integration. Unlike terminal
233 This should automatically enable :magic:`autoawait` integration. Unlike
234 IPython, all code runs on ``asyncio`` eventloop, so creating a loop by hand will
234 terminal IPython, all code runs on ``asyncio`` eventloop, so creating a loop by
235 not work, including with magics like ``%run`` or other frameworks that create
235 hand will not work, including with magics like :magic:`%run` or other
236 the eventloop themselves. In cases like these you can try to use projects like
236 frameworks that create the eventloop themselves. In cases like these you can
237 `nest_asyncio <https://github.com/erdewit/nest_asyncio>`_ and follow `this discussion
237 try to use projects like `nest_asyncio
238 <https://github.com/erdewit/nest_asyncio>`_ and follow `this discussion
238 <https://github.com/jupyter/notebook/issues/3397#issuecomment-419386811>`_
239 <https://github.com/jupyter/notebook/issues/3397#issuecomment-419386811>`_
239
240
240 Difference between terminal IPython and IPykernel
241 Difference between terminal IPython and IPykernel
@@ -242,7 +243,7 b' Difference between terminal IPython and IPykernel'
242
243
243 The exact asynchronous code running behavior varies between Terminal IPython and
244 The exact asynchronous code running behavior varies between Terminal IPython and
244 IPykernel. The root cause of this behavior is due to IPykernel having a
245 IPykernel. The root cause of this behavior is due to IPykernel having a
245 *persistent* ``asyncio`` loop running, while Terminal IPython starts and stops a
246 *persistent* `asyncio` loop running, while Terminal IPython starts and stops a
246 loop for each code block. This can lead to surprising behavior in some case if
247 loop for each code block. This can lead to surprising behavior in some case if
247 you are used to manipulate asyncio loop yourself, see for example
248 you are used to manipulate asyncio loop yourself, see for example
248 :ghissue:`11303` for a longer discussion but here are some of the astonishing
249 :ghissue:`11303` for a longer discussion but here are some of the astonishing
@@ -114,10 +114,10 b' Non-Asynchronous code'
114 ~~~~~~~~~~~~~~~~~~~~~
114 ~~~~~~~~~~~~~~~~~~~~~
115
115
116 As the internal API of IPython are now asynchronous, IPython need to run under
116 As the internal API of IPython are now asynchronous, IPython need to run under
117 an even loop. In order to allow many workflow, (like using the ``%run`` magic,
117 an even loop. In order to allow many workflow, (like using the :magic:`%run`
118 or copy_pasting code that explicitly starts/stop event loop), when top-level code
118 magic, or copy_pasting code that explicitly starts/stop event loop), when
119 is detected as not being asynchronous, IPython code is advanced via a
119 top-level code is detected as not being asynchronous, IPython code is advanced
120 pseudo-synchronous runner, and will not may not advance pending tasks.
120 via a pseudo-synchronous runner, and will not may not advance pending tasks.
121
121
122 Change to Nested Embed
122 Change to Nested Embed
123 ~~~~~~~~~~~~~~~~~~~~~~
123 ~~~~~~~~~~~~~~~~~~~~~~
@@ -151,11 +151,17 b' minrk, njsmith, pganssle, tacaswell, takluyver , vidartf ... And many others.'
151 Autoreload Improvement
151 Autoreload Improvement
152 ----------------------
152 ----------------------
153
153
154 The magic ``%autoreload 2`` now captures new methods added to classes. Earlier, only methods existing as of the initial import were being tracked and updated.
154 The magic :magic:`%autoreload 2 <autoreload>` now captures new methods added to
155 classes. Earlier, only methods existing as of the initial import were being
156 tracked and updated.
155
157
156 This new feature helps dual environment development - Jupyter+IDE - where the code gradually moves from notebook cells to package files, as it gets structured.
158 This new feature helps dual environment development - Jupyter+IDE - where the
159 code gradually moves from notebook cells to package files, as it gets
160 structured.
157
161
158 **Example**: An instance of the class `MyClass` will be able to access the method `cube()` after it is uncommented and the file `file1.py` saved on disk.
162 **Example**: An instance of the class ``MyClass`` will be able to access the
163 method ``cube()`` after it is uncommented and the file ``file1.py`` saved on
164 disk.
159
165
160
166
161 ..code::
167 ..code::
@@ -191,13 +197,14 b' Misc'
191 The autoindent feature that was deprecated in 5.x was re-enabled and
197 The autoindent feature that was deprecated in 5.x was re-enabled and
192 un-deprecated in :ghpull:`11257`
198 un-deprecated in :ghpull:`11257`
193
199
194 Make ``%run -n -i ...`` work correctly. Earlier, if ``%run`` was passed both arguments, ``-n`` would be silently ignored. See :ghpull:`10308`
200 Make :magic:`%run -n -i ... <run>` work correctly. Earlier, if :magic:`%run` was
201 passed both arguments, ``-n`` would be silently ignored. See :ghpull:`10308`
195
202
196
203
197 The ``%%script`` (as well as ``%%bash``, ``ruby``... ) cell magics now raise
204 The :cellmagic:`%%script`` (as well as :cellmagic:`%%bash``,
198 by default if the return code of the given code is non-zero (thus halting
205 :cellmagic:`%%ruby``... ) cell magics now raise by default if the return code of
199 execution of further cells in a notebook). The behavior can be disable by
206 the given code is non-zero (thus halting execution of further cells in a
200 passing the ``--no-raise-error`` flag.
207 notebook). The behavior can be disable by passing the ``--no-raise-error`` flag.
201
208
202
209
203 Deprecations
210 Deprecations
@@ -19,6 +19,9 b' Authors'
19
19
20 from docutils import nodes, utils
20 from docutils import nodes, utils
21 from docutils.parsers.rst.roles import set_classes
21 from docutils.parsers.rst.roles import set_classes
22 from sphinx.util.logging import getLogger
23
24 info = getLogger(__name__).info
22
25
23 def make_link_node(rawtext, app, type, slug, options):
26 def make_link_node(rawtext, app, type, slug, options):
24 """Create a link to a github resource.
27 """Create a link to a github resource.
@@ -75,7 +78,7 b' def ghissue_role(name, rawtext, text, lineno, inliner, options={}, content=[]):'
75 prb = inliner.problematic(rawtext, rawtext, msg)
78 prb = inliner.problematic(rawtext, rawtext, msg)
76 return [prb], [msg]
79 return [prb], [msg]
77 app = inliner.document.settings.env.app
80 app = inliner.document.settings.env.app
78 #app.info('issue %r' % text)
81 #info('issue %r' % text)
79 if 'pull' in name.lower():
82 if 'pull' in name.lower():
80 category = 'pull'
83 category = 'pull'
81 elif 'issue' in name.lower():
84 elif 'issue' in name.lower():
@@ -105,7 +108,7 b' def ghuser_role(name, rawtext, text, lineno, inliner, options={}, content=[]):'
105 :param content: The directive content for customization.
108 :param content: The directive content for customization.
106 """
109 """
107 app = inliner.document.settings.env.app
110 app = inliner.document.settings.env.app
108 #app.info('user link %r' % text)
111 #info('user link %r' % text)
109 ref = 'https://www.github.com/' + text
112 ref = 'https://www.github.com/' + text
110 node = nodes.reference(rawtext, text, refuri=ref, **options)
113 node = nodes.reference(rawtext, text, refuri=ref, **options)
111 return [node], []
114 return [node], []
@@ -126,7 +129,7 b' def ghcommit_role(name, rawtext, text, lineno, inliner, options={}, content=[]):'
126 :param content: The directive content for customization.
129 :param content: The directive content for customization.
127 """
130 """
128 app = inliner.document.settings.env.app
131 app = inliner.document.settings.env.app
129 #app.info('user link %r' % text)
132 #info('user link %r' % text)
130 try:
133 try:
131 base = app.config.github_project_url
134 base = app.config.github_project_url
132 if not base:
135 if not base:
@@ -146,7 +149,7 b' def setup(app):'
146
149
147 :param app: Sphinx application context.
150 :param app: Sphinx application context.
148 """
151 """
149 app.info('Initializing GitHub plugin')
152 info('Initializing GitHub plugin')
150 app.add_role('ghissue', ghissue_role)
153 app.add_role('ghissue', ghissue_role)
151 app.add_role('ghpull', ghissue_role)
154 app.add_role('ghpull', ghissue_role)
152 app.add_role('ghuser', ghuser_role)
155 app.add_role('ghuser', ghuser_role)
@@ -37,9 +37,10 b' class CellMagicRole(LineMagicRole):'
37
37
38 def setup(app):
38 def setup(app):
39 app.add_object_type('magic', 'magic', 'pair: %s; magic command', parse_magic)
39 app.add_object_type('magic', 'magic', 'pair: %s; magic command', parse_magic)
40 StandardDomain.roles['magic'] = LineMagicRole()
40 app.add_role_to_domain('std', 'magic', LineMagicRole(), override=True)
41
41 app.add_object_type('cellmagic', 'cellmagic', 'pair: %s; cell magic', parse_cell_magic)
42 app.add_object_type('cellmagic', 'cellmagic', 'pair: %s; cell magic', parse_cell_magic)
42 StandardDomain.roles['cellmagic'] = CellMagicRole()
43 app.add_role_to_domain('std', 'cellmagic', CellMagicRole(), override=True)
43
44
44 metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
45 metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
45 return metadata
46 return metadata
General Comments 0
You need to be logged in to leave comments. Login now