diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-03 17:14:48 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-03 17:14:48 +0300 |
commit | 96015f265031dff57a3a8b3a70b5c097deff41bb (patch) | |
tree | eceeea82f7b8926e66613a9e27916bfd9f9c0452 /contrib/python/ipython | |
parent | 809c8cd1eb0536e15a8b84feb92c8b87042cb81a (diff) | |
download | ydb-96015f265031dff57a3a8b3a70b5c097deff41bb.tar.gz |
intermediate changes
ref:ac22a335bf0b52ff7f18a64a33cc4300ee0659de
Diffstat (limited to 'contrib/python/ipython')
7 files changed, 134 insertions, 19 deletions
diff --git a/contrib/python/ipython/py3/.dist-info/METADATA b/contrib/python/ipython/py3/.dist-info/METADATA index 7073677dca..a3bc994a4e 100644 --- a/contrib/python/ipython/py3/.dist-info/METADATA +++ b/contrib/python/ipython/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: ipython -Version: 7.31.1 +Version: 7.32.0 Summary: IPython: Productive Interactive Computing Home-page: https://ipython.org Author: The IPython Development Team diff --git a/contrib/python/ipython/py3/IPython/core/interactiveshell.py b/contrib/python/ipython/py3/IPython/core/interactiveshell.py index 835dc8d0a8..e222e991c0 100644 --- a/contrib/python/ipython/py3/IPython/core/interactiveshell.py +++ b/contrib/python/ipython/py3/IPython/core/interactiveshell.py @@ -15,6 +15,7 @@ import abc import ast import atexit import builtins as builtin_mod +import dis import functools import inspect import os @@ -93,12 +94,17 @@ from IPython.utils.contexts import NoOpContext try: import docrepr.sphinxify as sphx - def sphinxify(doc): - with TemporaryDirectory() as dirname: - return { - 'text/html': sphx.sphinxify(doc, dirname), - 'text/plain': doc - } + def sphinxify(oinfo): + wrapped_docstring = sphx.wrap_main_docstring(oinfo) + + def sphinxify_docstring(docstring): + with TemporaryDirectory() as dirname: + return { + "text/html": sphx.sphinxify(wrapped_docstring, dirname), + "text/plain": docstring, + } + + return sphinxify_docstring except ImportError: sphinxify = None @@ -626,7 +632,6 @@ class InteractiveShell(SingletonConfigurable): def __init__(self, ipython_dir=None, profile_dir=None, user_module=None, user_ns=None, custom_exceptions=((), None), **kwargs): - # This is where traits with a config_key argument are updated # from the values on config. super(InteractiveShell, self).__init__(**kwargs) @@ -919,7 +924,7 @@ class InteractiveShell(SingletonConfigurable): while p.is_symlink(): p = Path(os.readlink(p)) paths.append(p.resolve()) - + # In Cygwin paths like "c:\..." and '\cygdrive\c\...' are possible if p_venv.parts[1] == "cygdrive": drive_name = p_venv.parts[2] @@ -1765,7 +1770,9 @@ class InteractiveShell(SingletonConfigurable): This function is meant to be called by pdef, pdoc & friends. """ info = self._object_find(oname, namespaces) - docformat = sphinxify if self.sphinxify_docstring else None + docformat = ( + sphinxify(self.object_inspect(oname)) if self.sphinxify_docstring else None + ) if info.found: pmethod = getattr(self.inspector, meth) # TODO: only apply format_screen to the plain/text repr of the mime @@ -1780,7 +1787,7 @@ class InteractiveShell(SingletonConfigurable): formatter, info, enable_html_pager=self.enable_html_pager, - **kw + **kw, ) else: pmethod(info.obj, oname) @@ -1812,7 +1819,11 @@ class InteractiveShell(SingletonConfigurable): with self.builtin_trap: info = self._object_find(oname) if info.found: - docformat = sphinxify if self.sphinxify_docstring else None + docformat = ( + sphinxify(self.object_inspect(oname)) + if self.sphinxify_docstring + else None + ) return self.inspector._get_info( info.obj, oname, @@ -2320,7 +2331,34 @@ class InteractiveShell(SingletonConfigurable): func, magic_kind=magic_kind, magic_name=magic_name ) - def run_line_magic(self, magic_name, line, _stack_depth=1): + def _find_with_lazy_load(self, type_, magic_name: str): + """ + Try to find a magic potentially lazy-loading it. + + Parameters + ---------- + + type_: "line"|"cell" + the type of magics we are trying to find/lazy load. + magic_name: str + The name of the magic we are trying to find/lazy load + + + Note that this may have any side effects + """ + finder = {"line": self.find_line_magic, "cell": self.find_cell_magic}[type_] + fn = finder(magic_name) + if fn is not None: + return fn + lazy = self.magics_manager.lazy_magics.get(magic_name) + if lazy is None: + return None + + self.run_line_magic("load_ext", lazy) + res = finder(magic_name) + return res + + def run_line_magic(self, magic_name: str, line, _stack_depth=1): """Execute the given line magic. Parameters @@ -2335,7 +2373,12 @@ class InteractiveShell(SingletonConfigurable): If run_line_magic() is called from magic() then _stack_depth=2. This is added to ensure backward compatibility for use of 'get_ipython().magic()' """ - fn = self.find_line_magic(magic_name) + fn = self._find_with_lazy_load("line", magic_name) + if fn is None: + lazy = self.magics_manager.lazy_magics.get(magic_name) + if lazy: + self.run_line_magic("load_ext", lazy) + fn = self.find_line_magic(magic_name) if fn is None: cm = self.find_cell_magic(magic_name) etpl = "Line magic function `%%%s` not found%s." @@ -2388,7 +2431,7 @@ class InteractiveShell(SingletonConfigurable): cell : str The body of the cell as a (possibly multiline) string. """ - fn = self.find_cell_magic(magic_name) + fn = self._find_with_lazy_load("cell", magic_name) if fn is None: lm = self.find_line_magic(magic_name) etpl = "Cell magic `%%{0}` not found{1}." @@ -3262,6 +3305,29 @@ class InteractiveShell(SingletonConfigurable): ast.fix_missing_locations(node) return node + def _update_code_co_name(self, code): + """Python 3.10 changed the behaviour so that whenever a code object + is assembled in the compile(ast) the co_firstlineno would be == 1. + + This makes pydevd/debugpy think that all cells invoked are the same + since it caches information based on (co_firstlineno, co_name, co_filename). + + Given that, this function changes the code 'co_name' to be unique + based on the first real lineno of the code (which also has a nice + side effect of customizing the name so that it's not always <module>). + + See: https://github.com/ipython/ipykernel/issues/841 + """ + if not hasattr(code, "replace"): + # It may not be available on older versions of Python (only + # available for 3.8 onwards). + return code + try: + first_real_line = next(dis.findlinestarts(code))[1] + except StopIteration: + return code + return code.replace(co_name="<cell line: %s>" % (first_real_line,)) + async def run_ast_nodes(self, nodelist:ListType[AST], cell_name:str, interactivity='last_expr', compiler=compile, result=None): """Run a sequence of AST nodes. The execution mode depends on the @@ -3373,6 +3439,7 @@ class InteractiveShell(SingletonConfigurable): mod = ast.Interactive([node]) with compiler.extra_flags(getattr(ast, 'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0) if self.autoawait else 0x0): code = compiler(mod, cell_name, mode) + code = self._update_code_co_name(code) asy = compare(code) if (await self.run_code(code, result, async_=asy)): return True diff --git a/contrib/python/ipython/py3/IPython/core/magic.py b/contrib/python/ipython/py3/IPython/core/magic.py index bc51677f08..63b6bec685 100644 --- a/contrib/python/ipython/py3/IPython/core/magic.py +++ b/contrib/python/ipython/py3/IPython/core/magic.py @@ -310,6 +310,34 @@ class MagicsManager(Configurable): # holding the actual callable object as value. This is the dict used for # magic function dispatch magics = Dict() + lazy_magics = Dict( + help=""" + Mapping from magic names to modules to load. + + This can be used in IPython/IPykernel configuration to declare lazy magics + that will only be imported/registered on first use. + + For example:: + + c.MagicsManger.lazy_magics = { + "my_magic": "slow.to.import", + "my_other_magic": "also.slow", + } + + On first invocation of `%my_magic`, `%%my_magic`, `%%my_other_magic` or + `%%my_other_magic`, the corresponding module will be loaded as an ipython + extensions as if you had previously done `%load_ext ipython`. + + Magics names should be without percent(s) as magics can be both cell + and line magics. + + Lazy loading happen relatively late in execution process, and + complex extensions that manipulate Python/IPython internal state or global state + might not support lazy loading. + """ + ).tag( + config=True, + ) # A registry of the original objects that we've been given holding magics. registry = Dict() @@ -374,6 +402,24 @@ class MagicsManager(Configurable): docs[m_type] = m_docs return docs + def register_lazy(self, name: str, fully_qualified_name: str): + """ + Lazily register a magic via an extension. + + + Parameters + ---------- + name : str + Name of the magic you wish to register. + fully_qualified_name : + Fully qualified name of the module/submodule that should be loaded + as an extensions when the magic is first called. + It is assumed that loading this extensions will register the given + magic. + """ + + self.lazy_magics[name] = fully_qualified_name + def register(self, *magic_objects): """Register one or more instances of Magics. diff --git a/contrib/python/ipython/py3/IPython/core/release.py b/contrib/python/ipython/py3/IPython/core/release.py index 90d9e6caf5..8faabe871f 100644 --- a/contrib/python/ipython/py3/IPython/core/release.py +++ b/contrib/python/ipython/py3/IPython/core/release.py @@ -20,8 +20,8 @@ name = 'ipython' # release. 'dev' as a _version_extra string means this is a development # version _version_major = 7 -_version_minor = 31 -_version_patch = 1 +_version_minor = 32 +_version_patch = 0 _version_extra = '.dev' # _version_extra = 'b1' _version_extra = "" # Uncomment this for full releases diff --git a/contrib/python/ipython/py3/IPython/terminal/ipapp.py b/contrib/python/ipython/py3/IPython/terminal/ipapp.py index defe3e79fa..b2b8d5f964 100644 --- a/contrib/python/ipython/py3/IPython/terminal/ipapp.py +++ b/contrib/python/ipython/py3/IPython/terminal/ipapp.py @@ -25,6 +25,7 @@ from IPython.core.history import HistoryManager from IPython.core.application import ( ProfileDir, BaseIPythonApplication, base_flags, base_aliases ) +from IPython.core.magic import MagicsManager from IPython.core.magics import ( ScriptMagics, LoggingMagics ) @@ -200,6 +201,7 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): self.__class__, # it will also affect subclasses (e.g. QtConsole) TerminalInteractiveShell, HistoryManager, + MagicsManager, ProfileDir, PlainTextFormatter, IPCompleter, diff --git a/contrib/python/ipython/py3/IPython/utils/_sysinfo.py b/contrib/python/ipython/py3/IPython/utils/_sysinfo.py index 084b3b16a1..950e8a10d6 100644 --- a/contrib/python/ipython/py3/IPython/utils/_sysinfo.py +++ b/contrib/python/ipython/py3/IPython/utils/_sysinfo.py @@ -1,2 +1,2 @@ # GENERATED BY setup.py -commit = u"e321e760a" +commit = u"e84cee846" diff --git a/contrib/python/ipython/py3/ya.make b/contrib/python/ipython/py3/ya.make index a0f1dd9e64..8cdfa2220f 100644 --- a/contrib/python/ipython/py3/ya.make +++ b/contrib/python/ipython/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() OWNER(borman nslus g:python-contrib) -VERSION(7.31.1) +VERSION(7.32.0) LICENSE(BSD-3-Clause) |