aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/patches/01-arcadia.patch
blob: eafd4f30f6c5f441eeae0ccdc027f937100bdb48 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
--- contrib/python/ipython/py3/IPython/core/completer.py	(index)
+++ contrib/python/ipython/py3/IPython/core/completer.py	(working tree)
@@ -1025,6 +1025,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()
@@ -1438,7 +1439,7 @@ class IPCompleter(Completer):
                 else:
                     raise ValueError("Don't understand self.omit__names == {}".format(self.omit__names))
 
-        interpreter = jedi.Interpreter(text[:offset], namespaces)
+        interpreter = jedi.Interpreter(text[:offset], namespaces, column=cursor_column, line=cursor_line + 1)
         try_jedi = True
 
         try:
@@ -1465,7 +1466,7 @@ class IPCompleter(Completer):
         if not try_jedi:
             return []
         try:
-            return filter(completion_filter, interpreter.complete(column=cursor_column, line=cursor_line + 1))
+            return filter(completion_filter, interpreter.completions())
         except Exception as e:
             if self.debug:
                 return [_FakeJediCompletion('Oops Jedi has crashed, please report a bug with the following:\n"""\n%s\ns"""' % (e))]
--- contrib/python/ipython/py3/IPython/core/completerlib.py	(index)
+++ contrib/python/ipython/py3/IPython/core/completerlib.py	(working tree)
@@ -18,6 +18,7 @@ These are all loaded by default by IPython.
 # Stdlib imports
 import glob
 import inspect
+import itertools
 import os
 import re
 import sys
@@ -39,6 +40,8 @@ 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]?)$')
 # 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
@@ -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,10 +238,10 @@ def try_import(mod: str, only_modules=False) -> List[str]:
         completions.extend(m_all)

     if m_is_init:
-        completions.extend(module_list(os.path.dirname(m.__file__)))
+        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/extensions.py	(index)
+++ contrib/python/ipython/py3/IPython/core/extensions.py	(working tree)
@@ -84,11 +84,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:
                     mod = import_module(module_str)
                     if mod.__file__.startswith(self.ipython_extension_dir):
                         print(("Loading extensions from {dir} is deprecated. "
--- contrib/python/ipython/py3/IPython/core/profiledir.py	(index)
+++ contrib/python/ipython/py3/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):