diff options
author | Brett Cannon <brett@python.org> | 2012-05-11 16:58:42 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-05-11 16:58:42 (GMT) |
commit | cb66eb0deca1d5cd232f97c76a215ecaab958d30 (patch) | |
tree | f38497a2e61cf8be225c4e7394961703cea5f66c /Lib/importlib/_bootstrap.py | |
parent | 810c64df8f8bf70a2cb7a626004185616cb88213 (diff) | |
download | cpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.zip cpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.tar.gz cpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.tar.bz2 |
Issue #13959: Deprecate imp.get_suffixes() for new attributes on
importlib.machinery that provide the suffix details for import.
The attributes were not put on imp so as to compartmentalize
everything importlib needs for setting up imports in
importlib.machinery.
This also led to an indirect deprecation of inspect.getmoduleinfo() as
it directly returned imp.get_suffix's returned tuple which no longer
makes sense.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 9952b06..ce23043 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -163,11 +163,14 @@ def new_module(name): _PYCACHE = '__pycache__' -_SOURCE_SUFFIXES = ['.py'] # _setup() adds .pyw as needed. +SOURCE_SUFFIXES = ['.py'] # _setup() adds .pyw as needed. -_DEBUG_BYTECODE_SUFFIX = '.pyc' -_OPT_BYTECODE_SUFFIX = '.pyo' -_BYTECODE_SUFFIX = _DEBUG_BYTECODE_SUFFIX if __debug__ else _OPT_BYTECODE_SUFFIX +DEBUG_BYTECODE_SUFFIXES = ['.pyc'] +OPTIMIZED_BYTECODE_SUFFIXES = ['.pyo'] +if __debug__: + BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES +else: + BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES def cache_from_source(path, debug_override=None): """Given the path to a .py file, return the path to its .pyc/.pyo file. @@ -181,10 +184,13 @@ def cache_from_source(path, debug_override=None): """ debug = __debug__ if debug_override is None else debug_override - suffix = _DEBUG_BYTECODE_SUFFIX if debug else _OPT_BYTECODE_SUFFIX + if debug: + suffixes = DEBUG_BYTECODE_SUFFIXES + else: + suffixes = OPTIMIZED_BYTECODE_SUFFIXES head, tail = _path_split(path) base_filename, sep, _ = tail.partition('.') - filename = ''.join([base_filename, sep, _TAG, suffix]) + filename = ''.join([base_filename, sep, _TAG, suffixes[0]]) return _path_join(head, _PYCACHE, filename) @@ -1147,15 +1153,15 @@ def _setup(sys_module, _imp_module): setattr(self_module, '_MAGIC_NUMBER', _imp_module.get_magic()) setattr(self_module, '_TAG', _imp.get_tag()) if builtin_os == 'nt': - _SOURCE_SUFFIXES.append('.pyw') + SOURCE_SUFFIXES.append('.pyw') def _install(sys_module, _imp_module): """Install importlib as the implementation of import.""" _setup(sys_module, _imp_module) extensions = ExtensionFileLoader, _imp_module.extension_suffixes(), False - source = SourceFileLoader, _SOURCE_SUFFIXES, True - bytecode = SourcelessFileLoader, [_BYTECODE_SUFFIX], True + source = SourceFileLoader, SOURCE_SUFFIXES, True + bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES, True supported_loaders = [extensions, source, bytecode] sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)]) sys.meta_path.extend([BuiltinImporter, FrozenImporter, PathFinder]) |