mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-98040: Remove just the imp
module (#98573)
This commit is contained in:
parent
79b9db9295
commit
e1f14643dc
24 changed files with 40 additions and 1537 deletions
|
@ -6,7 +6,7 @@ thus has no external changes made to import-related attributes in sys.
|
|||
"""
|
||||
from test.test_importlib import util
|
||||
import decimal
|
||||
import imp
|
||||
from importlib.util import cache_from_source
|
||||
import importlib
|
||||
import importlib.machinery
|
||||
import json
|
||||
|
@ -65,7 +65,7 @@ def source_wo_bytecode(seconds, repeat):
|
|||
name = '__importlib_test_benchmark__'
|
||||
# Clears out sys.modules and puts an entry at the front of sys.path.
|
||||
with util.create_modules(name) as mapping:
|
||||
assert not os.path.exists(imp.cache_from_source(mapping[name]))
|
||||
assert not os.path.exists(cache_from_source(mapping[name]))
|
||||
sys.meta_path.append(importlib.machinery.PathFinder)
|
||||
loader = (importlib.machinery.SourceFileLoader,
|
||||
importlib.machinery.SOURCE_SUFFIXES)
|
||||
|
@ -80,7 +80,7 @@ def _wo_bytecode(module):
|
|||
name = module.__name__
|
||||
def benchmark_wo_bytecode(seconds, repeat):
|
||||
"""Source w/o bytecode: {}"""
|
||||
bytecode_path = imp.cache_from_source(module.__file__)
|
||||
bytecode_path = cache_from_source(module.__file__)
|
||||
if os.path.exists(bytecode_path):
|
||||
os.unlink(bytecode_path)
|
||||
sys.dont_write_bytecode = True
|
||||
|
@ -108,9 +108,9 @@ def source_writing_bytecode(seconds, repeat):
|
|||
sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader))
|
||||
def cleanup():
|
||||
sys.modules.pop(name)
|
||||
os.unlink(imp.cache_from_source(mapping[name]))
|
||||
os.unlink(cache_from_source(mapping[name]))
|
||||
for result in bench(name, cleanup, repeat=repeat, seconds=seconds):
|
||||
assert not os.path.exists(imp.cache_from_source(mapping[name]))
|
||||
assert not os.path.exists(cache_from_source(mapping[name]))
|
||||
yield result
|
||||
|
||||
|
||||
|
@ -121,7 +121,7 @@ def _writing_bytecode(module):
|
|||
assert not sys.dont_write_bytecode
|
||||
def cleanup():
|
||||
sys.modules.pop(name)
|
||||
os.unlink(imp.cache_from_source(module.__file__))
|
||||
os.unlink(cache_from_source(module.__file__))
|
||||
yield from bench(name, cleanup, repeat=repeat, seconds=seconds)
|
||||
|
||||
writing_bytecode_benchmark.__doc__ = (
|
||||
|
@ -141,7 +141,7 @@ def source_using_bytecode(seconds, repeat):
|
|||
importlib.machinery.SOURCE_SUFFIXES)
|
||||
sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader))
|
||||
py_compile.compile(mapping[name])
|
||||
assert os.path.exists(imp.cache_from_source(mapping[name]))
|
||||
assert os.path.exists(cache_from_source(mapping[name]))
|
||||
yield from bench(name, lambda: sys.modules.pop(name), repeat=repeat,
|
||||
seconds=seconds)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue