Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace imp with importlib #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions py2deb/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

# Standard library modules.
import errno
import imp
import importlib
import json
import logging
import os
import py_compile
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')
Expand Down Expand Up @@ -228,18 +228,18 @@ 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()`.

.. _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:
Expand Down