Skip to content

Commit

Permalink
Merge pull request #632 from nsoranzo/python312-imp-module_past
Browse files Browse the repository at this point in the history
Python 3.12 support
  • Loading branch information
edschofield authored Feb 21, 2024
2 parents a6222d2 + 9ef05b3 commit ba1cc50
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 220 deletions.
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved",
"License :: OSI Approved :: MIT License",
"Development Status :: 4 - Beta",
Expand Down
35 changes: 0 additions & 35 deletions src/future/backports/test/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
# import collections.abc # not present on Py2.7
import re
import subprocess
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 @@ -344,37 +340,6 @@ def rmtree(path):
if error.errno != errno.ENOENT:
raise

def make_legacy_pyc(source):
"""Move a PEP 3147 pyc/pyo file to its legacy pyc/pyo location.
The choice of .pyc or .pyo extension is done based on the __debug__ flag
value.
:param source: The file system path to the source file. The source file
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 = 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)
return legacy_pyc

def forget(modname):
"""'Forget' a module was ever imported.
This removes the module from sys.modules and deletes any PEP 3147 or
legacy .pyc and .pyo files.
"""
unload(modname)
for dirname in sys.path:
source = os.path.join(dirname, modname + '.py')
# It doesn't matter if they exist or not, unlink all possible
# combinations of PEP 3147 and legacy pyc and pyo files.
unlink(source + 'c')
unlink(source + 'o')
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
9 changes: 9 additions & 0 deletions src/future/moves/test/support.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from __future__ import absolute_import

import sys

from future.standard_library import suspend_hooks
from future.utils import PY3

if PY3:
from test.support import *
if sys.version_info[:2] >= (3, 10):
from test.support.os_helper import (
EnvironmentVarGuard,
TESTFN,
)
from test.support.warnings_helper import check_warnings
else:
__future_module__ = True
with suspend_hooks():
Expand Down
15 changes: 5 additions & 10 deletions src/future/standard_library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@

import sys
import logging
try:
import importlib
except ImportError:
import imp
import contextlib
import types
import copy
import os

Expand All @@ -82,6 +77,9 @@

from future.utils import PY2, PY3

if PY2:
import imp

# The modules that are defined under the same names on Py3 but with
# different contents in a significant way (e.g. submodules) are:
# pickle (fast one)
Expand Down Expand Up @@ -300,11 +298,8 @@ def _find_and_load_module(self, name, path=None):
flog.debug('What to do here?')

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


class hooks(object):
Expand Down
Loading

0 comments on commit ba1cc50

Please sign in to comment.