Skip to content

Commit

Permalink
Change integer options to string options for interactivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Apr 7, 2011
1 parent 4863c51 commit beafaea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions IPython/core/compilerop.py
Expand Up @@ -7,6 +7,7 @@
------- -------
* Robert Kern * Robert Kern
* Fernando Perez * Fernando Perez
* Thomas Kluyver
""" """


# Note: though it might be more natural to name this module 'compiler', that # Note: though it might be more natural to name this module 'compiler', that
Expand Down
25 changes: 15 additions & 10 deletions IPython/core/interactiveshell.py
Expand Up @@ -2134,9 +2134,9 @@ def run_cell(self, cell, store_history=True):
self.execution_count += 1 self.execution_count += 1
return None return None


interactivity = 1 # Last node to be run interactive interactivity = 'last' # Last node to be run interactive
if len(cell.splitlines()) == 1: if len(cell.splitlines()) == 1:
interactivity = 2 # Single line; run fully interactive interactivity = 'all' # Single line; run fully interactive


self.run_ast_nodes(code_ast.body, cell_name, interactivity) self.run_ast_nodes(code_ast.body, cell_name, interactivity)


Expand All @@ -2147,28 +2147,33 @@ def run_cell(self, cell, store_history=True):
# Each cell is a *single* input, regardless of how many lines it has # Each cell is a *single* input, regardless of how many lines it has
self.execution_count += 1 self.execution_count += 1


def run_ast_nodes(self, nodelist, cell_name, interactivity=1): def run_ast_nodes(self, nodelist, cell_name, interactivity='last'):
"""Run a sequence of AST nodes. The execution mode depends on the """Run a sequence of AST nodes. The execution mode depends on the
interactivity parameter. interactivity parameter.
Parameters Parameters
---------- ----------
nodelist : list nodelist : list
A sequence of AST nodes to run. A sequence of AST nodes to run.
interactivity : int cell_name : str
At 0, all nodes are run in 'exec' mode. At '1', the last node alone Will be passed to the compiler as the filename of the cell. Typically
is run in interactive mode (so the result of an expression is shown). the value returned by ip.compile.cache(cell).
At 2, all nodes are run in interactive mode. interactivity : str
'all', 'last' or 'none', specifying which nodes should be run
interactively (displaying output from expressions). Other values for
this parameter will raise a ValueError.
""" """
if not nodelist: if not nodelist:
return return


if interactivity == 0: if interactivity == 'none':
to_run_exec, to_run_interactive = nodelist, [] to_run_exec, to_run_interactive = nodelist, []
elif interactivity == 1: elif interactivity == 'last':
to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:] to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:]
else: elif interactivity == 'all':
to_run_exec, to_run_interactive = [], nodelist to_run_exec, to_run_interactive = [], nodelist
else:
raise ValueError("Interactivity was %r" % interactivity)


exec_count = self.execution_count exec_count = self.execution_count
if to_run_exec: if to_run_exec:
Expand Down

0 comments on commit beafaea

Please sign in to comment.