123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- --- 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):
|