01-arcadia.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. --- contrib/python/ipython/py3/IPython/core/completer.py (index)
  2. +++ contrib/python/ipython/py3/IPython/core/completer.py (working tree)
  3. @@ -1362,6 +1362,7 @@ def _make_signature(completion)-> str:
  4. """
  5. + return '(%s)'% ', '.join([f for f in (_formatparamchildren(p) for p in completion.params) if f])
  6. # it looks like this might work on jedi 0.17
  7. if hasattr(completion, 'get_signatures'):
  8. signatures = completion.get_signatures()
  9. @@ -1921,1 +1922,1 @@ class IPCompleter(Completer):
  10. - interpreter = jedi.Interpreter(text[:offset], namespaces)
  11. + interpreter = jedi.Interpreter(text[:offset], namespaces, column=cursor_column, line=cursor_line + 1)
  12. @@ -1948,1 +1949,1 @@ class IPCompleter(Completer):
  13. - return filter(completion_filter, interpreter.complete(column=cursor_column, line=cursor_line + 1))
  14. + return filter(completion_filter, interpreter.completions())
  15. --- contrib/python/ipython/py3/IPython/core/completerlib.py (index)
  16. +++ contrib/python/ipython/py3/IPython/core/completerlib.py (working tree)
  17. @@ -20,2 +20,3 @@ These are all loaded by default by IPython.
  18. import inspect
  19. +import itertools
  20. import os
  21. @@ -40,4 +41,6 @@ from IPython import get_ipython
  22. from typing import List
  23. +from __res import importer
  24. +
  25. #-----------------------------------------------------------------------------
  26. # Globals and constants
  27. @@ -64,6 +67,50 @@ magic_run_re = re.compile(r'.*(\.ipy|\.ipynb|\.py[w]?)$')
  28. #-----------------------------------------------------------------------------
  29. +arcadia_rootmodules_cache = None
  30. +arcadia_modules_cache = None
  31. +
  32. +
  33. +def arcadia_init_cache():
  34. + global arcadia_rootmodules_cache, arcadia_modules_cache
  35. + arcadia_rootmodules_cache = set()
  36. + arcadia_modules_cache = {}
  37. +
  38. + all_modules = itertools.chain(
  39. + sys.builtin_module_names,
  40. + importer.memory
  41. + )
  42. +
  43. + for name in all_modules:
  44. + path = name.split('.')
  45. + arcadia_rootmodules_cache.add(path[0])
  46. +
  47. + prefix = path[0]
  48. + for element in path[1:]:
  49. + if element == '__init__':
  50. + continue
  51. +
  52. + arcadia_modules_cache.setdefault(prefix, set()).add(element)
  53. + prefix += '.' + element
  54. +
  55. + arcadia_rootmodules_cache = sorted(arcadia_rootmodules_cache)
  56. + arcadia_modules_cache = {k: sorted(v) for k, v in arcadia_modules_cache.items()}
  57. +
  58. +
  59. +def arcadia_module_list(mod):
  60. + if arcadia_modules_cache is None:
  61. + arcadia_init_cache()
  62. +
  63. + return arcadia_modules_cache.get(mod, ())
  64. +
  65. +
  66. +def arcadia_get_root_modules():
  67. + if arcadia_rootmodules_cache is None:
  68. + arcadia_init_cache()
  69. +
  70. + return arcadia_rootmodules_cache
  71. +
  72. +
  73. def module_list(path: str) -> List[str]:
  74. """
  75. Return the list containing the names of the modules available in the given
  76. @@ -176,7 +223,8 @@ def try_import(mod: str, only_modules=False) -> List[str]:
  77. except:
  78. return []
  79. - m_is_init = '__init__' in (getattr(m, '__file__', '') or '')
  80. + filename = getattr(m, '__file__', '')
  81. + m_is_init = '__init__' in (filename or '') or filename == mod
  82. completions = []
  83. if (not hasattr(m, '__file__')) or (not only_modules) or m_is_init:
  84. @@ -190,9 +238,10 @@ def try_import(mod: str, only_modules=False) -> List[str]:
  85. file_path = os.path.dirname(file_) # type: ignore
  86. if file_path is not None:
  87. completions.extend(module_list(file_path))
  88. + completions.extend(arcadia_module_list(mod))
  89. completions_set = {c for c in completions if isinstance(c, str)}
  90. completions_set.discard('__init__')
  91. - return list(completions_set)
  92. + return sorted(completions_set)
  93. #-----------------------------------------------------------------------------
  94. @@ -242,10 +290,10 @@ def module_completion(line):
  95. # 'from xy<tab>' or 'import xy<tab>'
  96. if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) :
  97. if nwords == 1:
  98. - return get_root_modules()
  99. + return arcadia_get_root_modules()
  100. mod = words[1].split('.')
  101. if len(mod) < 2:
  102. - return get_root_modules()
  103. + return arcadia_get_root_modules()
  104. completion_list = try_import('.'.join(mod[:-1]), True)
  105. return ['.'.join(mod[:-1] + [el]) for el in completion_list]
  106. --- contrib/python/ipython/py3/IPython/core/profiledir.py (index)
  107. +++ contrib/python/ipython/py3/IPython/core/profiledir.py (working tree)
  108. @@ -126,18 +126,12 @@ class ProfileDir(LoggingConfigurable):
  109. def check_startup_dir(self, change=None):
  110. if self._mkdir(self.startup_dir):
  111. readme = os.path.join(self.startup_dir, "README")
  112. - src = os.path.join(
  113. - get_ipython_package_dir(), "core", "profile", "README_STARTUP"
  114. - )
  115. - if os.path.exists(src):
  116. - if not os.path.exists(readme):
  117. - shutil.copy(src, readme)
  118. - else:
  119. - self.log.warning(
  120. - "Could not copy README_STARTUP to startup dir. Source file %s does not exist.",
  121. - src,
  122. - )
  123. + if not os.path.exists(readme):
  124. + import pkgutil
  125. + with open(readme, "wb") as f:
  126. + f.write(pkgutil.get_data(__name__, "profile/README_STARTUP"))
  127. + return
  128. @observe('security_dir')
  129. def check_security_dir(self, change=None):