Fix deprecation warning on using imp

In build log fixes the following warning:
/builddir/build/SOURCES/check-pyc-and-pyo-timestamps.py:3: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
This commit is contained in:
Iryna Shcherbina 2018-02-13 13:49:21 +01:00
parent daeec838fe
commit 56c7fd9871

View File

@ -1,6 +1,6 @@
"""Checks if all *.pyc and *.pyo files have later mtime than their *.py files."""
import imp
import importlib.util
import os
import sys
@ -37,16 +37,18 @@ not_compiled = [
]
failed = 0
def bytecode_expected(source):
for f in not_compiled:
if source.endswith(f):
return False
return True
compiled = filter(lambda f: bytecode_expected(f), sys.argv[1:])
for f in compiled:
# check both pyo and pyc
to_check = map(lambda b: imp.cache_from_source(f, b), (True, False))
to_check = map(lambda b: importlib.util.cache_from_source(f, b), (True, False))
f_mtime = os.path.getmtime(f)
for c in to_check:
c_mtime = os.path.getmtime(c)