Skip to content

Commit

Permalink
Remove runlines method and calls to it.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Apr 12, 2011
1 parent bb38481 commit 07aea6a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 53 deletions.
46 changes: 0 additions & 46 deletions IPython/core/interactiveshell.py
Expand Up @@ -2224,52 +2224,6 @@ def run_ast_nodes(self, nodelist, cell_name, interactivity='last_expr'):

return False


# PENDING REMOVAL: this method is slated for deletion, once our new
# input logic has been 100% moved to frontends and is stable.
def runlines(self, lines, clean=False):
"""Run a string of one or more lines of source.
This method is capable of running a string containing multiple source
lines, as if they had been entered at the IPython prompt. Since it
exposes IPython's processing machinery, the given strings can contain
magic calls (%magic), special shell access (!cmd), etc.
"""

if not isinstance(lines, (list, tuple)):
lines = lines.splitlines()

if clean:
lines = self._cleanup_ipy_script(lines)

# We must start with a clean buffer, in case this is run from an
# interactive IPython session (via a magic, for example).
self.reset_buffer()

# Since we will prefilter all lines, store the user's raw input too
# before we apply any transformations
self.buffer_raw[:] = [ l+'\n' for l in lines]

more = False
prefilter_lines = self.prefilter_manager.prefilter_lines
with nested(self.builtin_trap, self.display_trap):
for line in lines:
# skip blank lines so we don't mess up the prompt counter, but
# do NOT skip even a blank line if we are in a code block (more
# is true)

if line or more:
more = self.push_line(prefilter_lines(line, more))
# IPython's run_source returns None if there was an error
# compiling the code. This allows us to stop processing
# right away, so the user gets the error message at the
# right place.
if more is None:
break
# final newline in case the input didn't have it, so that the code
# actually does get executed
if more:
self.push_line('\n')

def run_source(self, source, filename=None, symbol='single'):
"""Compile and run some source in the interpreter.
Expand Down
8 changes: 4 additions & 4 deletions IPython/core/tests/test_iplib.py
Expand Up @@ -237,10 +237,10 @@ def doctest_tb_sysexit():
"""


def test_runlines():
def test_run_cell():
import textwrap
ip.runlines(['a = 10', 'a+=1'])
ip.runlines('assert a == 11\nassert 1')
ip.run_cell('a = 10\na+=1')
ip.run_cell('assert a == 11\nassert 1')

nt.assert_equals(ip.user_ns['a'], 11)
complex = textwrap.dedent("""
Expand All @@ -260,7 +260,7 @@ def test_runlines():
""")
# Simply verifies that this kind of input is run
ip.runlines(complex)
ip.run_cell(complex)


def test_db():
Expand Down
4 changes: 2 additions & 2 deletions IPython/core/tests/test_run.py
Expand Up @@ -151,7 +151,7 @@ def test_simpledef(self):
"def f(): return foo()")
self.mktmp(src)
_ip.magic('run %s' % self.fname)
_ip.runlines('t = isinstance(f(), foo)')
_ip.run_cell('t = isinstance(f(), foo)')
nt.assert_true(_ip.user_ns['t'])

# We have to skip these in win32 because getoutputerr() crashes,
Expand Down Expand Up @@ -188,7 +188,7 @@ class secondtmp(tt.TempFileMixin): pass
" print i;break\n" % empty.fname)
self.mktmp(src)
_ip.magic('run %s' % self.fname)
_ip.runlines('ip == get_ipython()')
_ip.run_cell('ip == get_ipython()')
tt.assert_equals(_ip.user_ns['i'], 5)

@dec.skip_win32
Expand Down
2 changes: 1 addition & 1 deletion IPython/zmq/ipkernel.py
Expand Up @@ -241,7 +241,7 @@ def execute_request(self, ident, parent):
except:
status = u'error'
# FIXME: this code right now isn't being used yet by default,
# because the runlines() call above directly fires off exception
# because the run_cell() call above directly fires off exception
# reporting. This code, therefore, is only active in the scenario
# where runlines itself has an unhandled exception. We need to
# uniformize this, for all exception construction to come from a
Expand Down

0 comments on commit 07aea6a

Please sign in to comment.