Show More
@@ -150,14 +150,16 b' def removed_co_newlocals(function:types.FunctionType) -> types.FunctionType:' | |||||
150 | return FunctionType(new_code, globals(), function.__name__, function.__defaults__) |
|
150 | return FunctionType(new_code, globals(), function.__name__, function.__defaults__) | |
151 |
|
151 | |||
152 |
|
152 | |||
|
153 | # we still need to run things using the asyncio eventloop, but there is no | |||
|
154 | # async integration | |||
|
155 | from .async_helpers import (_asyncio_runner, _asyncify) | |||
|
156 | ||||
153 | if sys.version_info > (3,5): |
|
157 | if sys.version_info > (3,5): | |
154 |
from .async_helpers import |
|
158 | from .async_helpers import _curio_runner, _trio_runner, _should_be_async | |
155 | _should_be_async, _asyncify |
|
|||
156 | ) |
|
|||
157 | else : |
|
159 | else : | |
158 |
|
|
160 | _curio_runner = _trio_runner = None | |
159 |
|
161 | |||
160 |
def _should_be_async( |
|
162 | def _should_be_async(cell:str)->bool: | |
161 | return False |
|
163 | return False | |
162 |
|
164 | |||
163 |
|
165 | |||
@@ -2200,6 +2202,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
2200 | m.ExtensionMagics, m.HistoryMagics, m.LoggingMagics, |
|
2202 | m.ExtensionMagics, m.HistoryMagics, m.LoggingMagics, | |
2201 | m.NamespaceMagics, m.OSMagics, m.PylabMagics, m.ScriptMagics, |
|
2203 | m.NamespaceMagics, m.OSMagics, m.PylabMagics, m.ScriptMagics, | |
2202 | ) |
|
2204 | ) | |
|
2205 | if sys.version_info >(3,5): | |||
|
2206 | self.register_magics(m.AsyncMagics) | |||
2203 |
|
2207 | |||
2204 | # Register Magic Aliases |
|
2208 | # Register Magic Aliases | |
2205 | mman = self.magics_manager |
|
2209 | mman = self.magics_manager |
@@ -14,7 +14,7 b'' | |||||
14 |
|
14 | |||
15 | from ..magic import Magics, magics_class |
|
15 | from ..magic import Magics, magics_class | |
16 | from .auto import AutoMagics |
|
16 | from .auto import AutoMagics | |
17 | from .basic import BasicMagics |
|
17 | from .basic import BasicMagics, AsyncMagics | |
18 | from .code import CodeMagics, MacroToEdit |
|
18 | from .code import CodeMagics, MacroToEdit | |
19 | from .config import ConfigMagics |
|
19 | from .config import ConfigMagics | |
20 | from .display import DisplayMagics |
|
20 | from .display import DisplayMagics |
@@ -379,62 +379,6 b' Currently the magic system has the following functions:""",' | |||||
379 | except: |
|
379 | except: | |
380 | xmode_switch_err('user') |
|
380 | xmode_switch_err('user') | |
381 |
|
381 | |||
382 | @line_magic |
|
|||
383 | def autoawait(self, parameter_s): |
|
|||
384 | """ |
|
|||
385 | Allow to change the status of the autoawait option. |
|
|||
386 |
|
||||
387 | This allow you to set a specific asynchronous code runner. |
|
|||
388 |
|
||||
389 | If no value is passed, print the currently used asynchronous integration |
|
|||
390 | and whether it is activated. |
|
|||
391 |
|
||||
392 | It can take a number of value evaluated in the following order: |
|
|||
393 |
|
||||
394 | - False/false/off deactivate autoawait integration |
|
|||
395 | - True/true/on activate autoawait integration using configured default |
|
|||
396 | loop |
|
|||
397 | - asyncio/curio/trio activate autoawait integration and use integration |
|
|||
398 | with said library. |
|
|||
399 |
|
||||
400 | If the passed parameter does not match any of the above and is a python |
|
|||
401 | identifier, get said object from user namespace and set it as the |
|
|||
402 | runner, and activate autoawait. |
|
|||
403 |
|
||||
404 | If the object is a fully qualified object name, attempt to import it and |
|
|||
405 | set it as the runner, and activate autoawait.""" |
|
|||
406 |
|
||||
407 | param = parameter_s.strip() |
|
|||
408 | d = {True: "on", False: "off"} |
|
|||
409 |
|
||||
410 | if not param: |
|
|||
411 | print("IPython autoawait is `{}`, and set to use `{}`".format( |
|
|||
412 | d[self.shell.autoawait], |
|
|||
413 | self.shell.loop_runner |
|
|||
414 | )) |
|
|||
415 | return None |
|
|||
416 |
|
||||
417 | if param.lower() in ('false', 'off'): |
|
|||
418 | self.shell.autoawait = False |
|
|||
419 | return None |
|
|||
420 | if param.lower() in ('true', 'on'): |
|
|||
421 | self.shell.autoawait = True |
|
|||
422 | return None |
|
|||
423 |
|
||||
424 | if param in self.shell.loop_runner_map: |
|
|||
425 | self.shell.loop_runner = param |
|
|||
426 | self.shell.autoawait = True |
|
|||
427 | return None |
|
|||
428 |
|
||||
429 | if param in self.shell.user_ns : |
|
|||
430 | self.shell.loop_runner = self.shell.user_ns[param] |
|
|||
431 | self.shell.autoawait = True |
|
|||
432 | return None |
|
|||
433 |
|
||||
434 | runner = import_item(param) |
|
|||
435 |
|
||||
436 | self.shell.loop_runner = runner |
|
|||
437 | self.shell.autoawait = True |
|
|||
438 |
|
382 | |||
439 |
|
383 | |||
440 | @line_magic |
|
384 | @line_magic | |
@@ -656,3 +600,63 b' Currently the magic system has the following functions:""",' | |||||
656 | nb = v4.new_notebook(cells=cells) |
|
600 | nb = v4.new_notebook(cells=cells) | |
657 | with io.open(args.filename, 'w', encoding='utf-8') as f: |
|
601 | with io.open(args.filename, 'w', encoding='utf-8') as f: | |
658 | write(nb, f, version=4) |
|
602 | write(nb, f, version=4) | |
|
603 | ||||
|
604 | @magics_class | |||
|
605 | class AsyncMagics(BasicMagics): | |||
|
606 | ||||
|
607 | @line_magic | |||
|
608 | def autoawait(self, parameter_s): | |||
|
609 | """ | |||
|
610 | Allow to change the status of the autoawait option. | |||
|
611 | ||||
|
612 | This allow you to set a specific asynchronous code runner. | |||
|
613 | ||||
|
614 | If no value is passed, print the currently used asynchronous integration | |||
|
615 | and whether it is activated. | |||
|
616 | ||||
|
617 | It can take a number of value evaluated in the following order: | |||
|
618 | ||||
|
619 | - False/false/off deactivate autoawait integration | |||
|
620 | - True/true/on activate autoawait integration using configured default | |||
|
621 | loop | |||
|
622 | - asyncio/curio/trio activate autoawait integration and use integration | |||
|
623 | with said library. | |||
|
624 | ||||
|
625 | If the passed parameter does not match any of the above and is a python | |||
|
626 | identifier, get said object from user namespace and set it as the | |||
|
627 | runner, and activate autoawait. | |||
|
628 | ||||
|
629 | If the object is a fully qualified object name, attempt to import it and | |||
|
630 | set it as the runner, and activate autoawait.""" | |||
|
631 | ||||
|
632 | param = parameter_s.strip() | |||
|
633 | d = {True: "on", False: "off"} | |||
|
634 | ||||
|
635 | if not param: | |||
|
636 | print("IPython autoawait is `{}`, and set to use `{}`".format( | |||
|
637 | d[self.shell.autoawait], | |||
|
638 | self.shell.loop_runner | |||
|
639 | )) | |||
|
640 | return None | |||
|
641 | ||||
|
642 | if param.lower() in ('false', 'off'): | |||
|
643 | self.shell.autoawait = False | |||
|
644 | return None | |||
|
645 | if param.lower() in ('true', 'on'): | |||
|
646 | self.shell.autoawait = True | |||
|
647 | return None | |||
|
648 | ||||
|
649 | if param in self.shell.loop_runner_map: | |||
|
650 | self.shell.loop_runner = param | |||
|
651 | self.shell.autoawait = True | |||
|
652 | return None | |||
|
653 | ||||
|
654 | if param in self.shell.user_ns : | |||
|
655 | self.shell.loop_runner = self.shell.user_ns[param] | |||
|
656 | self.shell.autoawait = True | |||
|
657 | return None | |||
|
658 | ||||
|
659 | runner = import_item(param) | |||
|
660 | ||||
|
661 | self.shell.loop_runner = runner | |||
|
662 | self.shell.autoawait = True |
General Comments 0
You need to be logged in to leave comments.
Login now