##// END OF EJS Templates
Change integer options to string options for interactivity.
Thomas Kluyver -
Show More
@@ -7,6 +7,7 b' Authors'
7 -------
7 -------
8 * Robert Kern
8 * Robert Kern
9 * Fernando Perez
9 * Fernando Perez
10 * Thomas Kluyver
10 """
11 """
11
12
12 # Note: though it might be more natural to name this module 'compiler', that
13 # Note: though it might be more natural to name this module 'compiler', that
@@ -2134,9 +2134,9 b' class InteractiveShell(Configurable, Magic):'
2134 self.execution_count += 1
2134 self.execution_count += 1
2135 return None
2135 return None
2136
2136
2137 interactivity = 1 # Last node to be run interactive
2137 interactivity = 'last' # Last node to be run interactive
2138 if len(cell.splitlines()) == 1:
2138 if len(cell.splitlines()) == 1:
2139 interactivity = 2 # Single line; run fully interactive
2139 interactivity = 'all' # Single line; run fully interactive
2140
2140
2141 self.run_ast_nodes(code_ast.body, cell_name, interactivity)
2141 self.run_ast_nodes(code_ast.body, cell_name, interactivity)
2142
2142
@@ -2147,7 +2147,7 b' class InteractiveShell(Configurable, Magic):'
2147 # Each cell is a *single* input, regardless of how many lines it has
2147 # Each cell is a *single* input, regardless of how many lines it has
2148 self.execution_count += 1
2148 self.execution_count += 1
2149
2149
2150 def run_ast_nodes(self, nodelist, cell_name, interactivity=1):
2150 def run_ast_nodes(self, nodelist, cell_name, interactivity='last'):
2151 """Run a sequence of AST nodes. The execution mode depends on the
2151 """Run a sequence of AST nodes. The execution mode depends on the
2152 interactivity parameter.
2152 interactivity parameter.
2153
2153
@@ -2155,20 +2155,25 b' class InteractiveShell(Configurable, Magic):'
2155 ----------
2155 ----------
2156 nodelist : list
2156 nodelist : list
2157 A sequence of AST nodes to run.
2157 A sequence of AST nodes to run.
2158 interactivity : int
2158 cell_name : str
2159 At 0, all nodes are run in 'exec' mode. At '1', the last node alone
2159 Will be passed to the compiler as the filename of the cell. Typically
2160 is run in interactive mode (so the result of an expression is shown).
2160 the value returned by ip.compile.cache(cell).
2161 At 2, all nodes are run in interactive mode.
2161 interactivity : str
2162 'all', 'last' or 'none', specifying which nodes should be run
2163 interactively (displaying output from expressions). Other values for
2164 this parameter will raise a ValueError.
2162 """
2165 """
2163 if not nodelist:
2166 if not nodelist:
2164 return
2167 return
2165
2168
2166 if interactivity == 0:
2169 if interactivity == 'none':
2167 to_run_exec, to_run_interactive = nodelist, []
2170 to_run_exec, to_run_interactive = nodelist, []
2168 elif interactivity == 1:
2171 elif interactivity == 'last':
2169 to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:]
2172 to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:]
2170 else:
2173 elif interactivity == 'all':
2171 to_run_exec, to_run_interactive = [], nodelist
2174 to_run_exec, to_run_interactive = [], nodelist
2175 else:
2176 raise ValueError("Interactivity was %r" % interactivity)
2172
2177
2173 exec_count = self.execution_count
2178 exec_count = self.execution_count
2174 if to_run_exec:
2179 if to_run_exec:
General Comments 0
You need to be logged in to leave comments. Login now