Browse Source

Intermediate changes

robot-piglet 1 year ago
parent
commit
7b5df0095a

+ 5 - 5
contrib/python/ipython/py3/.dist-info/METADATA

@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: ipython
-Version: 8.20.0
+Version: 8.21.0
 Summary: IPython: Productive Interactive Computing
 Home-page: https://ipython.org
 Author: The IPython Development Team
@@ -46,9 +46,9 @@ Requires-Dist: sphinx-rtd-theme ; extra == 'all'
 Requires-Dist: docrepr ; extra == 'all'
 Requires-Dist: matplotlib ; extra == 'all'
 Requires-Dist: stack-data ; extra == 'all'
-Requires-Dist: pytest ; extra == 'all'
 Requires-Dist: typing-extensions ; extra == 'all'
 Requires-Dist: exceptiongroup ; extra == 'all'
+Requires-Dist: pytest <8 ; extra == 'all'
 Requires-Dist: pytest-asyncio <0.22 ; extra == 'all'
 Requires-Dist: testpath ; extra == 'all'
 Requires-Dist: pickleshare ; extra == 'all'
@@ -73,9 +73,9 @@ Requires-Dist: sphinx-rtd-theme ; extra == 'doc'
 Requires-Dist: docrepr ; extra == 'doc'
 Requires-Dist: matplotlib ; extra == 'doc'
 Requires-Dist: stack-data ; extra == 'doc'
-Requires-Dist: pytest ; extra == 'doc'
 Requires-Dist: typing-extensions ; extra == 'doc'
 Requires-Dist: exceptiongroup ; extra == 'doc'
+Requires-Dist: pytest <8 ; extra == 'doc'
 Requires-Dist: pytest-asyncio <0.22 ; extra == 'doc'
 Requires-Dist: testpath ; extra == 'doc'
 Requires-Dist: pickleshare ; extra == 'doc'
@@ -94,12 +94,12 @@ Provides-Extra: qtconsole
 Requires-Dist: qtconsole ; extra == 'qtconsole'
 Provides-Extra: terminal
 Provides-Extra: test
-Requires-Dist: pytest ; extra == 'test'
+Requires-Dist: pytest <8 ; extra == 'test'
 Requires-Dist: pytest-asyncio <0.22 ; extra == 'test'
 Requires-Dist: testpath ; extra == 'test'
 Requires-Dist: pickleshare ; extra == 'test'
 Provides-Extra: test_extra
-Requires-Dist: pytest ; extra == 'test_extra'
+Requires-Dist: pytest <8 ; extra == 'test_extra'
 Requires-Dist: pytest-asyncio <0.22 ; extra == 'test_extra'
 Requires-Dist: testpath ; extra == 'test_extra'
 Requires-Dist: pickleshare ; extra == 'test_extra'

+ 15 - 9
contrib/python/ipython/py3/IPython/core/alias.py

@@ -190,22 +190,28 @@ class Alias(object):
 #-----------------------------------------------------------------------------
 
 class AliasManager(Configurable):
-
-    default_aliases = List(default_aliases()).tag(config=True)
-    user_aliases = List(default_value=[]).tag(config=True)
-    shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
+    default_aliases: List = List(default_aliases()).tag(config=True)
+    user_aliases: List = List(default_value=[]).tag(config=True)
+    shell = Instance(
+        "IPython.core.interactiveshell.InteractiveShellABC", allow_none=True
+    )
 
     def __init__(self, shell=None, **kwargs):
         super(AliasManager, self).__init__(shell=shell, **kwargs)
         # For convenient access
-        self.linemagics = self.shell.magics_manager.magics['line']
-        self.init_aliases()
+        if self.shell is not None:
+            self.linemagics = self.shell.magics_manager.magics["line"]
+            self.init_aliases()
 
     def init_aliases(self):
         # Load default & user aliases
         for name, cmd in self.default_aliases + self.user_aliases:
-            if cmd.startswith('ls ') and self.shell.colors == 'NoColor':
-                cmd = cmd.replace(' --color', '')
+            if (
+                cmd.startswith("ls ")
+                and self.shell is not None
+                and self.shell.colors == "NoColor"
+            ):
+                cmd = cmd.replace(" --color", "")
             self.soft_define_alias(name, cmd)
 
     @property
@@ -246,7 +252,7 @@ class AliasManager(Configurable):
             raise ValueError('%s is not an alias' % name)
 
     def clear_aliases(self):
-        for name, cmd in self.aliases:
+        for name, _ in self.aliases:
             self.undefine_alias(name)
 
     def retrieve_alias(self, name):

+ 4 - 0
contrib/python/ipython/py3/IPython/core/application.py

@@ -213,7 +213,9 @@ class BaseIPythonApplication(Application):
         return d
     
     _in_init_profile_dir = False
+
     profile_dir = Instance(ProfileDir, allow_none=True)
+
     @default('profile_dir')
     def _profile_dir_default(self):
         # avoid recursion
@@ -226,11 +228,13 @@ class BaseIPythonApplication(Application):
     overwrite = Bool(False,
         help="""Whether to overwrite existing config files when copying"""
     ).tag(config=True)
+
     auto_create = Bool(False,
         help="""Whether to create profile dir if it doesn't exist"""
     ).tag(config=True)
 
     config_files = List(Unicode())
+
     @default('config_files')
     def _config_files_default(self):
         return [self.config_file_name]

+ 5 - 2
contrib/python/ipython/py3/IPython/core/debugger.py

@@ -1111,10 +1111,13 @@ class InterruptiblePdb(Pdb):
                 raise
 
 
-def set_trace(frame=None):
+def set_trace(frame=None, header=None):
     """
     Start debugging from `frame`.
 
     If frame is not specified, debugging starts from caller's frame.
     """
-    Pdb().set_trace(frame or sys._getframe().f_back)
+    pdb = Pdb()
+    if header is not None:
+        pdb.message(header)
+    pdb.set_trace(frame or sys._getframe().f_back)

+ 118 - 108
contrib/python/ipython/py3/IPython/core/excolors.py

@@ -42,118 +42,128 @@ def exception_colors():
     ex_colors = ColorSchemeTable()
 
     # Populate it with color schemes
-    C = TermColors # shorthand and local lookup
-    ex_colors.add_scheme(ColorScheme(
-        'NoColor',
-        # The color to be used for the top line
-        topline = C.NoColor,
-
-        # The colors to be used in the traceback
-        filename = C.NoColor,
-        lineno = C.NoColor,
-        name = C.NoColor,
-        vName = C.NoColor,
-        val = C.NoColor,
-        em = C.NoColor,
-
-        # Emphasized colors for the last frame of the traceback
-        normalEm = C.NoColor,
-        filenameEm = C.NoColor,
-        linenoEm = C.NoColor,
-        nameEm = C.NoColor,
-        valEm = C.NoColor,
-
-        # Colors for printing the exception
-        excName = C.NoColor,
-        line = C.NoColor,
-        caret = C.NoColor,
-        Normal = C.NoColor
-        ))
+    C = TermColors  # shorthand and local lookup
+    ex_colors.add_scheme(
+        ColorScheme(
+            "NoColor",
+            {
+                # The color to be used for the top line
+                "topline": C.NoColor,
+
+                # The colors to be used in the traceback
+                "filename": C.NoColor,
+                "lineno": C.NoColor,
+                "name": C.NoColor,
+                "vName": C.NoColor,
+                "val": C.NoColor,
+                "em": C.NoColor,
+
+                # Emphasized colors for the last frame of the traceback
+                "normalEm": C.NoColor,
+                "filenameEm": C.NoColor,
+                "linenoEm": C.NoColor,
+                "nameEm": C.NoColor,
+                "valEm": C.NoColor,
+
+                # Colors for printing the exception
+                "excName": C.NoColor,
+                "line": C.NoColor,
+                "caret": C.NoColor,
+                "Normal": C.NoColor,
+            },
+        )
+    )
 
     # make some schemes as instances so we can copy them for modification easily
-    ex_colors.add_scheme(ColorScheme(
-        'Linux',
-        # The color to be used for the top line
-        topline = C.LightRed,
-
-        # The colors to be used in the traceback
-        filename = C.Green,
-        lineno = C.Green,
-        name = C.Purple,
-        vName = C.Cyan,
-        val = C.Green,
-        em = C.LightCyan,
-
-        # Emphasized colors for the last frame of the traceback
-        normalEm = C.LightCyan,
-        filenameEm = C.LightGreen,
-        linenoEm = C.LightGreen,
-        nameEm = C.LightPurple,
-        valEm = C.LightBlue,
-
-        # Colors for printing the exception
-        excName = C.LightRed,
-        line = C.Yellow,
-        caret = C.White,
-        Normal = C.Normal
-        ))
+    ex_colors.add_scheme(
+        ColorScheme(
+            "Linux",
+            {
+                # The color to be used for the top line
+                "topline": C.LightRed,
+                # The colors to be used in the traceback
+                "filename": C.Green,
+                "lineno": C.Green,
+                "name": C.Purple,
+                "vName": C.Cyan,
+                "val": C.Green,
+                "em": C.LightCyan,
+                # Emphasized colors for the last frame of the traceback
+                "normalEm": C.LightCyan,
+                "filenameEm": C.LightGreen,
+                "linenoEm": C.LightGreen,
+                "nameEm": C.LightPurple,
+                "valEm": C.LightBlue,
+                # Colors for printing the exception
+                "excName": C.LightRed,
+                "line": C.Yellow,
+                "caret": C.White,
+                "Normal": C.Normal,
+            },
+        )
+    )
 
     # For light backgrounds, swap dark/light colors
-    ex_colors.add_scheme(ColorScheme(
-        'LightBG',
-        # The color to be used for the top line
-        topline = C.Red,
-
-        # The colors to be used in the traceback
-        filename = C.LightGreen,
-        lineno = C.LightGreen,
-        name = C.LightPurple,
-        vName = C.Cyan,
-        val = C.LightGreen,
-        em = C.Cyan,
-
-        # Emphasized colors for the last frame of the traceback
-        normalEm = C.Cyan,
-        filenameEm = C.Green,
-        linenoEm = C.Green,
-        nameEm = C.Purple,
-        valEm = C.Blue,
-
-        # Colors for printing the exception
-        excName = C.Red,
-        #line = C.Brown,  # brown often is displayed as yellow
-        line = C.Red,
-        caret = C.Normal,
-        Normal = C.Normal,
-        ))
-
-    ex_colors.add_scheme(ColorScheme(
-        'Neutral',
-        # The color to be used for the top line
-        topline = C.Red,
-
-        # The colors to be used in the traceback
-        filename = C.LightGreen,
-        lineno = C.LightGreen,
-        name = C.LightPurple,
-        vName = C.Cyan,
-        val = C.LightGreen,
-        em = C.Cyan,
-
-        # Emphasized colors for the last frame of the traceback
-        normalEm = C.Cyan,
-        filenameEm = C.Green,
-        linenoEm = C.Green,
-        nameEm = C.Purple,
-        valEm = C.Blue,
-
-        # Colors for printing the exception
-        excName = C.Red,
-        #line = C.Brown,  # brown often is displayed as yellow
-        line = C.Red,
-        caret = C.Normal,
-        Normal = C.Normal,
-        ))
+    ex_colors.add_scheme(
+        ColorScheme(
+            "LightBG",
+            {
+                # The color to be used for the top line
+                "topline": C.Red,
+
+                # The colors to be used in the traceback
+                "filename": C.LightGreen,
+                "lineno": C.LightGreen,
+                "name": C.LightPurple,
+                "vName": C.Cyan,
+                "val": C.LightGreen,
+                "em": C.Cyan,
+
+                # Emphasized colors for the last frame of the traceback
+                "normalEm": C.Cyan,
+                "filenameEm": C.Green,
+                "linenoEm": C.Green,
+                "nameEm": C.Purple,
+                "valEm": C.Blue,
+
+                # Colors for printing the exception
+                "excName": C.Red,
+                # "line": C.Brown,  # brown often is displayed as yellow
+                "line": C.Red,
+                "caret": C.Normal,
+                "Normal": C.Normal,
+            },
+        )
+    )
+
+    ex_colors.add_scheme(
+        ColorScheme(
+            "Neutral",
+            {
+                # The color to be used for the top line
+                "topline": C.Red,
+                # The colors to be used in the traceback
+                "filename": C.LightGreen,
+                "lineno": C.LightGreen,
+                "name": C.LightPurple,
+                "vName": C.Cyan,
+                "val": C.LightGreen,
+                "em": C.Cyan,
+                # Emphasized colors for the last frame of the traceback
+                "normalEm": C.Cyan,
+                "filenameEm": C.Green,
+                "linenoEm": C.Green,
+                "nameEm": C.Purple,
+                "valEm": C.Blue,
+                # Colors for printing the exception
+                "excName": C.Red,
+                # line = C.Brown,  # brown often is displayed as yellow
+                "line": C.Red,
+                "caret": C.Normal,
+                "Normal": C.Normal,
+            },
+        )
+    )
 
     # Hack: the 'neutral' colours are not very visible on a dark background on
     # Windows. Since Windows command prompts have a dark background by default, and

+ 5 - 21
contrib/python/ipython/py3/IPython/core/extensions.py

@@ -10,8 +10,7 @@ import sys
 from importlib import import_module, reload
 
 from traitlets.config.configurable import Configurable
-from IPython.utils.path import ensure_dir_exists, compress_user
-from IPython.utils.decorators import undoc
+from IPython.utils.path import ensure_dir_exists
 from traitlets import Instance
 
 
@@ -36,35 +35,22 @@ class ExtensionManager(Configurable):
     the only argument.  You can do anything you want with IPython at
     that point, including defining new magic and aliases, adding new
     components, etc.
-    
+
     You can also optionally define an :func:`unload_ipython_extension(ipython)`
     function, which will be called if the user unloads or reloads the extension.
     The extension manager will only call :func:`load_ipython_extension` again
     if the extension is reloaded.
 
     You can put your extension modules anywhere you want, as long as
-    they can be imported by Python's standard import mechanism.  However,
-    to make it easy to write extensions, you can also put your extensions
-    in ``os.path.join(self.ipython_dir, 'extensions')``.  This directory
-    is added to ``sys.path`` automatically.
+    they can be imported by Python's standard import mechanism.
     """
 
     shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
 
     def __init__(self, shell=None, **kwargs):
         super(ExtensionManager, self).__init__(shell=shell, **kwargs)
-        self.shell.observe(
-            self._on_ipython_dir_changed, names=('ipython_dir',)
-        )
         self.loaded = set()
 
-    @property
-    def ipython_extension_dir(self):
-        return os.path.join(self.shell.ipython_dir, u'extensions')
-
-    def _on_ipython_dir_changed(self, change):
-        ensure_dir_exists(self.ipython_extension_dir)
-
     def load_extension(self, module_str: str):
         """Load an IPython extension by its module name.
 
@@ -84,7 +70,7 @@ class ExtensionManager(Configurable):
         if module_str in self.loaded:
             return "already loaded"
 
-        from IPython.utils.syspathcontext import prepended_to_syspath
+        assert self.shell is not None
 
         with self.shell.builtin_trap:
             if module_str not in sys.modules:
@@ -125,7 +111,6 @@ class ExtensionManager(Configurable):
         :func:`reload` is called and then the :func:`load_ipython_extension`
         function of the module, if it exists is called.
         """
-        from IPython.utils.syspathcontext import prepended_to_syspath
 
         if BUILTINS_EXTS.get(module_str, False) is True:
             module_str = "IPython.extensions." + module_str
@@ -133,8 +118,7 @@ class ExtensionManager(Configurable):
         if (module_str in self.loaded) and (module_str in sys.modules):
             self.unload_extension(module_str)
             mod = sys.modules[module_str]
-            with prepended_to_syspath(self.ipython_extension_dir):
-                reload(mod)
+            reload(mod)
             if self._call_load_ipython_extension(mod):
                 self.loaded.add(module_str)
         else:

+ 26 - 13
contrib/python/ipython/py3/IPython/core/oinspect.py

@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 """Tools for inspecting Python objects.
 
 Uses syntax highlighting for presenting the various information elements.
@@ -22,7 +21,6 @@ import inspect
 import io as stdlib_io
 import linecache
 import os
-import sys
 import types
 import warnings
 
@@ -30,6 +28,8 @@ from typing import Any, Optional, Dict, Union, List, Tuple
 
 from typing import TypeAlias
 
+import traitlets
+
 # IPython's own
 from IPython.core import page
 from IPython.lib.pretty import pretty
@@ -41,7 +41,7 @@ from IPython.utils.path import compress_user
 from IPython.utils.text import indent
 from IPython.utils.wildcard import list_namespace
 from IPython.utils.wildcard import typestr2type
-from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable
+from IPython.utils.coloransi import TermColors
 from IPython.utils.py3compat import cast_unicode
 from IPython.utils.colorable import Colorable
 from IPython.utils.decorators import undoc
@@ -145,7 +145,7 @@ def get_encoding(obj):
         # getsourcelines returns lineno with 1-offset and page() uses
         # 0-offset, so we must adjust.
         with stdlib_io.open(ofile, 'rb') as buffer:   # Tweaked to use io.open for Python 2
-            encoding, lines = openpy.detect_encoding(buffer.readline)
+            encoding, _lines = openpy.detect_encoding(buffer.readline)
         return encoding
 
 def getdoc(obj) -> Union[str,None]:
@@ -328,7 +328,7 @@ def _get_wrapped(obj):
             return orig_obj
     return obj
 
-def find_file(obj) -> str:
+def find_file(obj) -> Optional[str]:
     """Find the absolute path to the file where an object was defined.
 
     This is essentially a robust wrapper around `inspect.getabsfile`.
@@ -346,7 +346,7 @@ def find_file(obj) -> str:
     """
     obj = _get_wrapped(obj)
 
-    fname = None
+    fname: Optional[str] = None
     try:
         fname = inspect.getabsfile(obj)
     except TypeError:
@@ -360,7 +360,7 @@ def find_file(obj) -> str:
     except OSError:
         pass
 
-    return cast_unicode(fname)
+    return fname
 
 
 def find_source_lines(obj):
@@ -396,11 +396,20 @@ def find_source_lines(obj):
 
 class Inspector(Colorable):
 
-    def __init__(self, color_table=InspectColors,
-                 code_color_table=PyColorize.ANSICodeColors,
-                 scheme=None,
-                 str_detail_level=0,
-                 parent=None, config=None):
+    mime_hooks = traitlets.Dict(
+        config=True,
+        help="dictionary of mime to callable to add informations into help mimebundle dict",
+    ).tag(config=True)
+
+    def __init__(
+        self,
+        color_table=InspectColors,
+        code_color_table=PyColorize.ANSICodeColors,
+        scheme=None,
+        str_detail_level=0,
+        parent=None,
+        config=None,
+    ):
         super(Inspector, self).__init__(parent=parent, config=config)
         self.color_table = color_table
         self.parser = PyColorize.Parser(out='str', parent=self, style=scheme)
@@ -625,7 +634,7 @@ class Inspector(Colorable):
             if k in ("text/html", "text/plain"):
                 continue
             else:
-                new_b = bundle[k]  # type:ignore
+                new_b[k] = bundle[k]  # type:ignore
         return new_b
 
     def _append_info_field(
@@ -759,6 +768,10 @@ class Inspector(Colorable):
             detail_level=detail_level,
             omit_sections=omit_sections,
         )
+        for key, hook in self.mime_hooks.items():
+            res = hook(obj, info)
+            if res is not None:
+                bundle[key] = res
         return self.format_mime(bundle)
 
     def pinfo(

+ 1 - 2
contrib/python/ipython/py3/IPython/core/payload.py

@@ -26,8 +26,7 @@ from traitlets import List
 #-----------------------------------------------------------------------------
 
 class PayloadManager(Configurable):
-
-    _payload = List([])
+    _payload: List = List([])
 
     def write_payload(self, data, single=True):
         """Include or update the specified `data` payload in the PayloadManager.

+ 1 - 1
contrib/python/ipython/py3/IPython/core/profileapp.py

@@ -209,7 +209,7 @@ class ProfileCreate(BaseIPythonApplication):
     name = u'ipython-profile'
     description = create_help
     examples = _create_examples
-    auto_create = Bool(True)
+    auto_create = Bool(True).tag(config=True)
     def _log_format_default(self):
         return "[%(name)s] %(message)s"
 

+ 1 - 1
contrib/python/ipython/py3/IPython/core/release.py

@@ -16,7 +16,7 @@
 # release.  'dev' as a _version_extra string means this is a development
 # version
 _version_major = 8
-_version_minor = 20
+_version_minor = 21
 _version_patch = 0
 _version_extra = ".dev"
 # _version_extra = "rc1"

Some files were not shown because too many files changed in this diff