In [1]:
%install_ext https://raw.github.com/rocky/ipython-trepan/master/trepanmagic.py


Installed trepanmagic.py. To use it, type:
  %load_ext trepanmagic

In [2]:
%load_ext trepanmagic


trepanmagic.py loaded

In [3]:
import os

In [4]:
%trepan_eval os.path.join('/tmp', 'foo', 'bar.py')


(/tmp/eval_stringpv63vwvy.py:1 remapped <string>): <module>
-> 1 os.path.join('/tmp', 'foo', 'bar.py')
(trepan3k) s
(/home/rocky/.pyenv/versions/3.4.1/lib/python3.4/posixpath.py:71): join
-> 71 def join(a, *p):
(trepan3k) backtrace
->0 join(a='/tmp', *p=('foo', 'bar.py'))
     called from file '/home/rocky/.pyenv/versions/3.4.1/lib/python3.4/posixpath.py' at line 71
##1 <module> eval()
     in exec <string> at line 1
(trepan3k) list
 66    	
 67    	# Join pathnames.
 68    	# Ignore the previous parts if a part is absolute.
 69    	# Insert a '/' unless the first part is empty or already ends in '/'.
 70    	
 71  ->	def join(a, *p):
 72    	    """Join two or more pathname components, inserting '/' as needed.
 73    	    If any component is an absolute path, all previous path components
 74    	    will be discarded.  An empty last part will result in a path that
 75    	    ends with a separator."""
(trepan3k) set autolist on
(trepan3k) step
(/home/rocky/.pyenv/versions/3.4.1/lib/python3.4/posixpath.py:76): join
-- 76     sep = _get_sep(a)
 71    	def join(a, *p):
 72    	    """Join two or more pathname components, inserting '/' as needed.
 73    	    If any component is an absolute path, all previous path components
 74    	    will be discarded.  An empty last part will result in a path that
 75    	    ends with a separator."""
 76  ->	    sep = _get_sep(a)
 77    	    path = a
 78    	    try:
 79    	        for b in p:
 80    	            if b.startswith(sep):
(trepan3k) step
(/home/rocky/.pyenv/versions/3.4.1/lib/python3.4/posixpath.py:38): _get_sep
-> 38 def _get_sep(path):
 33    	pathsep = ':'
 34    	defpath = ':/bin:/usr/bin'
 35    	altsep = None
 36    	devnull = '/dev/null'
 37    	
 38  ->	def _get_sep(path):
 39    	    if isinstance(path, bytes):
 40    	        return b'/'
 41    	    else:
 42    	        return '/'
(trepan3k) step
(/home/rocky/.pyenv/versions/3.4.1/lib/python3.4/posixpath.py:39): _get_sep
-- 39     if isinstance(path, bytes):
 34    	defpath = ':/bin:/usr/bin'
 35    	altsep = None
 36    	devnull = '/dev/null'
 37    	
 38    	def _get_sep(path):
 39  ->	    if isinstance(path, bytes):
 40    	        return b'/'
 41    	    else:
 42    	        return '/'
 43    	
(trepan3k) continue
Out[4]:
'/tmp/foo/bar.py'

In [5]:
%trepan_eval 1+2 # can eval expressions, but this is stupid


(/tmp/eval_stringor5m82_u.py:1 remapped <string>): <module>
-> 1 1+2 # can eval expressions, but this is stupid
(trepan3k) c
Out[5]:
3

In [6]:
%trepan_eval 3+4


(/tmp/eval_stringju9lkx9w.py:1 remapped <string>): <module>
-> 1 3+4
(trepan3k) backtrace
->0 <module> eval()
     in exec <string> at line 1
(trepan3k) quit # don't continue evaluation; return to ipython

In [7]:
quit