mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Issue #17177: stop using imp for compileall.
This commit is contained in:
parent
0b16b0d3f0
commit
7822e123c4
2 changed files with 29 additions and 32 deletions
|
|
@ -13,7 +13,7 @@ See module py_compile for details of the actual byte-compilation.
|
|||
import os
|
||||
import sys
|
||||
import errno
|
||||
import imp
|
||||
import importlib.util
|
||||
import py_compile
|
||||
import struct
|
||||
|
||||
|
|
@ -91,17 +91,18 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=False,
|
|||
cfile = fullname + ('c' if __debug__ else 'o')
|
||||
else:
|
||||
if optimize >= 0:
|
||||
cfile = imp.cache_from_source(fullname,
|
||||
debug_override=not optimize)
|
||||
cfile = importlib.util.cache_from_source(
|
||||
fullname, debug_override=not optimize)
|
||||
else:
|
||||
cfile = imp.cache_from_source(fullname)
|
||||
cfile = importlib.util.cache_from_source(fullname)
|
||||
cache_dir = os.path.dirname(cfile)
|
||||
head, tail = name[:-3], name[-3:]
|
||||
if tail == '.py':
|
||||
if not force:
|
||||
try:
|
||||
mtime = int(os.stat(fullname).st_mtime)
|
||||
expect = struct.pack('<4sl', imp.get_magic(), mtime)
|
||||
expect = struct.pack('<4sl', importlib.util.MAGIC_NUMBER,
|
||||
mtime)
|
||||
with open(cfile, 'rb') as chandle:
|
||||
actual = chandle.read(8)
|
||||
if expect == actual:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue