From 8c591d85500247e411bfe8fd3968003768eceabb Mon Sep 17 00:00:00 2001 From: Mike Roberts <2947595+m-roberts@users.noreply.github.com> Date: Mon, 19 Oct 2020 15:13:26 +0100 Subject: [PATCH] Replace imp with importlib --- py2deb/hooks.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/py2deb/hooks.py b/py2deb/hooks.py index c6455b8..2726dfa 100644 --- a/py2deb/hooks.py +++ b/py2deb/hooks.py @@ -34,7 +34,7 @@ # Standard library modules. import errno -import imp +import importlib import json import logging import os @@ -42,7 +42,7 @@ import subprocess # Detect whether the Python implementation we're running on supports PEP 3147. -HAS_PEP_3147 = hasattr(imp, 'get_tag') +HAS_PEP_3147 = hasattr(importlib, 'sys.implementation.cache_tag') # Initialize a logger. logger = logging.getLogger('py2deb.hooks') @@ -228,7 +228,7 @@ def find_bytecode_files(python_file): :returns: A generator of pathnames (strings). Starting from Python 3.2 byte code files are written according to `PEP - 3147`_ which also defines :func:`imp.cache_from_source()` to locate + 3147`_ which also defines :func:`importlib.util.cache_from_source()` to locate (optimized) byte code files. When this function is available it is used, when it's not available the corresponding ``*.pyc`` and/or ``*.pyo`` files are located manually by :func:`find_bytecode_files()`. @@ -236,10 +236,10 @@ def find_bytecode_files(python_file): .. _PEP 3147: https://www.python.org/dev/peps/pep-3147/ """ if HAS_PEP_3147: - bytecode_file = imp.cache_from_source(python_file, True) + bytecode_file = importlib.util.cache_from_source(python_file, True) if os.path.isfile(bytecode_file): yield bytecode_file - optimized_bytecode_file = imp.cache_from_source(python_file, False) + optimized_bytecode_file = importlib.util.cache_from_source(python_file, False) if os.path.isfile(optimized_bytecode_file): yield optimized_bytecode_file else: