##// END OF EJS Templates
Merge pull request #2868 from takluyver/import-performance...
Merge pull request #2868 from takluyver/import-performance Import performance Defer various imports for a small reduction in startup time. IPython.lib.__init__ previously loaded IPython.lib.inputhook to export some of its functions. This meant that importing anything from IPython.lib also loaded inputhook. For now, I've just removed that import, but that is an API change, because the functions are no longer accessible as e.g. IPython.lib.enable_qt4 Added a note about the API change. Timing command, borrowed from Openoffice to simulate cold start: $ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches; time ipython3 -c pass Results with this branch: 7.68, 7.64, 7.35, 7.38 s 'real' Results with master: 8.17, 8.04, 7.81, 7.77

File last commit:

r5882:fd2691c8
r9459:ff3032f2 merge
Show More
pyfile.py
23 lines | 840 B | text/x-python | PythonLexer
Thomas Kluyver
Find .py files for verbose tracebacks, rather than trying to tokenize .pyc files.
r5851 """Utilities for working with Python source files.
Exposes various functions from recent Python standard libraries, along with
equivalents for older Python versions.
"""
import os.path
try: # Python 3.2
from imp import source_from_cache, cache_from_source
except ImportError:
# Python <= 3.1: .pyc files go next to .py
def source_from_cache(path):
basename, ext = os.path.splitext(path)
Thomas
Fix syntax for Python 2.6 - no set literals.
r5882 if ext not in ('.pyc', '.pyo'):
Thomas Kluyver
Find .py files for verbose tracebacks, rather than trying to tokenize .pyc files.
r5851 raise ValueError('Not a cached Python file extension', ext)
# Should we look for .pyw files?
return basename + '.py'
def cache_from_source(path, debug_override=None):
if debug_override is None:
debug_override = __debug__
basename, ext = os.path.splitext(path)
return basename + '.pyc' if debug_override else '.pyo'