Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- lib/python3.12/site-packages/IPython/core/__pycache__/__init__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/alias.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/application.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/async_helpers.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/autocall.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/builtin_trap.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/compilerop.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/completerlib.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/crashhandler.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/debugger.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/debugger_backport.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/display.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/display_functions.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/display_trap.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/displayhook.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/displaypub.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/doctb.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/error.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/events.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/extensions.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/formatters.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/getipython.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/guarded_eval.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/history.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/historyapp.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/hooks.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/inputtransformer2.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/latex_symbols.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/logger.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/macro.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/magic.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/magic_arguments.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/oinspect.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/page.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/payload.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/payloadpage.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/prefilter.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/profileapp.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/profiledir.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/pylabtools.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/release.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/shellapp.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/splitinput.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/tbtools.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/tips.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/ultratb.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/__pycache__/usage.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/IPython/core/completerlib.py +382 -0
- lib/python3.12/site-packages/IPython/core/error.py +60 -0
- lib/python3.12/site-packages/IPython/core/extensions.py +135 -0
lib/python3.12/site-packages/IPython/core/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (191 Bytes). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/alias.cpython-312.pyc
ADDED
|
Binary file (10.5 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/application.cpython-312.pyc
ADDED
|
Binary file (22.9 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/async_helpers.cpython-312.pyc
ADDED
|
Binary file (6.08 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/autocall.cpython-312.pyc
ADDED
|
Binary file (2.36 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/builtin_trap.cpython-312.pyc
ADDED
|
Binary file (4.02 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/compilerop.cpython-312.pyc
ADDED
|
Binary file (6.15 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/completerlib.cpython-312.pyc
ADDED
|
Binary file (14.3 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/crashhandler.cpython-312.pyc
ADDED
|
Binary file (9.21 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/debugger.cpython-312.pyc
ADDED
|
Binary file (51.6 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/debugger_backport.cpython-312.pyc
ADDED
|
Binary file (9.05 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/display.cpython-312.pyc
ADDED
|
Binary file (48.9 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/display_functions.cpython-312.pyc
ADDED
|
Binary file (12.8 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/display_trap.cpython-312.pyc
ADDED
|
Binary file (2.54 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/displayhook.cpython-312.pyc
ADDED
|
Binary file (15.7 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/displaypub.cpython-312.pyc
ADDED
|
Binary file (8.34 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/doctb.cpython-312.pyc
ADDED
|
Binary file (16.3 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/error.cpython-312.pyc
ADDED
|
Binary file (1.81 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/events.cpython-312.pyc
ADDED
|
Binary file (6.91 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/extensions.cpython-312.pyc
ADDED
|
Binary file (6.3 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/formatters.cpython-312.pyc
ADDED
|
Binary file (40.8 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/getipython.cpython-312.pyc
ADDED
|
Binary file (690 Bytes). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/guarded_eval.cpython-312.pyc
ADDED
|
Binary file (65.9 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/history.cpython-312.pyc
ADDED
|
Binary file (50.2 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/historyapp.cpython-312.pyc
ADDED
|
Binary file (7.62 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/hooks.cpython-312.pyc
ADDED
|
Binary file (5.75 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/inputtransformer2.cpython-312.pyc
ADDED
|
Binary file (38 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/latex_symbols.cpython-312.pyc
ADDED
|
Binary file (54 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/logger.cpython-312.pyc
ADDED
|
Binary file (9.18 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/macro.cpython-312.pyc
ADDED
|
Binary file (2.48 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/magic.cpython-312.pyc
ADDED
|
Binary file (28.2 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/magic_arguments.cpython-312.pyc
ADDED
|
Binary file (11.9 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/oinspect.cpython-312.pyc
ADDED
|
Binary file (41.9 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/page.cpython-312.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/payload.cpython-312.pyc
ADDED
|
Binary file (1.83 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/payloadpage.cpython-312.pyc
ADDED
|
Binary file (1.23 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/prefilter.cpython-312.pyc
ADDED
|
Binary file (28.5 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/profileapp.cpython-312.pyc
ADDED
|
Binary file (13.2 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/profiledir.cpython-312.pyc
ADDED
|
Binary file (11.3 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/pylabtools.cpython-312.pyc
ADDED
|
Binary file (16.4 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/release.cpython-312.pyc
ADDED
|
Binary file (849 Bytes). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/shellapp.cpython-312.pyc
ADDED
|
Binary file (24.3 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/splitinput.cpython-312.pyc
ADDED
|
Binary file (5.54 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/tbtools.cpython-312.pyc
ADDED
|
Binary file (20.3 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/tips.cpython-312.pyc
ADDED
|
Binary file (4.42 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/ultratb.cpython-312.pyc
ADDED
|
Binary file (46.9 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/__pycache__/usage.cpython-312.pyc
ADDED
|
Binary file (13.5 kB). View file
|
|
|
lib/python3.12/site-packages/IPython/core/completerlib.py
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# encoding: utf-8
|
| 2 |
+
"""Implementations for various useful completers.
|
| 3 |
+
|
| 4 |
+
These are all loaded by default by IPython.
|
| 5 |
+
"""
|
| 6 |
+
#-----------------------------------------------------------------------------
|
| 7 |
+
# Copyright (C) 2010-2011 The IPython Development Team.
|
| 8 |
+
#
|
| 9 |
+
# Distributed under the terms of the BSD License.
|
| 10 |
+
#
|
| 11 |
+
# The full license is in the file COPYING.txt, distributed with this software.
|
| 12 |
+
#-----------------------------------------------------------------------------
|
| 13 |
+
|
| 14 |
+
#-----------------------------------------------------------------------------
|
| 15 |
+
# Imports
|
| 16 |
+
#-----------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
# Stdlib imports
|
| 19 |
+
import glob
|
| 20 |
+
import inspect
|
| 21 |
+
import os
|
| 22 |
+
import re
|
| 23 |
+
import sys
|
| 24 |
+
from importlib import import_module
|
| 25 |
+
from importlib.machinery import all_suffixes
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Third-party imports
|
| 29 |
+
from time import time
|
| 30 |
+
from zipimport import zipimporter
|
| 31 |
+
|
| 32 |
+
# Our own imports
|
| 33 |
+
from .completer import expand_user, compress_user
|
| 34 |
+
from .error import TryNext
|
| 35 |
+
from ..utils._process_common import arg_split
|
| 36 |
+
|
| 37 |
+
# FIXME: this should be pulled in with the right call via the component system
|
| 38 |
+
from IPython import get_ipython
|
| 39 |
+
|
| 40 |
+
from typing import List
|
| 41 |
+
|
| 42 |
+
#-----------------------------------------------------------------------------
|
| 43 |
+
# Globals and constants
|
| 44 |
+
#-----------------------------------------------------------------------------
|
| 45 |
+
_suffixes = all_suffixes()
|
| 46 |
+
|
| 47 |
+
# Time in seconds after which the rootmodules will be stored permanently in the
|
| 48 |
+
# ipython ip.db database (kept in the user's .ipython dir).
|
| 49 |
+
TIMEOUT_STORAGE = 2
|
| 50 |
+
|
| 51 |
+
# Time in seconds after which we give up
|
| 52 |
+
TIMEOUT_GIVEUP = 20
|
| 53 |
+
|
| 54 |
+
# Regular expression for the python import statement
|
| 55 |
+
import_re = re.compile(r'(?P<name>[^\W\d]\w*?)'
|
| 56 |
+
r'(?P<package>[/\\]__init__)?'
|
| 57 |
+
r'(?P<suffix>%s)$' %
|
| 58 |
+
r'|'.join(re.escape(s) for s in _suffixes))
|
| 59 |
+
|
| 60 |
+
# RE for the ipython %run command (python + ipython scripts)
|
| 61 |
+
magic_run_re = re.compile(r'.*(\.ipy|\.ipynb|\.py[w]?)$')
|
| 62 |
+
|
| 63 |
+
#-----------------------------------------------------------------------------
|
| 64 |
+
# Local utilities
|
| 65 |
+
#-----------------------------------------------------------------------------
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def module_list(path: str) -> List[str]:
|
| 69 |
+
"""
|
| 70 |
+
Return the list containing the names of the modules available in the given
|
| 71 |
+
folder.
|
| 72 |
+
"""
|
| 73 |
+
# sys.path has the cwd as an empty string, but isdir/listdir need it as '.'
|
| 74 |
+
if path == '':
|
| 75 |
+
path = '.'
|
| 76 |
+
|
| 77 |
+
# A few local constants to be used in loops below
|
| 78 |
+
pjoin = os.path.join
|
| 79 |
+
|
| 80 |
+
if os.path.isdir(path):
|
| 81 |
+
# Build a list of all files in the directory and all files
|
| 82 |
+
# in its subdirectories. For performance reasons, do not
|
| 83 |
+
# recurse more than one level into subdirectories.
|
| 84 |
+
files: List[str] = []
|
| 85 |
+
for root, dirs, nondirs in os.walk(path, followlinks=True):
|
| 86 |
+
subdir = root[len(path)+1:]
|
| 87 |
+
if subdir:
|
| 88 |
+
files.extend(pjoin(subdir, f) for f in nondirs)
|
| 89 |
+
dirs[:] = [] # Do not recurse into additional subdirectories.
|
| 90 |
+
else:
|
| 91 |
+
files.extend(nondirs)
|
| 92 |
+
|
| 93 |
+
else:
|
| 94 |
+
try:
|
| 95 |
+
files = list(zipimporter(path)._files.keys()) # type: ignore
|
| 96 |
+
except Exception:
|
| 97 |
+
files = []
|
| 98 |
+
|
| 99 |
+
# Build a list of modules which match the import_re regex.
|
| 100 |
+
modules = []
|
| 101 |
+
for f in files:
|
| 102 |
+
m = import_re.match(f)
|
| 103 |
+
if m:
|
| 104 |
+
modules.append(m.group('name'))
|
| 105 |
+
return list(set(modules))
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def get_root_modules():
|
| 109 |
+
"""
|
| 110 |
+
Returns a list containing the names of all the modules available in the
|
| 111 |
+
folders of the pythonpath.
|
| 112 |
+
|
| 113 |
+
ip.db['rootmodules_cache'] maps sys.path entries to list of modules.
|
| 114 |
+
"""
|
| 115 |
+
ip = get_ipython()
|
| 116 |
+
if ip is None:
|
| 117 |
+
# No global shell instance to store cached list of modules.
|
| 118 |
+
# Don't try to scan for modules every time.
|
| 119 |
+
return list(sys.builtin_module_names)
|
| 120 |
+
|
| 121 |
+
if getattr(ip.db, "_mock", False):
|
| 122 |
+
rootmodules_cache = {}
|
| 123 |
+
else:
|
| 124 |
+
rootmodules_cache = ip.db.get("rootmodules_cache", {})
|
| 125 |
+
rootmodules = list(sys.builtin_module_names)
|
| 126 |
+
start_time = time()
|
| 127 |
+
store = False
|
| 128 |
+
for path in sys.path:
|
| 129 |
+
try:
|
| 130 |
+
modules = rootmodules_cache[path]
|
| 131 |
+
except KeyError:
|
| 132 |
+
modules = module_list(path)
|
| 133 |
+
try:
|
| 134 |
+
modules.remove('__init__')
|
| 135 |
+
except ValueError:
|
| 136 |
+
pass
|
| 137 |
+
if path not in ('', '.'): # cwd modules should not be cached
|
| 138 |
+
rootmodules_cache[path] = modules
|
| 139 |
+
if time() - start_time > TIMEOUT_STORAGE and not store:
|
| 140 |
+
store = True
|
| 141 |
+
print("\nCaching the list of root modules, please wait!")
|
| 142 |
+
print("(This will only be done once - type '%rehashx' to "
|
| 143 |
+
"reset cache!)\n")
|
| 144 |
+
sys.stdout.flush()
|
| 145 |
+
if time() - start_time > TIMEOUT_GIVEUP:
|
| 146 |
+
print("This is taking too long, we give up.\n")
|
| 147 |
+
return []
|
| 148 |
+
rootmodules.extend(modules)
|
| 149 |
+
if store:
|
| 150 |
+
ip.db['rootmodules_cache'] = rootmodules_cache
|
| 151 |
+
rootmodules = list(set(rootmodules))
|
| 152 |
+
return rootmodules
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def is_importable(module, attr: str, only_modules) -> bool:
|
| 156 |
+
if only_modules:
|
| 157 |
+
try:
|
| 158 |
+
mod = getattr(module, attr)
|
| 159 |
+
except ModuleNotFoundError:
|
| 160 |
+
# See gh-14434
|
| 161 |
+
return False
|
| 162 |
+
return inspect.ismodule(mod)
|
| 163 |
+
else:
|
| 164 |
+
return not(attr[:2] == '__' and attr[-2:] == '__')
|
| 165 |
+
|
| 166 |
+
def is_possible_submodule(module, attr):
|
| 167 |
+
try:
|
| 168 |
+
obj = getattr(module, attr)
|
| 169 |
+
except AttributeError:
|
| 170 |
+
# Is possibly an unimported submodule
|
| 171 |
+
return True
|
| 172 |
+
except TypeError:
|
| 173 |
+
# https://github.com/ipython/ipython/issues/9678
|
| 174 |
+
return False
|
| 175 |
+
return inspect.ismodule(obj)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def try_import(mod: str, only_modules=False) -> List[str]:
|
| 179 |
+
"""
|
| 180 |
+
Try to import given module and return list of potential completions.
|
| 181 |
+
"""
|
| 182 |
+
mod = mod.rstrip('.')
|
| 183 |
+
try:
|
| 184 |
+
m = import_module(mod)
|
| 185 |
+
except:
|
| 186 |
+
return []
|
| 187 |
+
|
| 188 |
+
m_is_init = '__init__' in (getattr(m, '__file__', '') or '')
|
| 189 |
+
|
| 190 |
+
completions = []
|
| 191 |
+
if (not hasattr(m, '__file__')) or (not only_modules) or m_is_init:
|
| 192 |
+
completions.extend( [attr for attr in dir(m) if
|
| 193 |
+
is_importable(m, attr, only_modules)])
|
| 194 |
+
|
| 195 |
+
m_all = getattr(m, "__all__", [])
|
| 196 |
+
if only_modules:
|
| 197 |
+
completions.extend(attr for attr in m_all if is_possible_submodule(m, attr))
|
| 198 |
+
else:
|
| 199 |
+
completions.extend(m_all)
|
| 200 |
+
|
| 201 |
+
if m_is_init:
|
| 202 |
+
file_ = m.__file__
|
| 203 |
+
file_path = os.path.dirname(file_) # type: ignore
|
| 204 |
+
if file_path is not None:
|
| 205 |
+
completions.extend(module_list(file_path))
|
| 206 |
+
completions_set = {c for c in completions if isinstance(c, str)}
|
| 207 |
+
completions_set.discard('__init__')
|
| 208 |
+
return list(completions_set)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
#-----------------------------------------------------------------------------
|
| 212 |
+
# Completion-related functions.
|
| 213 |
+
#-----------------------------------------------------------------------------
|
| 214 |
+
|
| 215 |
+
def quick_completer(cmd, completions):
|
| 216 |
+
r""" Easily create a trivial completer for a command.
|
| 217 |
+
|
| 218 |
+
Takes either a list of completions, or all completions in string (that will
|
| 219 |
+
be split on whitespace).
|
| 220 |
+
|
| 221 |
+
Example::
|
| 222 |
+
|
| 223 |
+
[d:\ipython]|1> import ipy_completers
|
| 224 |
+
[d:\ipython]|2> ipy_completers.quick_completer('foo', ['bar','baz'])
|
| 225 |
+
[d:\ipython]|3> foo b<TAB>
|
| 226 |
+
bar baz
|
| 227 |
+
[d:\ipython]|3> foo ba
|
| 228 |
+
"""
|
| 229 |
+
|
| 230 |
+
if isinstance(completions, str):
|
| 231 |
+
completions = completions.split()
|
| 232 |
+
|
| 233 |
+
def do_complete(self, event):
|
| 234 |
+
return completions
|
| 235 |
+
|
| 236 |
+
get_ipython().set_hook('complete_command',do_complete, str_key = cmd)
|
| 237 |
+
|
| 238 |
+
def module_completion(line):
|
| 239 |
+
"""
|
| 240 |
+
Returns a list containing the completion possibilities for an import line.
|
| 241 |
+
|
| 242 |
+
The line looks like this :
|
| 243 |
+
'import xml.d'
|
| 244 |
+
'from xml.dom import'
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
words = line.split(' ')
|
| 248 |
+
nwords = len(words)
|
| 249 |
+
|
| 250 |
+
# from whatever <tab> -> 'import '
|
| 251 |
+
if nwords == 3 and words[0] == 'from':
|
| 252 |
+
return ['import ']
|
| 253 |
+
|
| 254 |
+
# 'from xy<tab>' or 'import xy<tab>'
|
| 255 |
+
if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) :
|
| 256 |
+
if nwords == 1:
|
| 257 |
+
return get_root_modules()
|
| 258 |
+
mod = words[1].split('.')
|
| 259 |
+
if len(mod) < 2:
|
| 260 |
+
return get_root_modules()
|
| 261 |
+
completion_list = try_import('.'.join(mod[:-1]), True)
|
| 262 |
+
return ['.'.join(mod[:-1] + [el]) for el in completion_list]
|
| 263 |
+
|
| 264 |
+
# 'from xyz import abc<tab>'
|
| 265 |
+
if nwords >= 3 and words[0] == 'from':
|
| 266 |
+
mod = words[1]
|
| 267 |
+
return try_import(mod)
|
| 268 |
+
|
| 269 |
+
#-----------------------------------------------------------------------------
|
| 270 |
+
# Completers
|
| 271 |
+
#-----------------------------------------------------------------------------
|
| 272 |
+
# These all have the func(self, event) signature to be used as custom
|
| 273 |
+
# completers
|
| 274 |
+
|
| 275 |
+
def module_completer(self,event):
|
| 276 |
+
"""Give completions after user has typed 'import ...' or 'from ...'"""
|
| 277 |
+
|
| 278 |
+
# This works in all versions of python. While 2.5 has
|
| 279 |
+
# pkgutil.walk_packages(), that particular routine is fairly dangerous,
|
| 280 |
+
# since it imports *EVERYTHING* on sys.path. That is: a) very slow b) full
|
| 281 |
+
# of possibly problematic side effects.
|
| 282 |
+
# This search the folders in the sys.path for available modules.
|
| 283 |
+
|
| 284 |
+
return module_completion(event.line)
|
| 285 |
+
|
| 286 |
+
# FIXME: there's a lot of logic common to the run, cd and builtin file
|
| 287 |
+
# completers, that is currently reimplemented in each.
|
| 288 |
+
|
| 289 |
+
def magic_run_completer(self, event):
|
| 290 |
+
"""Complete files that end in .py or .ipy or .ipynb for the %run command.
|
| 291 |
+
"""
|
| 292 |
+
comps = arg_split(event.line, strict=False)
|
| 293 |
+
# relpath should be the current token that we need to complete.
|
| 294 |
+
if (len(comps) > 1) and (not event.line.endswith(' ')):
|
| 295 |
+
relpath = comps[-1].strip("'\"")
|
| 296 |
+
else:
|
| 297 |
+
relpath = ''
|
| 298 |
+
|
| 299 |
+
#print("\nev=", event) # dbg
|
| 300 |
+
#print("rp=", relpath) # dbg
|
| 301 |
+
#print('comps=', comps) # dbg
|
| 302 |
+
|
| 303 |
+
lglob = glob.glob
|
| 304 |
+
isdir = os.path.isdir
|
| 305 |
+
relpath, tilde_expand, tilde_val = expand_user(relpath)
|
| 306 |
+
|
| 307 |
+
# Find if the user has already typed the first filename, after which we
|
| 308 |
+
# should complete on all files, since after the first one other files may
|
| 309 |
+
# be arguments to the input script.
|
| 310 |
+
|
| 311 |
+
if any(magic_run_re.match(c) for c in comps):
|
| 312 |
+
matches = [f.replace('\\','/') + ('/' if isdir(f) else '')
|
| 313 |
+
for f in lglob(relpath+'*')]
|
| 314 |
+
else:
|
| 315 |
+
dirs = [f.replace('\\','/') + "/" for f in lglob(relpath+'*') if isdir(f)]
|
| 316 |
+
pys = [f.replace('\\','/')
|
| 317 |
+
for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') +
|
| 318 |
+
lglob(relpath+'*.ipynb') + lglob(relpath + '*.pyw')]
|
| 319 |
+
|
| 320 |
+
matches = dirs + pys
|
| 321 |
+
|
| 322 |
+
#print('run comp:', dirs+pys) # dbg
|
| 323 |
+
return [compress_user(p, tilde_expand, tilde_val) for p in matches]
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def cd_completer(self, event):
|
| 327 |
+
"""Completer function for cd, which only returns directories."""
|
| 328 |
+
ip = get_ipython()
|
| 329 |
+
relpath = event.symbol
|
| 330 |
+
|
| 331 |
+
#print(event) # dbg
|
| 332 |
+
if event.line.endswith('-b') or ' -b ' in event.line:
|
| 333 |
+
# return only bookmark completions
|
| 334 |
+
bkms = self.db.get('bookmarks', None)
|
| 335 |
+
if bkms:
|
| 336 |
+
return bkms.keys()
|
| 337 |
+
else:
|
| 338 |
+
return []
|
| 339 |
+
|
| 340 |
+
if event.symbol == '-':
|
| 341 |
+
width_dh = str(len(str(len(ip.user_ns['_dh']) + 1)))
|
| 342 |
+
# jump in directory history by number
|
| 343 |
+
fmt = '-%0' + width_dh +'d [%s]'
|
| 344 |
+
ents = [ fmt % (i,s) for i,s in enumerate(ip.user_ns['_dh'])]
|
| 345 |
+
if len(ents) > 1:
|
| 346 |
+
return ents
|
| 347 |
+
return []
|
| 348 |
+
|
| 349 |
+
if event.symbol.startswith('--'):
|
| 350 |
+
return ["--" + os.path.basename(d) for d in ip.user_ns['_dh']]
|
| 351 |
+
|
| 352 |
+
# Expand ~ in path and normalize directory separators.
|
| 353 |
+
relpath, tilde_expand, tilde_val = expand_user(relpath)
|
| 354 |
+
relpath = relpath.replace('\\','/')
|
| 355 |
+
|
| 356 |
+
found = []
|
| 357 |
+
for d in [f.replace('\\','/') + '/' for f in glob.glob(relpath+'*')
|
| 358 |
+
if os.path.isdir(f)]:
|
| 359 |
+
if ' ' in d:
|
| 360 |
+
# we don't want to deal with any of that, complex code
|
| 361 |
+
# for this is elsewhere
|
| 362 |
+
raise TryNext
|
| 363 |
+
|
| 364 |
+
found.append(d)
|
| 365 |
+
|
| 366 |
+
if not found:
|
| 367 |
+
if os.path.isdir(relpath):
|
| 368 |
+
return [compress_user(relpath, tilde_expand, tilde_val)]
|
| 369 |
+
|
| 370 |
+
# if no completions so far, try bookmarks
|
| 371 |
+
bks = self.db.get('bookmarks',{})
|
| 372 |
+
bkmatches = [s for s in bks if s.startswith(event.symbol)]
|
| 373 |
+
if bkmatches:
|
| 374 |
+
return bkmatches
|
| 375 |
+
|
| 376 |
+
raise TryNext
|
| 377 |
+
|
| 378 |
+
return [compress_user(p, tilde_expand, tilde_val) for p in found]
|
| 379 |
+
|
| 380 |
+
def reset_completer(self, event):
|
| 381 |
+
"A completer for %reset magic"
|
| 382 |
+
return '-f -s in out array dhist'.split()
|
lib/python3.12/site-packages/IPython/core/error.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# encoding: utf-8
|
| 2 |
+
"""
|
| 3 |
+
Global exception classes for IPython.core.
|
| 4 |
+
|
| 5 |
+
Authors:
|
| 6 |
+
|
| 7 |
+
* Brian Granger
|
| 8 |
+
* Fernando Perez
|
| 9 |
+
* Min Ragan-Kelley
|
| 10 |
+
|
| 11 |
+
Notes
|
| 12 |
+
-----
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
#-----------------------------------------------------------------------------
|
| 16 |
+
# Copyright (C) 2008 The IPython Development Team
|
| 17 |
+
#
|
| 18 |
+
# Distributed under the terms of the BSD License. The full license is in
|
| 19 |
+
# the file COPYING, distributed as part of this software.
|
| 20 |
+
#-----------------------------------------------------------------------------
|
| 21 |
+
|
| 22 |
+
#-----------------------------------------------------------------------------
|
| 23 |
+
# Imports
|
| 24 |
+
#-----------------------------------------------------------------------------
|
| 25 |
+
|
| 26 |
+
#-----------------------------------------------------------------------------
|
| 27 |
+
# Exception classes
|
| 28 |
+
#-----------------------------------------------------------------------------
|
| 29 |
+
|
| 30 |
+
class IPythonCoreError(Exception):
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class TryNext(IPythonCoreError):
|
| 35 |
+
"""Try next hook exception.
|
| 36 |
+
|
| 37 |
+
Raise this in your hook function to indicate that the next hook handler
|
| 38 |
+
should be used to handle the operation.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
class UsageError(IPythonCoreError):
|
| 42 |
+
"""Error in magic function arguments, etc.
|
| 43 |
+
|
| 44 |
+
Something that probably won't warrant a full traceback, but should
|
| 45 |
+
nevertheless interrupt a macro / batch file.
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
class StdinNotImplementedError(IPythonCoreError, NotImplementedError):
|
| 49 |
+
"""raw_input was requested in a context where it is not supported
|
| 50 |
+
|
| 51 |
+
For use in IPython kernels, where only some frontends may support
|
| 52 |
+
stdin requests.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
class InputRejected(Exception):
|
| 56 |
+
"""Input rejected by ast transformer.
|
| 57 |
+
|
| 58 |
+
Raise this in your NodeTransformer to indicate that InteractiveShell should
|
| 59 |
+
not execute the supplied input.
|
| 60 |
+
"""
|
lib/python3.12/site-packages/IPython/core/extensions.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# encoding: utf-8
|
| 2 |
+
"""A class for managing IPython extensions."""
|
| 3 |
+
|
| 4 |
+
# Copyright (c) IPython Development Team.
|
| 5 |
+
# Distributed under the terms of the Modified BSD License.
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import os.path
|
| 9 |
+
import sys
|
| 10 |
+
from importlib import import_module, reload
|
| 11 |
+
|
| 12 |
+
from traitlets.config.configurable import Configurable
|
| 13 |
+
from IPython.utils.path import ensure_dir_exists
|
| 14 |
+
from traitlets import Instance
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
#-----------------------------------------------------------------------------
|
| 18 |
+
# Main class
|
| 19 |
+
#-----------------------------------------------------------------------------
|
| 20 |
+
|
| 21 |
+
BUILTINS_EXTS = {"storemagic": False, "autoreload": False}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class ExtensionManager(Configurable):
|
| 25 |
+
"""A class to manage IPython extensions.
|
| 26 |
+
|
| 27 |
+
An IPython extension is an importable Python module that has
|
| 28 |
+
a function with the signature::
|
| 29 |
+
|
| 30 |
+
def load_ipython_extension(ipython):
|
| 31 |
+
# Do things with ipython
|
| 32 |
+
|
| 33 |
+
This function is called after your extension is imported and the
|
| 34 |
+
currently active :class:`InteractiveShell` instance is passed as
|
| 35 |
+
the only argument. You can do anything you want with IPython at
|
| 36 |
+
that point, including defining new magic and aliases, adding new
|
| 37 |
+
components, etc.
|
| 38 |
+
|
| 39 |
+
You can also optionally define an :func:`unload_ipython_extension(ipython)`
|
| 40 |
+
function, which will be called if the user unloads or reloads the extension.
|
| 41 |
+
The extension manager will only call :func:`load_ipython_extension` again
|
| 42 |
+
if the extension is reloaded.
|
| 43 |
+
|
| 44 |
+
You can put your extension modules anywhere you want, as long as
|
| 45 |
+
they can be imported by Python's standard import mechanism.
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
|
| 49 |
+
|
| 50 |
+
def __init__(self, shell=None, **kwargs):
|
| 51 |
+
super(ExtensionManager, self).__init__(shell=shell, **kwargs)
|
| 52 |
+
self.loaded = set()
|
| 53 |
+
|
| 54 |
+
def load_extension(self, module_str: str):
|
| 55 |
+
"""Load an IPython extension by its module name.
|
| 56 |
+
|
| 57 |
+
Returns the string "already loaded" if the extension is already loaded,
|
| 58 |
+
"no load function" if the module doesn't have a load_ipython_extension
|
| 59 |
+
function, or None if it succeeded.
|
| 60 |
+
"""
|
| 61 |
+
try:
|
| 62 |
+
return self._load_extension(module_str)
|
| 63 |
+
except ModuleNotFoundError:
|
| 64 |
+
if module_str in BUILTINS_EXTS:
|
| 65 |
+
BUILTINS_EXTS[module_str] = True
|
| 66 |
+
return self._load_extension("IPython.extensions." + module_str)
|
| 67 |
+
raise
|
| 68 |
+
|
| 69 |
+
def _load_extension(self, module_str: str):
|
| 70 |
+
if module_str in self.loaded:
|
| 71 |
+
return "already loaded"
|
| 72 |
+
|
| 73 |
+
assert self.shell is not None
|
| 74 |
+
|
| 75 |
+
with self.shell.builtin_trap:
|
| 76 |
+
if module_str not in sys.modules:
|
| 77 |
+
mod = import_module(module_str)
|
| 78 |
+
mod = sys.modules[module_str]
|
| 79 |
+
if self._call_load_ipython_extension(mod):
|
| 80 |
+
self.loaded.add(module_str)
|
| 81 |
+
else:
|
| 82 |
+
return "no load function"
|
| 83 |
+
|
| 84 |
+
def unload_extension(self, module_str: str):
|
| 85 |
+
"""Unload an IPython extension by its module name.
|
| 86 |
+
|
| 87 |
+
This function looks up the extension's name in ``sys.modules`` and
|
| 88 |
+
simply calls ``mod.unload_ipython_extension(self)``.
|
| 89 |
+
|
| 90 |
+
Returns the string "no unload function" if the extension doesn't define
|
| 91 |
+
a function to unload itself, "not loaded" if the extension isn't loaded,
|
| 92 |
+
otherwise None.
|
| 93 |
+
"""
|
| 94 |
+
if BUILTINS_EXTS.get(module_str, False) is True:
|
| 95 |
+
module_str = "IPython.extensions." + module_str
|
| 96 |
+
if module_str not in self.loaded:
|
| 97 |
+
return "not loaded"
|
| 98 |
+
|
| 99 |
+
if module_str in sys.modules:
|
| 100 |
+
mod = sys.modules[module_str]
|
| 101 |
+
if self._call_unload_ipython_extension(mod):
|
| 102 |
+
self.loaded.discard(module_str)
|
| 103 |
+
else:
|
| 104 |
+
return "no unload function"
|
| 105 |
+
|
| 106 |
+
def reload_extension(self, module_str: str):
|
| 107 |
+
"""Reload an IPython extension by calling reload.
|
| 108 |
+
|
| 109 |
+
If the module has not been loaded before,
|
| 110 |
+
:meth:`InteractiveShell.load_extension` is called. Otherwise
|
| 111 |
+
:func:`reload` is called and then the :func:`load_ipython_extension`
|
| 112 |
+
function of the module, if it exists is called.
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
if BUILTINS_EXTS.get(module_str, False) is True:
|
| 116 |
+
module_str = "IPython.extensions." + module_str
|
| 117 |
+
|
| 118 |
+
if (module_str in self.loaded) and (module_str in sys.modules):
|
| 119 |
+
self.unload_extension(module_str)
|
| 120 |
+
mod = sys.modules[module_str]
|
| 121 |
+
reload(mod)
|
| 122 |
+
if self._call_load_ipython_extension(mod):
|
| 123 |
+
self.loaded.add(module_str)
|
| 124 |
+
else:
|
| 125 |
+
self.load_extension(module_str)
|
| 126 |
+
|
| 127 |
+
def _call_load_ipython_extension(self, mod):
|
| 128 |
+
if hasattr(mod, 'load_ipython_extension'):
|
| 129 |
+
mod.load_ipython_extension(self.shell)
|
| 130 |
+
return True
|
| 131 |
+
|
| 132 |
+
def _call_unload_ipython_extension(self, mod):
|
| 133 |
+
if hasattr(mod, 'unload_ipython_extension'):
|
| 134 |
+
mod.unload_ipython_extension(self.shell)
|
| 135 |
+
return True
|