mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
Issue #18194: Introduce importlib.util.cache_from_source() and
source_from_cache(), finishing the work introduced in changset 4134:9cacdb9d0c59.
This commit is contained in:
parent
589c4fffd2
commit
a38e81428a
2 changed files with 37 additions and 2 deletions
35
Lib/imp.py
35
Lib/imp.py
|
@ -16,8 +16,7 @@ except ModuleNotFoundError:
|
||||||
# Platform doesn't support dynamic loading.
|
# Platform doesn't support dynamic loading.
|
||||||
load_dynamic = None
|
load_dynamic = None
|
||||||
|
|
||||||
from importlib._bootstrap import (cache_from_source, source_from_cache,
|
from importlib._bootstrap import SourcelessFileLoader, _ERR_MSG
|
||||||
SourcelessFileLoader, _ERR_MSG)
|
|
||||||
|
|
||||||
from importlib import machinery
|
from importlib import machinery
|
||||||
from importlib import util
|
from importlib import util
|
||||||
|
@ -66,6 +65,38 @@ def get_tag():
|
||||||
return sys.implementation.cache_tag
|
return sys.implementation.cache_tag
|
||||||
|
|
||||||
|
|
||||||
|
def cache_from_source(path, debug_override=None):
|
||||||
|
"""**DEPRECATED**
|
||||||
|
|
||||||
|
Given the path to a .py file, return the path to its .pyc/.pyo file.
|
||||||
|
|
||||||
|
The .py file does not need to exist; this simply returns the path to the
|
||||||
|
.pyc/.pyo file calculated as if the .py file were imported. The extension
|
||||||
|
will be .pyc unless sys.flags.optimize is non-zero, then it will be .pyo.
|
||||||
|
|
||||||
|
If debug_override is not None, then it must be a boolean and is used in
|
||||||
|
place of sys.flags.optimize.
|
||||||
|
|
||||||
|
If sys.implementation.cache_tag is None then NotImplementedError is raised.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return util.cache_from_source(path, debug_override)
|
||||||
|
|
||||||
|
|
||||||
|
def source_from_cache(path):
|
||||||
|
"""**DEPRECATED**
|
||||||
|
|
||||||
|
Given the path to a .pyc./.pyo file, return the path to its .py file.
|
||||||
|
|
||||||
|
The .pyc/.pyo file does not need to exist; this simply returns the path to
|
||||||
|
the .py file calculated to correspond to the .pyc/.pyo file. If path does
|
||||||
|
not conform to PEP 3147 format, ValueError will be raised. If
|
||||||
|
sys.implementation.cache_tag is None then NotImplementedError is raised.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return util.source_from_cache(path)
|
||||||
|
|
||||||
|
|
||||||
def get_suffixes():
|
def get_suffixes():
|
||||||
warnings.warn('imp.get_suffixes() is deprecated; use the constants '
|
warnings.warn('imp.get_suffixes() is deprecated; use the constants '
|
||||||
'defined on importlib.machinery instead',
|
'defined on importlib.machinery instead',
|
||||||
|
|
|
@ -123,6 +123,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #18194: Introduce importlib.util.cache_from_source() and
|
||||||
|
source_from_cache() while documenting the equivalent functions in imp as
|
||||||
|
deprecated.
|
||||||
|
|
||||||
- Issue #17907: Document imp.new_module() as deprecated in favour of
|
- Issue #17907: Document imp.new_module() as deprecated in favour of
|
||||||
types.ModuleType.
|
types.ModuleType.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue