Skip to content

Commit

Permalink
Merge pull request #626 from odie5533/python312-imp-module
Browse files Browse the repository at this point in the history
WIP Python 3.12 support for removal of imp module
  • Loading branch information
edschofield committed Feb 21, 2024
2 parents 3dc7acc + 1901c1c commit a6222d2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -3,7 +3,7 @@ set -xuo pipefail

DOCKER_IMAGE=jmadler/python-future-builder
# XXX: TODO: Perhaps this version shouldn't be hardcoded
version=0.18.3
version=0.18.4

docker build . -t $DOCKER_IMAGE
docker push $DOCKER_IMAGE:latest
Expand Down
6 changes: 6 additions & 0 deletions docs/whatsnew.rst
Expand Up @@ -3,6 +3,12 @@
What's New
**********

What's new in version 0.18.4 (2023-10-10)
=========================================
This is a minor bug-fix release containing a number of fixes:

- Fix for Python 3.12's removal of the imp module

What's new in version 0.18.3 (2023-01-13)
=========================================
This is a minor bug-fix release containing a number of fixes:
Expand Down
2 changes: 1 addition & 1 deletion src/future/__init__.py
Expand Up @@ -87,7 +87,7 @@
__copyright__ = 'Copyright 2013-2019 Python Charmers Pty Ltd'
__ver_major__ = 0
__ver_minor__ = 18
__ver_patch__ = 3
__ver_patch__ = 4
__ver_sub__ = ''
__version__ = "%d.%d.%d%s" % (__ver_major__, __ver_minor__,
__ver_patch__, __ver_sub__)
11 changes: 7 additions & 4 deletions src/future/backports/test/support.py
Expand Up @@ -28,7 +28,10 @@
# import collections.abc # not present on Py2.7
import re
import subprocess
import imp
try:
from imp import cache_from_source
except ImportError:
from importlib.util import cache_from_source
import time
try:
import sysconfig
Expand Down Expand Up @@ -351,7 +354,7 @@ def make_legacy_pyc(source):
does not need to exist, however the PEP 3147 pyc file must exist.
:return: The file system path to the legacy pyc file.
"""
pyc_file = imp.cache_from_source(source)
pyc_file = cache_from_source(source)
up_one = os.path.dirname(os.path.abspath(source))
legacy_pyc = os.path.join(up_one, source + ('c' if __debug__ else 'o'))
os.rename(pyc_file, legacy_pyc)
Expand All @@ -370,8 +373,8 @@ def forget(modname):
# combinations of PEP 3147 and legacy pyc and pyo files.
unlink(source + 'c')
unlink(source + 'o')
unlink(imp.cache_from_source(source, debug_override=True))
unlink(imp.cache_from_source(source, debug_override=False))
unlink(cache_from_source(source, debug_override=True))
unlink(cache_from_source(source, debug_override=False))

# On some platforms, should not run gui test even if it is allowed
# in `use_resources'.
Expand Down
12 changes: 9 additions & 3 deletions src/future/standard_library/__init__.py
Expand Up @@ -62,7 +62,10 @@

import sys
import logging
import imp
try:
import importlib
except ImportError:
import imp
import contextlib
import types
import copy
Expand Down Expand Up @@ -297,8 +300,11 @@ def _find_and_load_module(self, name, path=None):
flog.debug('What to do here?')

name = bits[0]
module_info = imp.find_module(name, path)
return imp.load_module(name, *module_info)
try:
module_info = imp.find_module(name, path)
return imp.load_module(name, *module_info)
except AttributeError:
return importlib.import_module(name, path)


class hooks(object):
Expand Down
5 changes: 4 additions & 1 deletion src/past/translation/__init__.py
Expand Up @@ -32,7 +32,10 @@
Inspired by and based on ``uprefix`` by Vinay M. Sajip.
"""

import imp
try:
import imp
except ImportError:
import importlib
import logging
import marshal
import os
Expand Down
11 changes: 8 additions & 3 deletions tests/test_future/test_standard_library.py
Expand Up @@ -447,9 +447,14 @@ def test_reload(self):
"""
reload has been moved to the imp module
"""
import imp
imp.reload(imp)
self.assertTrue(True)
try:
import imp
imp.reload(imp)
self.assertTrue(True)
except ImportError:
import importlib
importlib.reload(importlib)
self.assertTrue(True)

def test_install_aliases(self):
"""
Expand Down

0 comments on commit a6222d2

Please sign in to comment.