diff options
author | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 12:29:46 +0300 |
---|---|---|
committer | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 13:14:22 +0300 |
commit | 9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80 (patch) | |
tree | a8fb3181d5947c0d78cf402aa56e686130179049 /contrib/python/ipython | |
parent | a44b779cd359f06c3ebbef4ec98c6b38609d9d85 (diff) | |
download | ydb-9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80.tar.gz |
publishFullContrib: true for ydb
<HIDDEN_URL>
commit_hash:c82a80ac4594723cebf2c7387dec9c60217f603e
Diffstat (limited to 'contrib/python/ipython')
9 files changed, 385 insertions, 0 deletions
diff --git a/contrib/python/ipython/py2/.yandex_meta/yamaker.yaml b/contrib/python/ipython/py2/.yandex_meta/yamaker.yaml new file mode 100644 index 0000000000..60823c058c --- /dev/null +++ b/contrib/python/ipython/py2/.yandex_meta/yamaker.yaml @@ -0,0 +1,2 @@ +exclude_from_macros: + - IPython/testing/plugin/*.txt diff --git a/contrib/python/ipython/py2/patches/01-arcadia.patch b/contrib/python/ipython/py2/patches/01-arcadia.patch new file mode 100644 index 0000000000..3a14077574 --- /dev/null +++ b/contrib/python/ipython/py2/patches/01-arcadia.patch @@ -0,0 +1,144 @@ +--- contrib/python/ipython/py2/IPython/core/completerlib.py (index) ++++ contrib/python/ipython/py2/IPython/core/completerlib.py (working tree) +@@ -19,6 +19,7 @@ from __future__ import print_function + # Stdlib imports + import glob + import inspect ++import itertools + import os + import re + import sys +@@ -44,6 +45,8 @@ from IPython.utils.py3compat import string_types + # FIXME: this should be pulled in with the right call via the component system + from IPython import get_ipython + ++from __res import importer ++ + #----------------------------------------------------------------------------- + # Globals and constants + #----------------------------------------------------------------------------- +@@ -68,6 +71,51 @@ magic_run_re = re.compile(r'.*(\.ipy|\.ipynb|\.py[w]?)$') + # Local utilities + #----------------------------------------------------------------------------- + ++arcadia_rootmodules_cache = None ++arcadia_modules_cache = None ++ ++ ++def arcadia_init_cache(): ++ global arcadia_rootmodules_cache, arcadia_modules_cache ++ arcadia_rootmodules_cache = set() ++ arcadia_modules_cache = {} ++ ++ all_modules = itertools.chain( ++ sys.builtin_module_names, ++ importer.memory ++ ) ++ ++ for name in all_modules: ++ path = name.split('.') ++ arcadia_rootmodules_cache.add(path[0]) ++ ++ prefix = path[0] ++ for element in path[1:]: ++ if element == '__init__': ++ continue ++ ++ arcadia_modules_cache.setdefault(prefix, set()).add(element) ++ prefix += '.' + element ++ ++ arcadia_rootmodules_cache = sorted(arcadia_rootmodules_cache) ++ arcadia_modules_cache = {k: sorted(v) for k, v in arcadia_modules_cache.items()} ++ ++ ++def arcadia_module_list(mod): ++ if arcadia_modules_cache is None: ++ arcadia_init_cache() ++ ++ return arcadia_modules_cache.get(mod, ()) ++ ++ ++def arcadia_get_root_modules(): ++ if arcadia_rootmodules_cache is None: ++ arcadia_init_cache() ++ ++ return arcadia_rootmodules_cache ++ ++ ++ + def module_list(path): + """ + Return the list containing the names of the modules available in the given +@@ -168,7 +216,8 @@ def try_import(mod, only_modules=False): + for module in mods[1:]: + m = getattr(m, module) + +- m_is_init = hasattr(m, '__file__') and '__init__' in m.__file__ ++ filename = getattr(m, '__file__', '') ++ m_is_init = '__init__' in (filename or '') or filename == mod + + completions = [] + if (not hasattr(m, '__file__')) or (not only_modules) or m_is_init: +@@ -177,10 +226,10 @@ def try_import(mod, only_modules=False): + + completions.extend(getattr(m, '__all__', [])) + if m_is_init: +- completions.extend(module_list(os.path.dirname(m.__file__))) ++ completions.extend(arcadia_module_list(mod)) + completions = {c for c in completions if isinstance(c, string_types)} + completions.discard('__init__') +- return list(completions) ++ return sorted(completions) + + + #----------------------------------------------------------------------------- +@@ -229,10 +278,10 @@ def module_completion(line): + # 'from xy<tab>' or 'import xy<tab>' + if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) : + if nwords == 1: +- return get_root_modules() ++ return arcadia_get_root_modules() + mod = words[1].split('.') + if len(mod) < 2: +- return get_root_modules() ++ return arcadia_get_root_modules() + completion_list = try_import('.'.join(mod[:-1]), True) + return ['.'.join(mod[:-1] + [el]) for el in completion_list] + +--- contrib/python/ipython/py2/IPython/core/extensions.py (index) ++++ contrib/python/ipython/py2/IPython/core/extensions.py (working tree) +@@ -75,11 +75,11 @@ class ExtensionManager(Configurable): + if module_str in self.loaded: + return "already loaded" + +- from IPython.utils.syspathcontext import prepended_to_syspath +- + with self.shell.builtin_trap: + if module_str not in sys.modules: +- with prepended_to_syspath(self.ipython_extension_dir): ++ try: ++ sys.modules[module_str] = __import__('IPython.extensions.' + module_str) ++ except ImportError: + __import__(module_str) + mod = sys.modules[module_str] + if self._call_load_ipython_extension(mod): +--- contrib/python/ipython/py2/IPython/core/profiledir.py (index) ++++ contrib/python/ipython/py2/IPython/core/profiledir.py (working tree) +@@ -112,13 +112,11 @@ class ProfileDir(LoggingConfigurable): + self._mkdir(self.startup_dir) + + readme = os.path.join(self.startup_dir, 'README') +- src = os.path.join(get_ipython_package_dir(), u'core', u'profile', u'README_STARTUP') + +- if not os.path.exists(src): +- self.log.warning("Could not copy README_STARTUP to startup dir. Source file %s does not exist.", src) +- +- if os.path.exists(src) and not os.path.exists(readme): +- shutil.copy(src, readme) ++ if not os.path.exists(readme): ++ import pkgutil ++ with open(readme, 'wb') as f: ++ f.write(pkgutil.get_data(__name__, 'profile/README_STARTUP')) + + @observe('security_dir') + def check_security_dir(self, change=None): diff --git a/contrib/python/ipython/py2/patches/02-fix-ya.make.patch b/contrib/python/ipython/py2/patches/02-fix-ya.make.patch new file mode 100644 index 0000000000..1317ceea2d --- /dev/null +++ b/contrib/python/ipython/py2/patches/02-fix-ya.make.patch @@ -0,0 +1,28 @@ +--- contrib/python/ipython/py2/ya.make (index) ++++ contrib/python/ipython/py2/ya.make (working tree) +@@ -16,1 +15,0 @@ PEERDIR( +- contrib/python/pexpect +@@ -21,6 +18,23 @@ PEERDIR( + contrib/python/traitlets + ) + ++IF (OS_WINDOWS) ++ PEERDIR( ++ contrib/python/colorama ++ contrib/deprecated/python/win-unicode-console ++ ) ++ELSE () ++ PEERDIR( ++ contrib/python/pexpect ++ ) ++ENDIF () ++ ++IF (OS_DARWIN) ++ PEERDIR( ++ contrib/python/appnope ++ ) ++ENDIF () ++ + NO_LINT() + + NO_CHECK_IMPORTS( diff --git a/contrib/python/ipython/py2/patches/03-fix-context-lines.patch b/contrib/python/ipython/py2/patches/03-fix-context-lines.patch new file mode 100644 index 0000000000..4627040e00 --- /dev/null +++ b/contrib/python/ipython/py2/patches/03-fix-context-lines.patch @@ -0,0 +1,11 @@ +--- contrib/python/ipython/py2/IPython/core/debugger.py (revision 12930657) ++++ contrib/python/ipython/py2/IPython/core/debugger.py (working copy) +@@ -408,7 +408,7 @@ + ret.append(u'%s(%s)%s\n' % (link,lineno,call)) + + start = lineno - 1 - context//2 +- lines = ulinecache.getlines(filename) ++ lines = ulinecache.getlines(filename, frame.f_globals) + start = min(start, len(lines) - context) + start = max(start, 0) + lines = lines[start : start + context] diff --git a/contrib/python/ipython/py3/.yandex_meta/yamaker.yaml b/contrib/python/ipython/py3/.yandex_meta/yamaker.yaml new file mode 100644 index 0000000000..60823c058c --- /dev/null +++ b/contrib/python/ipython/py3/.yandex_meta/yamaker.yaml @@ -0,0 +1,2 @@ +exclude_from_macros: + - IPython/testing/plugin/*.txt diff --git a/contrib/python/ipython/py3/patches/01-arcadia.patch b/contrib/python/ipython/py3/patches/01-arcadia.patch new file mode 100644 index 0000000000..9fee8bae72 --- /dev/null +++ b/contrib/python/ipython/py3/patches/01-arcadia.patch @@ -0,0 +1,141 @@ +--- contrib/python/ipython/py3/IPython/core/completer.py (index) ++++ contrib/python/ipython/py3/IPython/core/completer.py (working tree) +@@ -1362,6 +1362,7 @@ def _make_signature(completion)-> str: + + """ + ++ return '(%s)'% ', '.join([f for f in (_formatparamchildren(p) for p in completion.params) if f]) + # it looks like this might work on jedi 0.17 + if hasattr(completion, 'get_signatures'): + signatures = completion.get_signatures() +@@ -1921,1 +1922,1 @@ class IPCompleter(Completer): +- interpreter = jedi.Interpreter(text[:offset], namespaces) ++ interpreter = jedi.Interpreter(text[:offset], namespaces, column=cursor_column, line=cursor_line + 1) +@@ -1948,1 +1949,1 @@ class IPCompleter(Completer): +- return filter(completion_filter, interpreter.complete(column=cursor_column, line=cursor_line + 1)) ++ return filter(completion_filter, interpreter.completions()) +--- contrib/python/ipython/py3/IPython/core/completerlib.py (index) ++++ contrib/python/ipython/py3/IPython/core/completerlib.py (working tree) +@@ -20,2 +20,3 @@ These are all loaded by default by IPython. + import inspect ++import itertools + import os +@@ -40,4 +41,6 @@ from IPython import get_ipython + from typing import List + ++from __res import importer ++ + #----------------------------------------------------------------------------- + # Globals and constants +@@ -64,6 +67,50 @@ magic_run_re = re.compile(r'.*(\.ipy|\.ipynb|\.py[w]?)$') + #----------------------------------------------------------------------------- + + ++arcadia_rootmodules_cache = None ++arcadia_modules_cache = None ++ ++ ++def arcadia_init_cache(): ++ global arcadia_rootmodules_cache, arcadia_modules_cache ++ arcadia_rootmodules_cache = set() ++ arcadia_modules_cache = {} ++ ++ all_modules = itertools.chain( ++ sys.builtin_module_names, ++ importer.memory ++ ) ++ ++ for name in all_modules: ++ path = name.split('.') ++ arcadia_rootmodules_cache.add(path[0]) ++ ++ prefix = path[0] ++ for element in path[1:]: ++ if element == '__init__': ++ continue ++ ++ arcadia_modules_cache.setdefault(prefix, set()).add(element) ++ prefix += '.' + element ++ ++ arcadia_rootmodules_cache = sorted(arcadia_rootmodules_cache) ++ arcadia_modules_cache = {k: sorted(v) for k, v in arcadia_modules_cache.items()} ++ ++ ++def arcadia_module_list(mod): ++ if arcadia_modules_cache is None: ++ arcadia_init_cache() ++ ++ return arcadia_modules_cache.get(mod, ()) ++ ++ ++def arcadia_get_root_modules(): ++ if arcadia_rootmodules_cache is None: ++ arcadia_init_cache() ++ ++ return arcadia_rootmodules_cache ++ ++ + def module_list(path: str) -> List[str]: + """ + Return the list containing the names of the modules available in the given +@@ -176,7 +223,8 @@ def try_import(mod: str, only_modules=False) -> List[str]: + except: + return [] + +- m_is_init = '__init__' in (getattr(m, '__file__', '') or '') ++ filename = getattr(m, '__file__', '') ++ m_is_init = '__init__' in (filename or '') or filename == mod + + completions = [] + if (not hasattr(m, '__file__')) or (not only_modules) or m_is_init: +@@ -190,9 +238,10 @@ def try_import(mod: str, only_modules=False) -> List[str]: + file_path = os.path.dirname(file_) # type: ignore + if file_path is not None: + completions.extend(module_list(file_path)) ++ completions.extend(arcadia_module_list(mod)) + completions_set = {c for c in completions if isinstance(c, str)} + completions_set.discard('__init__') +- return list(completions_set) ++ return sorted(completions_set) + + + #----------------------------------------------------------------------------- +@@ -242,10 +290,10 @@ def module_completion(line): + # 'from xy<tab>' or 'import xy<tab>' + if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) : + if nwords == 1: +- return get_root_modules() ++ return arcadia_get_root_modules() + mod = words[1].split('.') + if len(mod) < 2: +- return get_root_modules() ++ return arcadia_get_root_modules() + completion_list = try_import('.'.join(mod[:-1]), True) + return ['.'.join(mod[:-1] + [el]) for el in completion_list] + +--- contrib/python/ipython/py3/IPython/core/profiledir.py (index) ++++ contrib/python/ipython/py3/IPython/core/profiledir.py (working tree) +@@ -126,18 +126,12 @@ class ProfileDir(LoggingConfigurable): + def check_startup_dir(self, change=None): + if self._mkdir(self.startup_dir): + readme = os.path.join(self.startup_dir, "README") +- src = os.path.join( +- get_ipython_package_dir(), "core", "profile", "README_STARTUP" +- ) + +- if os.path.exists(src): +- if not os.path.exists(readme): +- shutil.copy(src, readme) +- else: +- self.log.warning( +- "Could not copy README_STARTUP to startup dir. Source file %s does not exist.", +- src, +- ) ++ if not os.path.exists(readme): ++ import pkgutil ++ with open(readme, "wb") as f: ++ f.write(pkgutil.get_data(__name__, "profile/README_STARTUP")) ++ return + + @observe('security_dir') + def check_security_dir(self, change=None): diff --git a/contrib/python/ipython/py3/patches/02-fix-ya.make.patch b/contrib/python/ipython/py3/patches/02-fix-ya.make.patch new file mode 100644 index 0000000000..828df69945 --- /dev/null +++ b/contrib/python/ipython/py3/patches/02-fix-ya.make.patch @@ -0,0 +1,32 @@ +--- contrib/python/ipython/py3/.dist-info/METADATA (index) ++++ contrib/python/ipython/py3/.dist-info/METADATA (working tree) +@@ -31,1 +31,1 @@ Classifier: Programming Language :: Python :: 3 :: Only +-Requires-Dist: jedi >=0.16 ++Requires-Dist: jedi >=0.13 +--- contrib/python/ipython/py3/ya.make (index) ++++ contrib/python/ipython/py3/ya.make (working tree) +@@ -17,1 +17,0 @@ PEERDIR( +- contrib/python/pexpect +@@ -21,6 +20,22 @@ PEERDIR( + contrib/python/traitlets + ) + ++IF (OS_WINDOWS) ++ PEERDIR( ++ contrib/python/colorama ++ ) ++ELSE() ++ PEERDIR( ++ contrib/python/pexpect ++ ) ++ENDIF() ++ ++IF (OS_DARWIN) ++ PEERDIR( ++ contrib/python/appnope ++ ) ++ENDIF() ++ + NO_LINT() + + NO_CHECK_IMPORTS( diff --git a/contrib/python/ipython/py3/patches/03-dissable-backgroud-highlighting.patch b/contrib/python/ipython/py3/patches/03-dissable-backgroud-highlighting.patch new file mode 100644 index 0000000000..73b189b863 --- /dev/null +++ b/contrib/python/ipython/py3/patches/03-dissable-backgroud-highlighting.patch @@ -0,0 +1,5 @@ +--- contrib/python/ipython/py3/IPython/core/ultratb.py (index) ++++ contrib/python/ipython/py3/IPython/core/ultratb.py (working tree) +@@ -613,1 +613,1 @@ class VerboseTB(TBTools): +- _tb_highlight = "bg:ansiyellow" ++ _tb_highlight = "" diff --git a/contrib/python/ipython/py3/patches/04-fix-context-lines-and-lines-cmd.patch b/contrib/python/ipython/py3/patches/04-fix-context-lines-and-lines-cmd.patch new file mode 100644 index 0000000000..a25eb8752c --- /dev/null +++ b/contrib/python/ipython/py3/patches/04-fix-context-lines-and-lines-cmd.patch @@ -0,0 +1,20 @@ +--- contrib/python/ipython/py3/IPython/core/debugger.py (revision 12930657) ++++ contrib/python/ipython/py3/IPython/core/debugger.py (working copy) +@@ -616,7 +616,7 @@ + ret.append("%s(%s)%s\n" % (link, lineno, call)) + + start = lineno - 1 - context//2 +- lines = linecache.getlines(filename) ++ lines = linecache.getlines(filename, frame.f_globals) + start = min(start, len(lines) - context) + start = max(start, 0) + lines = lines[start : start + context] +@@ -674,7 +674,7 @@ + filename = self._exec_filename + + for lineno in range(first, last+1): +- line = linecache.getline(filename, lineno) ++ line = linecache.getline(filename, lineno, self.curframe.f_globals) + if not line: + break + |