A class to organize all history-related functionality in one place.
| 604 | |
| 605 | |
| 606 | class HistoryManager(HistoryAccessor): |
| 607 | """A class to organize all history-related functionality in one place.""" |
| 608 | |
| 609 | # Public interface |
| 610 | |
| 611 | # An instance of the IPython shell we are attached to |
| 612 | shell = Instance( |
| 613 | "IPython.core.interactiveshell.InteractiveShellABC", allow_none=False |
| 614 | ) |
| 615 | # Lists to hold processed and raw history. These start with a blank entry |
| 616 | # so that we can index them starting from 1 |
| 617 | input_hist_parsed = List([""]) |
| 618 | input_hist_raw = List([""]) |
| 619 | # A list of directories visited during session |
| 620 | dir_hist: List = List() |
| 621 | |
| 622 | @default("dir_hist") |
| 623 | def _dir_hist_default(self) -> list[Path]: |
| 624 | try: |
| 625 | return [Path.cwd()] |
| 626 | except OSError: |
| 627 | return [] |
| 628 | |
| 629 | # A dict of output history, keyed with ints from the shell's |
| 630 | # execution count. |
| 631 | output_hist = Dict() |
| 632 | # The text/plain repr of outputs. |
| 633 | output_hist_reprs: typing.Dict[int, str] = Dict() # type: ignore [assignment] |
| 634 | # Maps execution_count to MIME bundles |
| 635 | outputs: typing.Dict[int, typing.List[HistoryOutput]] = defaultdict(list) |
| 636 | # Maps execution_count to exception tracebacks |
| 637 | exceptions: typing.Dict[int, typing.Dict[str, Any]] = Dict() # type: ignore [assignment] |
| 638 | |
| 639 | # The number of the current session in the history database |
| 640 | session_number: int = Integer() # type: ignore [assignment] |
| 641 | |
| 642 | db_log_output = Bool( |
| 643 | False, help="Should the history database include output? (default: no)" |
| 644 | ).tag(config=True) |
| 645 | db_cache_size = Integer( |
| 646 | 0, |
| 647 | help="Write to database every x commands (higher values save disk access & power).\n" |
| 648 | "Values of 1 or less effectively disable caching.", |
| 649 | ).tag(config=True) |
| 650 | # The input and output caches |
| 651 | db_input_cache: List[tuple[int, str, str]] = List() |
| 652 | db_output_cache: List[tuple[int, str]] = List() |
| 653 | |
| 654 | # History saving in separate thread |
| 655 | save_thread = Instance("IPython.core.history.HistorySavingThread", allow_none=True) |
| 656 | |
| 657 | @property |
| 658 | def save_flag(self) -> threading.Event | None: |
| 659 | if self.save_thread is not None: |
| 660 | return self.save_thread.save_flag |
| 661 | return None |
| 662 | |
| 663 | # Private interface |
no outgoing calls
searching dependent graphs…