ipshell
Defines an IPython compatible shell.
Classes:
-
NullContext–A context that does nothing that can be used where a context is expected.
-
IPDisplayHook–Called by the kernel whenever the interpreter needs to display results.
-
IPDisplayPublisher–A display publisher used by IPython.display.publish_display_data.
-
IPHistoryManager–A class to organize history-related functionality in one place.
-
IPShell–An IPython InteractiveShell implementation.
NullContext
¶
A context that does nothing that can be used where a context is expected.
-
Reference
ipshell
IPShellbuiltin_trap
Source code in src/async_kernel/shell/ipshell.py
75 76 77 78 79 80 81 82 83 84 | |
IPDisplayHook
¶
Bases: HasInterface, DisplayHook
Called by the kernel whenever the interpreter needs to display results.
The output is always published with msg_type="execute_result".
-
Reference
ipshell
IPShelldisplayhook
-
Reference
ipshell
IPShelldisplayhook_class
Methods:
-
__call__–Publish the result.
Source code in src/async_kernel/shell/ipshell.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
__call__
¶
__call__(result=None) -> None
Publish the result.
This is invoked every time the interpreter needs to print, and is activated by setting the variable sys.displayhook to it.
Source code in src/async_kernel/shell/ipshell.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
IPDisplayPublisher
¶
Bases: HasInterface, DisplayPublisher
A display publisher used by IPython.display.publish_display_data.
-
Reference
ipshell
IPShelldisplay_pub
-
Reference
ipshell
IPShelldisplay_pub_class
Methods:
-
publish–Publish a display-data message.
-
clear_output–Clear output associated with the current execution (cell).
-
register_hook–Register a hook for when publish is called.
Source code in src/async_kernel/shell/ipshell.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
publish
¶
publish(
data: dict[str, Any],
metadata: dict | None = None,
*,
transient: dict | None = None,
update: bool = False,
**kwargs,
) -> None
Publish a display-data message.
Parameters:
-
(data¶dict[str, Any]) –A mime-bundle dict, keyed by mime-type.
-
(metadata¶dict | None, default:None) –Metadata associated with the data.
-
(transient¶dict | None, default:None) –Transient data that may only be relevant during a live display, such as display_id. Transient data should not be persisted to documents.
-
(update¶bool, default:False) –If True, send an update_display_data message instead of display_data.
Source code in src/async_kernel/shell/ipshell.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
clear_output
¶
Clear output associated with the current execution (cell).
Parameters:
-
(wait¶bool, default:False) –If True, the output will not be cleared immediately, instead waiting for the next display before clearing. This reduces bounce during repeated clear & display loops.
Source code in src/async_kernel/shell/ipshell.py
202 203 204 205 206 207 208 209 210 211 212 | |
register_hook
¶
Register a hook for when publish is called.
The hook should return the message or None.
Only return None when the message should not be sent.
Source code in src/async_kernel/shell/ipshell.py
214 215 216 217 218 219 220 | |
IPHistoryManager
¶
Bases: HasInterface[BaseInterface['IPShell']], HistoryManager
A class to organize history-related functionality in one place.
-
Reference
ipshell
IPShellhistory_manager
-
Reference
ipshell
IPShellhistory_manager
Methods:
-
__init__–Create a new history manager associated with a shell instance.
Source code in src/async_kernel/shell/ipshell.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
__init__
¶
__init__(*, shell: IPShell) -> None
Source code in src/async_kernel/shell/ipshell.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
IPShell
¶
Bases: BaseShell, InteractiveShell
An IPython InteractiveShell implementation.
-
Reference
ipshell
IPHistoryManager__init__
Methods:
-
apply_patches–Apply patches returning a callable to reverse the patches.
-
init_hooks–Initialize hooks.
-
run_line_magic_async–Call and awaits run_line_magic.
-
run_cell_magic_async–Call and awaits run_cell_magic.
-
system–Make a system call in a separate thread.
-
run_code–Execute a code object.
-
transform_cell_async–Transform the cell and substitute magic calls with an awaitable wrapper.
-
do_execute–Execute code in the shell's user_ns and global_ns.
-
do_complete– -
is_complete– -
do_inspect– -
do_history– -
init_magics–Initialize magics.
-
enable_matplotlib–Enable interactive matplotlib and inline figure support.
Attributes:
-
timeout–A timeout in seconds to complete execute requests.
-
stop_on_error_time_offset–An offset to add to the cancellation time to catch late arriving execute requests.
-
default_matplotlib_backends– -
compiler_class– -
prefilter_manager_class– -
displayhook_class– -
display_pub_class– -
display_formatter_class– -
configurables–Not used. Provided for compatibility.
-
compile(Fixed[Self, XCachingCompiler]) –The compiler: provides a filename for a selection of code (cell).
-
prefilter_manager(Fixed[Self, IPPrefilterManager]) – -
extension_manager(Fixed[Self, IPExtensionManager]) –A manager for loading extensions.
-
builtin_trap–A nullcontext.
-
displayhook(Fixed[Self, IPDisplayHook]) –An implementation of sys.displayhook.
-
display_pub(Fixed[Self, IPDisplayPublisher]) –Used for publishing output generated by calls made to IPython.display.display which calls IPython.display.publish_display_data.
-
display_formatter(Fixed[Self, IPDisplayFormatter]) –An object capable of transforming python objects to MIME content.
-
history_manager(Fixed[Self, IPHistoryManager]) –
Source code in src/async_kernel/shell/ipshell.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 | |
timeout
class-attribute
instance-attribute
¶
timeout = traitlets.CFloat(0.0).tag(config=True)
A timeout in seconds to complete execute requests.
stop_on_error_time_offset
class-attribute
instance-attribute
¶
stop_on_error_time_offset = traitlets.Float(0.0).tag(config=True)
An offset to add to the cancellation time to catch late arriving execute requests.
default_matplotlib_backends
class-attribute
instance-attribute
¶
default_matplotlib_backends = traitlets.List(['inline', 'ipympl']).tag(config=True)
compiler_class
class-attribute
instance-attribute
¶
compiler_class = traitlets.Type(XCachingCompiler).tag(config=True)
prefilter_manager_class
class-attribute
instance-attribute
¶
prefilter_manager_class = traitlets.Type(IPPrefilterManager).tag(config=True)
displayhook_class
class-attribute
instance-attribute
¶
displayhook_class = traitlets.Type(IPDisplayHook).tag(config=True)
display_pub_class
class-attribute
instance-attribute
¶
display_pub_class = traitlets.Type(IPDisplayPublisher).tag(config=True)
display_formatter_class
class-attribute
instance-attribute
¶
display_formatter_class = traitlets.Type(IPDisplayFormatter).tag(config=True)
configurables
class-attribute
instance-attribute
¶
Not used. Provided for compatibility.
compile
class-attribute
instance-attribute
¶
The compiler: provides a filename for a selection of code (cell).
prefilter_manager
class-attribute
instance-attribute
¶
prefilter_manager: Fixed[Self, IPPrefilterManager] = Fixed(
lambda c: c["owner"].prefilter_manager_class(shell=c["owner"])
)
extension_manager
class-attribute
instance-attribute
¶
extension_manager: Fixed[Self, IPExtensionManager] = Fixed(
lambda c: IPExtensionManager(shell=c["owner"])
)
A manager for loading extensions.
builtin_trap
class-attribute
instance-attribute
¶
builtin_trap = Fixed(NullContext)
A nullcontext.
Builtins are not dynamically modified.
displayhook
class-attribute
instance-attribute
¶
displayhook: Fixed[Self, IPDisplayHook] = Fixed(
lambda c: c["owner"].displayhook_class(c["owner"])
)
An implementation of sys.displayhook.
async_kernel.kernel.Kernel.displayhook patches sys.displayhook routing execution results to the shell whose context the execution result occurred.
display_pub
class-attribute
instance-attribute
¶
display_pub: Fixed[Self, IPDisplayPublisher] = Fixed(
lambda c: c["owner"].display_pub_class()
)
Used for publishing output generated by calls made to IPython.display.display which calls IPython.display.publish_display_data.
display_formatter
class-attribute
instance-attribute
¶
display_formatter: Fixed[Self, IPDisplayFormatter] = Fixed(
lambda c: c["owner"].display_formatter_class()
)
An object capable of transforming python objects to MIME content.
Notes
- Primarily used in IPython.core.interactiveshell.InteractiveShell.user_expressions.
- Ipython docs.
history_manager
class-attribute
instance-attribute
¶
history_manager: Fixed[Self, IPHistoryManager] = Fixed(
lambda c: IPHistoryManager(shell=c["owner"]), mode="ignore"
)
apply_patches
¶
apply_patches() -> Callable[[], None]
Apply patches returning a callable to reverse the patches.
Source code in src/async_kernel/shell/ipshell.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
init_hooks
¶
init_hooks() -> None
Initialize hooks.
Source code in src/async_kernel/shell/ipshell.py
523 524 525 526 527 528 529 530 531 532 533 534 535 | |
run_line_magic_async
async
¶
Call and awaits run_line_magic.
Source code in src/async_kernel/shell/ipshell.py
558 559 560 561 562 563 564 565 | |
run_cell_magic_async
async
¶
Call and awaits run_cell_magic.
Source code in src/async_kernel/shell/ipshell.py
567 568 569 570 571 572 573 574 | |
system
¶
Make a system call in a separate thread.
Parameters:
-
(cmd¶list[str] | str) –Passed as the first argument 'command' when calling anyio.open_process.
-
(stderr_to_stdout¶bool, default:False) –Send stderr output to stdout.
-
(**kwargs¶Any, default:{}) –Keyword arguments are passed to anyio.open_process.
Tip
- The output can be redicted by making the call in the context of async_kernel.utils.redirect_stdout and/or async_kernel.utils.redirect_stderr.
Source code in src/async_kernel/shell/ipshell.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
run_code
async
¶
run_code(
code_obj: CodeType, result: ExecutionResult | None = None, *, async_: bool = False
) -> bool
Execute a code object.
When an exception occurs, self.showtraceback() is called to display a traceback.
Parameters:
-
(code_obj¶CodeType) –A compiled code object, to be executed.
-
(result¶ExecutionResult | None, default:None) –An object to store exceptions that occur during execution.
-
(async_¶bool, default:False) –(Experimental) Attempt to run top-level asynchronous code in a default loop.
Returns:
Source code in src/async_kernel/shell/ipshell.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | |
transform_cell_async
¶
Transform the cell and substitute magic calls with an awaitable wrapper.
Source code in src/async_kernel/shell/ipshell.py
638 639 640 641 642 643 644 645 646 | |
do_execute
async
¶
do_execute(
code: str = "",
*,
silent: bool = False,
store_history: bool = False,
user_expressions: dict[str, str] | None = None,
allow_stdin: bool = False,
stop_on_error: bool = False,
cell_id: str | None = None,
received_time: float = 0,
tags: Iterable[str] = (),
**_ignored,
) -> Content
Execute code in the shell's user_ns and global_ns.
Source code in src/async_kernel/shell/ipshell.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
do_complete
async
¶
Source code in src/async_kernel/shell/ipshell.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | |
is_complete
async
¶
Source code in src/async_kernel/shell/ipshell.py
788 789 790 791 792 793 794 795 | |
do_inspect
async
¶
Source code in src/async_kernel/shell/ipshell.py
797 798 799 800 801 802 803 804 805 806 807 | |
do_history
async
¶
do_history(
*,
output: bool = False,
raw: bool = True,
hist_access_type: str,
session: int = 0,
start: int = 1,
stop: int | None = None,
n: int = 10,
pattern: str = "*",
unique: bool = False,
**_ignored,
) -> Content
Source code in src/async_kernel/shell/ipshell.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | |
init_magics
¶
init_magics() -> None
Initialize magics.
Source code in src/async_kernel/shell/ipshell.py
849 850 851 852 853 854 855 | |
enable_matplotlib
¶
Enable interactive matplotlib and inline figure support.
This takes the following steps:
- select the appropriate matplotlib backend
- set up matplotlib for interactive use with that backend
- configure formatters for inline figure display
Parameters:
-
(gui¶str | None, default:None) –If given, dictates the choice of matplotlib GUI backend to use (should be one of IPython's supported backends, 'qt', 'osx', 'tk', 'gtk', 'wx' or 'inline', 'ipympl'), otherwise we use the default chosen by matplotlib (as dictated by the matplotlib build-time options plus the user's matplotlibrc configuration file). Note that not all backends make sense in all contexts, for example a terminal ipython can't display figures inline.
Source code in src/async_kernel/shell/ipshell.py
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |