##// END OF EJS Templates
Find .py files for verbose tracebacks, rather than trying to tokenize .pyc files.
Thomas Kluyver -
Show More
@@ -0,0 +1,23 b''
1 """Utilities for working with Python source files.
2
3 Exposes various functions from recent Python standard libraries, along with
4 equivalents for older Python versions.
5 """
6 import os.path
7
8 try: # Python 3.2
9 from imp import source_from_cache, cache_from_source
10 except ImportError:
11 # Python <= 3.1: .pyc files go next to .py
12 def source_from_cache(path):
13 basename, ext = os.path.splitext(path)
14 if ext not in {'.pyc', '.pyo'}:
15 raise ValueError('Not a cached Python file extension', ext)
16 # Should we look for .pyw files?
17 return basename + '.py'
18
19 def cache_from_source(path, debug_override=None):
20 if debug_override is None:
21 debug_override = __debug__
22 basename, ext = os.path.splitext(path)
23 return basename + '.pyc' if debug_override else '.pyo'
@@ -100,6 +100,7 b' from IPython.core.excolors import exception_colors'
100 100 from IPython.utils import PyColorize
101 101 from IPython.utils import io
102 102 from IPython.utils import py3compat
103 from IPython.utils import pyfile
103 104 from IPython.utils.data import uniq_stable
104 105 from IPython.utils.warn import info, error
105 106
@@ -873,6 +874,8 b' class VerboseTB(TBTools):'
873 874 tokeneater.name_cont = False
874 875
875 876 def linereader(file=file, lnum=[lnum], getline=linecache.getline):
877 if file.endswith(('.pyc','.pyo')):
878 file = pyfile.source_from_cache(file)
876 879 line = getline(file, lnum[0])
877 880 lnum[0] += 1
878 881 return line
General Comments 0
You need to be logged in to leave comments. Login now