From 84ad7d21ac1957370e4d86431ce9f93440532a6e 2012-05-27 03:54:09 From: Fernando Perez Date: 2012-05-27 03:54:09 Subject: [PATCH] Rename a few methods as per review, also complete some docstrings. --- diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index 68b5fc3..c0183d1 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -775,7 +775,7 @@ class IPythonInputSplitter(InputSplitter): # get it all working, as right now changing the return API of our # methods would require major refactoring. self.cell_magic_parts = [body] - tpl = 'get_ipython()._cell_magic(%r, %r)' + tpl = 'get_ipython()._run_cached_cell_magic(%r, %r)' tlines = tpl % (magic_name, line) self._store(tlines) self._store(lines, self._buffer_raw, 'source_raw') diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index a58e0a8..d062b75 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2021,7 +2021,7 @@ class InteractiveShell(SingletonConfigurable): # even need a centralize colors management object. self.magic('colors %s' % self.colors) - def line_magic(self, magic_name, line): + def run_line_magic(self, magic_name, line): """Execute the given line magic. Parameters @@ -2054,8 +2054,19 @@ class InteractiveShell(SingletonConfigurable): result = fn(*args) return result - def cell_magic(self, magic_name, line, cell): + def run_cell_magic(self, magic_name, line, cell): """Execute the given cell magic. + + Parameters + ---------- + magic_name : str + Name of the desired magic function, without '%' prefix. + + line : str + The rest of the first input line as a single string. + + cell : str + The body of the cell as a (possibly multiline) string. """ fn = self.find_cell_magic(magic_name) if fn is None: @@ -2093,7 +2104,7 @@ class InteractiveShell(SingletonConfigurable): return self.magics_manager.magics[magic_kind].get(magic_name) def magic(self, arg_s): - """DEPRECATED. Use line_magic() instead. + """DEPRECATED. Use run_line_magic() instead. Call a magic function by name. @@ -2114,7 +2125,7 @@ class InteractiveShell(SingletonConfigurable): # TODO: should we issue a loud deprecation warning here? magic_name, _, magic_arg_s = arg_s.partition(' ') magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) - return self.line_magic(magic_name, magic_arg_s) + return self.run_line_magic(magic_name, magic_arg_s) #------------------------------------------------------------------------- # Things related to macros @@ -2484,12 +2495,12 @@ class InteractiveShell(SingletonConfigurable): self.showtraceback() warn('Unknown failure executing module: <%s>' % mod_name) - def _cell_magic(self, magic_name, line): + def _run_cached_cell_magic(self, magic_name, line): """Special method to call a cell magic with the data stored in self. """ cell = self._current_cell_magic_body self._current_cell_magic_body = None - return self.cell_magic(magic_name, line, cell) + return self.run_cell_magic(magic_name, line, cell) def run_cell(self, raw_cell, store_history=False, silent=False): """Run a complete IPython cell. diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index 2eda04c..20054d2 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -759,7 +759,7 @@ class CellModeCellMagics(unittest.TestCase): sp.push(src) nt.assert_equal(sp.cell_magic_parts, ['body\n']) out = sp.source - ref = u"get_ipython()._cell_magic(u'cellm', u'line')\n" + ref = u"get_ipython()._run_cached_cell_magic(u'cellm', u'line')\n" nt.assert_equal(out, ref) def test_incremental(self): @@ -793,7 +793,7 @@ class LineModeCellMagics(unittest.TestCase): sp.push(src) nt.assert_equal(sp.cell_magic_parts, ['body\n']) out = sp.source - ref = u"get_ipython()._cell_magic(u'cellm', u'line')\n" + ref = u"get_ipython()._run_cached_cell_magic(u'cellm', u'line')\n" nt.assert_equal(out, ref) def test_incremental(self): diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 0b53133..296d895 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -496,7 +496,7 @@ class CellMagicTestCase(TestCase): def check_ident(self, magic): # Manually called, we get the result - out = _ip.cell_magic(magic, 'a', 'b') + out = _ip.run_cell_magic(magic, 'a', 'b') nt.assert_equals(out, ('a','b')) # Via run_cell, it goes into the user's namespace via displayhook _ip.run_cell('%%' + magic +' c\nd')