##// END OF EJS Templates
Merge pull request #12825 from meeseeksmachine/auto-backport-of-pr-12809-on-7.x...
Matthias Bussonnier -
r26337:3c039d4c merge
parent child Browse files
Show More
@@ -112,25 +112,53 b' class CachingCompiler(codeop.Compile):'
112 """
112 """
113 return self.flags
113 return self.flags
114
114
115 def cache(self, code, number=0):
115 def get_code_name(self, raw_code, transformed_code, number):
116 """Compute filename given the code, and the cell number.
117
118 Parameters
119 ----------
120 raw_code : str
121 The raw cell code.
122 transformed_code : str
123 The executable Python source code to cache and compile.
124 number : int
125 A number which forms part of the code's name. Used for the execution
126 counter.
127
128 Returns
129 -------
130 The computed filename.
131 """
132 return code_name(transformed_code, number)
133
134 def cache(self, transformed_code, number=0, raw_code=None):
116 """Make a name for a block of code, and cache the code.
135 """Make a name for a block of code, and cache the code.
117
136
118 Parameters
137 Parameters
119 ----------
138 ----------
120 code : str
139 transformed_code : str
121 The Python source code to cache.
140 The executable Python source code to cache and compile.
122 number : int
141 number : int
123 A number which forms part of the code's name. Used for the execution
142 A number which forms part of the code's name. Used for the execution
124 counter.
143 counter.
144 raw_code : str
145 The raw code before transformation, if None, set to `transformed_code`.
125
146
126 Returns
147 Returns
127 -------
148 -------
128 The name of the cached code (as a string). Pass this as the filename
149 The name of the cached code (as a string). Pass this as the filename
129 argument to compilation, so that tracebacks are correctly hooked up.
150 argument to compilation, so that tracebacks are correctly hooked up.
130 """
151 """
131 name = code_name(code, number)
152 if raw_code is None:
132 entry = (len(code), time.time(),
153 raw_code = transformed_code
133 [line+'\n' for line in code.splitlines()], name)
154
155 name = self.get_code_name(raw_code, transformed_code, number)
156 entry = (
157 len(transformed_code),
158 time.time(),
159 [line + "\n" for line in transformed_code.splitlines()],
160 name,
161 )
134 linecache.cache[name] = entry
162 linecache.cache[name] = entry
135 linecache._ipython_cache[name] = entry
163 linecache._ipython_cache[name] = entry
136 return name
164 return name
@@ -443,6 +443,7 b' class InteractiveShell(SingletonConfigurable):'
443 display_formatter = Instance(DisplayFormatter, allow_none=True)
443 display_formatter = Instance(DisplayFormatter, allow_none=True)
444 displayhook_class = Type(DisplayHook)
444 displayhook_class = Type(DisplayHook)
445 display_pub_class = Type(DisplayPublisher)
445 display_pub_class = Type(DisplayPublisher)
446 compiler_class = Type(CachingCompiler)
446
447
447 sphinxify_docstring = Bool(False, help=
448 sphinxify_docstring = Bool(False, help=
448 """
449 """
@@ -748,7 +749,7 b' class InteractiveShell(SingletonConfigurable):'
748 self.more = False
749 self.more = False
749
750
750 # command compiler
751 # command compiler
751 self.compile = CachingCompiler()
752 self.compile = self.compiler_class()
752
753
753 # Make an empty namespace, which extension writers can rely on both
754 # Make an empty namespace, which extension writers can rely on both
754 # existing and NEVER being used by ipython itself. This gives them a
755 # existing and NEVER being used by ipython itself. This gives them a
@@ -1765,8 +1766,14 b' class InteractiveShell(SingletonConfigurable):'
1765 if meth == 'pdoc':
1766 if meth == 'pdoc':
1766 pmethod(info.obj, oname, formatter)
1767 pmethod(info.obj, oname, formatter)
1767 elif meth == 'pinfo':
1768 elif meth == 'pinfo':
1768 pmethod(info.obj, oname, formatter, info,
1769 pmethod(
1769 enable_html_pager=self.enable_html_pager, **kw)
1770 info.obj,
1771 oname,
1772 formatter,
1773 info,
1774 enable_html_pager=self.enable_html_pager,
1775 **kw
1776 )
1770 else:
1777 else:
1771 pmethod(info.obj, oname)
1778 pmethod(info.obj, oname)
1772 else:
1779 else:
@@ -2289,8 +2296,9 b' class InteractiveShell(SingletonConfigurable):'
2289 # Defined here so that it's included in the documentation
2296 # Defined here so that it's included in the documentation
2290 @functools.wraps(magic.MagicsManager.register_function)
2297 @functools.wraps(magic.MagicsManager.register_function)
2291 def register_magic_function(self, func, magic_kind='line', magic_name=None):
2298 def register_magic_function(self, func, magic_kind='line', magic_name=None):
2292 self.magics_manager.register_function(func,
2299 self.magics_manager.register_function(
2293 magic_kind=magic_kind, magic_name=magic_name)
2300 func, magic_kind=magic_kind, magic_name=magic_name
2301 )
2294
2302
2295 def run_line_magic(self, magic_name, line, _stack_depth=1):
2303 def run_line_magic(self, magic_name, line, _stack_depth=1):
2296 """Execute the given line magic.
2304 """Execute the given line magic.
@@ -3092,12 +3100,14 b' class InteractiveShell(SingletonConfigurable):'
3092 # Our own compiler remembers the __future__ environment. If we want to
3100 # Our own compiler remembers the __future__ environment. If we want to
3093 # run code with a separate __future__ environment, use the default
3101 # run code with a separate __future__ environment, use the default
3094 # compiler
3102 # compiler
3095 compiler = self.compile if shell_futures else CachingCompiler()
3103 compiler = self.compile if shell_futures else self.compiler_class()
3096
3104
3097 _run_async = False
3105 _run_async = False
3098
3106
3099 with self.builtin_trap:
3107 with self.builtin_trap:
3100 cell_name = self.compile.cache(cell, self.execution_count)
3108 cell_name = self.compile.cache(
3109 cell, self.execution_count, raw_code=raw_cell
3110 )
3101
3111
3102 with self.display_trap:
3112 with self.display_trap:
3103 # Compile to bytecode
3113 # Compile to bytecode
General Comments 0
You need to be logged in to leave comments. Login now