##// END OF EJS Templates
Consolidate utils.pyfile into utils.openpy
Thomas Kluyver -
Show More
@@ -104,9 +104,9 b' from IPython.core.display_trap import DisplayTrap'
104 104 from IPython.core.excolors import exception_colors
105 105 from IPython.utils import PyColorize
106 106 from IPython.utils import io
107 from IPython.utils import openpy
107 108 from IPython.utils import path as util_path
108 109 from IPython.utils import py3compat
109 from IPython.utils import pyfile
110 110 from IPython.utils import ulinecache
111 111 from IPython.utils.data import uniq_stable
112 112 from IPython.utils.warn import info, error
@@ -837,7 +837,7 b' class VerboseTB(TBTools):'
837 837 continue
838 838 elif file.endswith(('.pyc','.pyo')):
839 839 # Look up the corresponding source file.
840 file = pyfile.source_from_cache(file)
840 file = openpy.source_from_cache(file)
841 841
842 842 def linereader(file=file, lnum=[lnum], getline=ulinecache.getline):
843 843 line = getline(file, lnum[0])
@@ -119,7 +119,7 b' try:'
119 119 except NameError:
120 120 from imp import reload
121 121
122 from IPython.utils import pyfile
122 from IPython.utils import openpy
123 123 from IPython.utils.py3compat import PY3
124 124
125 125 #------------------------------------------------------------------------------
@@ -207,12 +207,12 b' class ModuleReloader(object):'
207 207 path, ext = os.path.splitext(filename)
208 208
209 209 if ext.lower() == '.py':
210 pyc_filename = pyfile.cache_from_source(filename)
210 pyc_filename = openpy.cache_from_source(filename)
211 211 py_filename = filename
212 212 else:
213 213 pyc_filename = filename
214 214 try:
215 py_filename = pyfile.source_from_cache(filename)
215 py_filename = openpy.source_from_cache(filename)
216 216 except ValueError:
217 217 continue
218 218
@@ -8,6 +8,7 b' from __future__ import absolute_import'
8 8
9 9 import io
10 10 from io import TextIOWrapper, BytesIO
11 import os.path
11 12 import re
12 13
13 14 cookie_re = re.compile(ur"coding[:=]\s*([-\w.]+)", re.UNICODE)
@@ -217,3 +218,22 b' def _list_readline(x):'
217 218 def readline():
218 219 return next(x)
219 220 return readline
221
222 # Code for going between .py files and cached .pyc files ----------------------
223
224 try: # Python 3.2, see PEP 3147
225 from imp import source_from_cache, cache_from_source
226 except ImportError:
227 # Python <= 3.1: .pyc files go next to .py
228 def source_from_cache(path):
229 basename, ext = os.path.splitext(path)
230 if ext not in ('.pyc', '.pyo'):
231 raise ValueError('Not a cached Python file extension', ext)
232 # Should we look for .pyw files?
233 return basename + '.py'
234
235 def cache_from_source(path, debug_override=None):
236 if debug_override is None:
237 debug_override = __debug__
238 basename, ext = os.path.splitext(path)
239 return basename + '.pyc' if debug_override else '.pyo'
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now