|
@@
-14,7
+14,6
b''
|
|
14
|
# Imports
|
|
14
|
# Imports
|
|
15
|
#-----------------------------------------------------------------------------
|
|
15
|
#-----------------------------------------------------------------------------
|
|
16
|
|
|
16
|
|
|
17
|
from __future__ import with_statement
|
|
|
|
|
18
|
from __future__ import absolute_import
|
|
17
|
from __future__ import absolute_import
|
|
19
|
from __future__ import print_function
|
|
18
|
from __future__ import print_function
|
|
20
|
|
|
19
|
|
|
@@
-42,7
+41,7
b' from IPython.core import ultratb'
|
|
42
|
from IPython.core.alias import AliasManager, AliasError
|
|
41
|
from IPython.core.alias import AliasManager, AliasError
|
|
43
|
from IPython.core.autocall import ExitAutocall
|
|
42
|
from IPython.core.autocall import ExitAutocall
|
|
44
|
from IPython.core.builtin_trap import BuiltinTrap
|
|
43
|
from IPython.core.builtin_trap import BuiltinTrap
|
|
45
|
from IPython.core.compilerop import CachingCompiler
|
|
44
|
from IPython.core.compilerop import CachingCompiler, check_linecache_ipython
|
|
46
|
from IPython.core.display_trap import DisplayTrap
|
|
45
|
from IPython.core.display_trap import DisplayTrap
|
|
47
|
from IPython.core.displayhook import DisplayHook
|
|
46
|
from IPython.core.displayhook import DisplayHook
|
|
48
|
from IPython.core.displaypub import DisplayPublisher
|
|
47
|
from IPython.core.displaypub import DisplayPublisher
|
|
@@
-1533,7
+1532,7
b' class InteractiveShell(SingletonConfigurable):'
|
|
1533
|
self.InteractiveTB = ultratb.AutoFormattedTB(mode = 'Plain',
|
|
1532
|
self.InteractiveTB = ultratb.AutoFormattedTB(mode = 'Plain',
|
|
1534
|
color_scheme='NoColor',
|
|
1533
|
color_scheme='NoColor',
|
|
1535
|
tb_offset = 1,
|
|
1534
|
tb_offset = 1,
|
|
1536
|
check_cache=self.compile.check_cache)
|
|
1535
|
check_cache=check_linecache_ipython)
|
|
1537
|
|
|
1536
|
|
|
1538
|
# The instance will store a pointer to the system-wide exception hook,
|
|
1537
|
# The instance will store a pointer to the system-wide exception hook,
|
|
1539
|
# so that runtime code (such as magics) can access it. This is because
|
|
1538
|
# so that runtime code (such as magics) can access it. This is because
|
|
@@
-2518,7
+2517,7
b' class InteractiveShell(SingletonConfigurable):'
|
|
2518
|
# raised in user code. It would be nice if there were
|
|
2517
|
# raised in user code. It would be nice if there were
|
|
2519
|
# versions of runlines, execfile that did raise, so
|
|
2518
|
# versions of runlines, execfile that did raise, so
|
|
2520
|
# we could catch the errors.
|
|
2519
|
# we could catch the errors.
|
|
2521
|
self.run_cell(thefile.read(), store_history=False)
|
|
2520
|
self.run_cell(thefile.read(), store_history=False, shell_futures=False)
|
|
2522
|
except:
|
|
2521
|
except:
|
|
2523
|
self.showtraceback()
|
|
2522
|
self.showtraceback()
|
|
2524
|
warn('Unknown failure executing file: <%s>' % fname)
|
|
2523
|
warn('Unknown failure executing file: <%s>' % fname)
|
|
@@
-2552,7
+2551,7
b' class InteractiveShell(SingletonConfigurable):'
|
|
2552
|
self._current_cell_magic_body = None
|
|
2551
|
self._current_cell_magic_body = None
|
|
2553
|
return self.run_cell_magic(magic_name, line, cell)
|
|
2552
|
return self.run_cell_magic(magic_name, line, cell)
|
|
2554
|
|
|
2553
|
|
|
2555
|
def run_cell(self, raw_cell, store_history=False, silent=False):
|
|
2554
|
def run_cell(self, raw_cell, store_history=False, silent=False, shell_futures=True):
|
|
2556
|
"""Run a complete IPython cell.
|
|
2555
|
"""Run a complete IPython cell.
|
|
2557
|
|
|
2556
|
|
|
2558
|
Parameters
|
|
2557
|
Parameters
|
|
@@
-2566,6
+2565,11
b' class InteractiveShell(SingletonConfigurable):'
|
|
2566
|
silent : bool
|
|
2565
|
silent : bool
|
|
2567
|
If True, avoid side-effects, such as implicit displayhooks and
|
|
2566
|
If True, avoid side-effects, such as implicit displayhooks and
|
|
2568
|
and logging. silent=True forces store_history=False.
|
|
2567
|
and logging. silent=True forces store_history=False.
|
|
|
|
|
2568
|
shell_futures : bool
|
|
|
|
|
2569
|
If True, the code will share future statements with the interactive
|
|
|
|
|
2570
|
shell. It will both be affected by previous __future__ imports, and
|
|
|
|
|
2571
|
any __future__ imports in the code will affect the shell. If False,
|
|
|
|
|
2572
|
__future__ imports are not shared in either direction.
|
|
2569
|
"""
|
|
2573
|
"""
|
|
2570
|
if (not raw_cell) or raw_cell.isspace():
|
|
2574
|
if (not raw_cell) or raw_cell.isspace():
|
|
2571
|
return
|
|
2575
|
return
|
|
@@
-2584,6
+2588,11
b' class InteractiveShell(SingletonConfigurable):'
|
|
2584
|
''.join(self.input_splitter.cell_magic_parts)
|
|
2588
|
''.join(self.input_splitter.cell_magic_parts)
|
|
2585
|
cell = self.input_splitter.source_reset()
|
|
2589
|
cell = self.input_splitter.source_reset()
|
|
2586
|
|
|
2590
|
|
|
|
|
|
2591
|
# Our own compiler remembers the __future__ environment. If we want to
|
|
|
|
|
2592
|
# run code with a separate __future__ environment, use the default
|
|
|
|
|
2593
|
# compiler
|
|
|
|
|
2594
|
compiler = self.compile if shell_futures else CachingCompiler()
|
|
|
|
|
2595
|
|
|
2587
|
with self.builtin_trap:
|
|
2596
|
with self.builtin_trap:
|
|
2588
|
prefilter_failed = False
|
|
2597
|
prefilter_failed = False
|
|
2589
|
if len(cell.splitlines()) == 1:
|
|
2598
|
if len(cell.splitlines()) == 1:
|
|
@@
-2612,8
+2621,7
b' class InteractiveShell(SingletonConfigurable):'
|
|
2612
|
|
|
2621
|
|
|
2613
|
with self.display_trap:
|
|
2622
|
with self.display_trap:
|
|
2614
|
try:
|
|
2623
|
try:
|
|
2615
|
code_ast = self.compile.ast_parse(cell,
|
|
2624
|
code_ast = compiler.ast_parse(cell, filename=cell_name)
|
|
2616
|
filename=cell_name)
|
|
|
|
|
2617
|
except IndentationError:
|
|
2625
|
except IndentationError:
|
|
2618
|
self.showindentationerror()
|
|
2626
|
self.showindentationerror()
|
|
2619
|
if store_history:
|
|
2627
|
if store_history:
|
|
@@
-2630,7
+2638,7
b' class InteractiveShell(SingletonConfigurable):'
|
|
2630
|
|
|
2638
|
|
|
2631
|
interactivity = "none" if silent else self.ast_node_interactivity
|
|
2639
|
interactivity = "none" if silent else self.ast_node_interactivity
|
|
2632
|
self.run_ast_nodes(code_ast.body, cell_name,
|
|
2640
|
self.run_ast_nodes(code_ast.body, cell_name,
|
|
2633
|
interactivity=interactivity)
|
|
2641
|
interactivity=interactivity, compiler=compiler)
|
|
2634
|
|
|
2642
|
|
|
2635
|
# Execute any registered post-execution functions.
|
|
2643
|
# Execute any registered post-execution functions.
|
|
2636
|
# unless we are silent
|
|
2644
|
# unless we are silent
|
|
@@
-2686,7
+2694,8
b' class InteractiveShell(SingletonConfigurable):'
|
|
2686
|
return ast.fix_missing_locations(node)
|
|
2694
|
return ast.fix_missing_locations(node)
|
|
2687
|
|
|
2695
|
|
|
2688
|
|
|
2696
|
|
|
2689
|
def run_ast_nodes(self, nodelist, cell_name, interactivity='last_expr'):
|
|
2697
|
def run_ast_nodes(self, nodelist, cell_name, interactivity='last_expr',
|
|
|
|
|
2698
|
compiler=compile):
|
|
2690
|
"""Run a sequence of AST nodes. The execution mode depends on the
|
|
2699
|
"""Run a sequence of AST nodes. The execution mode depends on the
|
|
2691
|
interactivity parameter.
|
|
2700
|
interactivity parameter.
|
|
2692
|
|
|
2701
|
|
|
@@
-2703,6
+2712,9
b' class InteractiveShell(SingletonConfigurable):'
|
|
2703
|
will run the last node interactively only if it is an expression (i.e.
|
|
2712
|
will run the last node interactively only if it is an expression (i.e.
|
|
2704
|
expressions in loops or other blocks are not displayed. Other values
|
|
2713
|
expressions in loops or other blocks are not displayed. Other values
|
|
2705
|
for this parameter will raise a ValueError.
|
|
2714
|
for this parameter will raise a ValueError.
|
|
|
|
|
2715
|
compiler : callable
|
|
|
|
|
2716
|
A function with the same interface as the built-in compile(), to turn
|
|
|
|
|
2717
|
the AST nodes into code objects. Default is the built-in compile().
|
|
2706
|
"""
|
|
2718
|
"""
|
|
2707
|
if not nodelist:
|
|
2719
|
if not nodelist:
|
|
2708
|
return
|
|
2720
|
return
|
|
@@
-2727,13
+2739,13
b' class InteractiveShell(SingletonConfigurable):'
|
|
2727
|
try:
|
|
2739
|
try:
|
|
2728
|
for i, node in enumerate(to_run_exec):
|
|
2740
|
for i, node in enumerate(to_run_exec):
|
|
2729
|
mod = ast.Module([node])
|
|
2741
|
mod = ast.Module([node])
|
|
2730
|
code = self.compile(mod, cell_name, "exec")
|
|
2742
|
code = compiler(mod, cell_name, "exec")
|
|
2731
|
if self.run_code(code):
|
|
2743
|
if self.run_code(code):
|
|
2732
|
return True
|
|
2744
|
return True
|
|
2733
|
|
|
2745
|
|
|
2734
|
for i, node in enumerate(to_run_interactive):
|
|
2746
|
for i, node in enumerate(to_run_interactive):
|
|
2735
|
mod = ast.Interactive([node])
|
|
2747
|
mod = ast.Interactive([node])
|
|
2736
|
code = self.compile(mod, cell_name, "single")
|
|
2748
|
code = compiler(mod, cell_name, "single")
|
|
2737
|
if self.run_code(code):
|
|
2749
|
if self.run_code(code):
|
|
2738
|
return True
|
|
2750
|
return True
|
|
2739
|
|
|
2751
|
|