diff --git a/NEWS.rst b/NEWS.rst index dbfc2227..adc804c7 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,3 +1,9 @@ +v6.1.3 +====== + +No significant changes. + + v6.1.2 ====== diff --git a/importlib_resources/tests/_compat.py b/importlib_resources/tests/_compat.py deleted file mode 100644 index e7bf06dd..00000000 --- a/importlib_resources/tests/_compat.py +++ /dev/null @@ -1,32 +0,0 @@ -import os - - -try: - from test.support import import_helper # type: ignore -except ImportError: - # Python 3.9 and earlier - class import_helper: # type: ignore - from test.support import ( - modules_setup, - modules_cleanup, - DirsOnSysPath, - CleanImport, - ) - - -try: - from test.support import os_helper # type: ignore -except ImportError: - # Python 3.9 compat - class os_helper: # type:ignore - from test.support import temp_dir - - -try: - # Python 3.10 - from test.support.os_helper import unlink -except ImportError: - from test.support import unlink as _unlink - - def unlink(target): - return _unlink(os.fspath(target)) diff --git a/importlib_resources/tests/compat/__init__.py b/importlib_resources/tests/compat/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/importlib_resources/tests/compat/py312.py b/importlib_resources/tests/compat/py312.py new file mode 100644 index 00000000..ea9a58ba --- /dev/null +++ b/importlib_resources/tests/compat/py312.py @@ -0,0 +1,18 @@ +import contextlib + +from .py39 import import_helper + + +@contextlib.contextmanager +def isolated_modules(): + """ + Save modules on entry and cleanup on exit. + """ + (saved,) = import_helper.modules_setup() + try: + yield + finally: + import_helper.modules_cleanup(saved) + + +vars(import_helper).setdefault('isolated_modules', isolated_modules) diff --git a/importlib_resources/tests/compat/py39.py b/importlib_resources/tests/compat/py39.py new file mode 100644 index 00000000..81ec9aac --- /dev/null +++ b/importlib_resources/tests/compat/py39.py @@ -0,0 +1,30 @@ +""" +Backward-compatability shims to support Python 3.9 and earlier. +""" + +import types + +from jaraco.collections import Projection + + +def from_test_support(*names): + """ + Return a SimpleNamespace of names from test.support. + """ + import test.support + + return types.SimpleNamespace(**Projection(names, vars(test.support))) + + +try: + from test.support import import_helper # type: ignore +except ImportError: + import_helper = from_test_support( + 'modules_setup', 'modules_cleanup', 'DirsOnSysPath' + ) + + +try: + from test.support import os_helper # type: ignore +except ImportError: + os_helper = from_test_support('temp_dir') diff --git a/importlib_resources/tests/test_custom.py b/importlib_resources/tests/test_custom.py index 35336f8f..86c65676 100644 --- a/importlib_resources/tests/test_custom.py +++ b/importlib_resources/tests/test_custom.py @@ -6,7 +6,7 @@ from .. import abc from ..abc import TraversableResources, ResourceReader from . import util -from ._compat import os_helper +from .compat.py39 import os_helper class SimpleLoader: diff --git a/importlib_resources/tests/test_files.py b/importlib_resources/tests/test_files.py index 51ecc896..9e45f701 100644 --- a/importlib_resources/tests/test_files.py +++ b/importlib_resources/tests/test_files.py @@ -9,7 +9,8 @@ from . import data01 from . import util from . import _path -from ._compat import os_helper, import_helper +from .compat.py39 import os_helper +from .compat.py312 import import_helper @contextlib.contextmanager @@ -68,7 +69,7 @@ def setUp(self): self.addCleanup(self.fixtures.close) self.site_dir = self.fixtures.enter_context(os_helper.temp_dir()) self.fixtures.enter_context(import_helper.DirsOnSysPath(self.site_dir)) - self.fixtures.enter_context(import_helper.CleanImport()) + self.fixtures.enter_context(import_helper.isolated_modules()) class ModulesFilesTests(SiteDir, unittest.TestCase): diff --git a/importlib_resources/tests/util.py b/importlib_resources/tests/util.py index 066f4113..fb827d2f 100644 --- a/importlib_resources/tests/util.py +++ b/importlib_resources/tests/util.py @@ -8,7 +8,7 @@ from . import data01 from ..abc import ResourceReader -from ._compat import import_helper, os_helper +from .compat.py39 import import_helper, os_helper from . import zip as zip_ @@ -148,8 +148,7 @@ def setUp(self): self.fixtures = contextlib.ExitStack() self.addCleanup(self.fixtures.close) - modules = import_helper.modules_setup() - self.addCleanup(import_helper.modules_cleanup, *modules) + self.fixtures.enter_context(import_helper.isolated_modules()) temp_dir = self.fixtures.enter_context(os_helper.temp_dir()) modules = pathlib.Path(temp_dir) / 'zipped modules.zip' diff --git a/setup.cfg b/setup.cfg index 017cdc48..feef5904 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,6 +34,7 @@ testing = # local zipp >= 3.17 + jaraco.collections docs = # upstream