diff -Nru importlib-resources-5.1.0/CHANGES.rst importlib-resources-5.1.2/CHANGES.rst --- importlib-resources-5.1.0/CHANGES.rst 2021-01-19 03:22:15.000000000 +0000 +++ importlib-resources-5.1.2/CHANGES.rst 2021-03-04 18:46:52.000000000 +0000 @@ -1,3 +1,34 @@ +v5.1.2 +====== + +* Re-release with changes from 5.0.4. + +v5.0.4 +====== + +* Fixed non-hermetic test in test_reader, revealed by + GH-24670. + +v5.1.1 +====== + +* Re-release with changes from 5.0.3. + +v5.0.3 +====== + +* Simplified DegenerateFiles.Path. + +v5.0.2 +====== + +* #214: Added ``_adapters`` module to ensure that degenerate + ``files`` behavior can be made available for legacy loaders + whose resource readers don't implement it. Fixes issue where + backport compatibility module was masking this fallback + behavior only to discover the defect when applying changes to + CPython. + v5.1.0 ====== diff -Nru importlib-resources-5.1.0/debian/changelog importlib-resources-5.1.2/debian/changelog --- importlib-resources-5.1.0/debian/changelog 2021-01-23 19:48:49.000000000 +0000 +++ importlib-resources-5.1.2/debian/changelog 2021-03-08 11:39:49.000000000 +0000 @@ -1,3 +1,14 @@ +importlib-resources (5.1.2-1) unstable; urgency=medium + + [ Jonas Meurer ] + * New upstream release 5.1.2 + + [ Debian Janitor ] + * Set upstream metadata fields: Bug-Database, Bug-Submit, Repository, + Repository-Browse. + + -- Jonas Meurer Mon, 08 Mar 2021 12:39:49 +0100 + importlib-resources (5.1.0-1) unstable; urgency=medium * New upstream release 5.1.0 diff -Nru importlib-resources-5.1.0/debian/upstream/metadata importlib-resources-5.1.2/debian/upstream/metadata --- importlib-resources-5.1.0/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ importlib-resources-5.1.2/debian/upstream/metadata 2021-03-08 11:39:49.000000000 +0000 @@ -0,0 +1,5 @@ +--- +Bug-Database: https://github.com/python/importlib_resources/issues +Bug-Submit: https://github.com/python/importlib_resources/issues/new +Repository: https://github.com/python/importlib_resources.git +Repository-Browse: https://github.com/python/importlib_resources diff -Nru importlib-resources-5.1.0/.editorconfig importlib-resources-5.1.2/.editorconfig --- importlib-resources-5.1.0/.editorconfig 1970-01-01 00:00:00.000000000 +0000 +++ importlib-resources-5.1.2/.editorconfig 2021-03-04 18:46:52.000000000 +0000 @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +indent_style = tab +indent_size = 4 +insert_final_newline = true +end_of_line = lf + +[*.py] +indent_style = space + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 diff -Nru importlib-resources-5.1.0/importlib_resources/_adapters.py importlib-resources-5.1.2/importlib_resources/_adapters.py --- importlib-resources-5.1.0/importlib_resources/_adapters.py 1970-01-01 00:00:00.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources/_adapters.py 2021-03-04 18:46:52.000000000 +0000 @@ -0,0 +1,82 @@ +from contextlib import suppress + +from . import abc + + +class SpecLoaderAdapter: + """ + Adapt a package spec to adapt the underlying loader. + """ + + def __init__(self, spec, adapter=lambda spec: spec.loader): + self.spec = spec + self.loader = adapter(spec) + + def __getattr__(self, name): + return getattr(self.spec, name) + + +class TraversableResourcesLoader: + """ + Adapt a loader to provide TraversableResources. + """ + + def __init__(self, spec): + self.spec = spec + + def get_resource_reader(self, name): + return DegenerateFiles(self.spec)._native() + + +class DegenerateFiles: + """ + Adapter for an existing or non-existant resource reader + to provide a degenerate .files(). + """ + + class Path(abc.Traversable): + def iterdir(self): + return iter(()) + + def is_dir(self): + return False + + is_file = exists = is_dir # type: ignore + + def joinpath(self, other): + return DegenerateFiles.Path() + + def name(self): + return '' + + def open(self): + raise ValueError() + + def __init__(self, spec): + self.spec = spec + + @property + def _reader(self): + with suppress(AttributeError): + return self.spec.loader.get_resource_reader(self.spec.name) + + def _native(self): + """ + Return the native reader if it supports files(). + """ + reader = self._reader + return reader if hasattr(reader, 'files') else self + + def __getattr__(self, attr): + return getattr(self._reader, attr) + + def files(self): + return DegenerateFiles.Path() + + +def wrap_spec(package): + """ + Construct a package spec with traversable compatibility + on the spec/loader/reader. + """ + return SpecLoaderAdapter(package.__spec__, TraversableResourcesLoader) diff -Nru importlib-resources-5.1.0/importlib_resources/_common.py importlib-resources-5.1.2/importlib_resources/_common.py --- importlib-resources-5.1.0/importlib_resources/_common.py 2021-01-19 03:22:15.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources/_common.py 2021-03-04 18:46:52.000000000 +0000 @@ -9,7 +9,7 @@ from typing import Union, Any, Optional from .abc import ResourceReader -from ._compat import package_spec +from ._compat import wrap_spec Package = Union[types.ModuleType, str] @@ -63,7 +63,7 @@ Raise an exception if the resolved module is not a package. """ resolved = resolve(package) - if package_spec(resolved).submodule_search_locations is None: + if wrap_spec(resolved).submodule_search_locations is None: raise TypeError('{!r} is not a package'.format(package)) return resolved @@ -73,7 +73,7 @@ Return a Traversable object for the given package. """ - spec = package_spec(package) + spec = wrap_spec(package) reader = spec.loader.get_resource_reader(spec.name) return reader.files() diff -Nru importlib-resources-5.1.0/importlib_resources/_compat.py importlib-resources-5.1.2/importlib_resources/_compat.py --- importlib-resources-5.1.0/importlib_resources/_compat.py 2021-01-19 03:22:15.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources/_compat.py 2021-03-04 18:46:52.000000000 +0000 @@ -1,9 +1,10 @@ +# flake8: noqa + import abc import sys +import pathlib from contextlib import suppress -# flake8: noqa - try: from zipfile import Path as ZipPath # type: ignore except ImportError: @@ -24,16 +25,7 @@ Protocol = abc.ABC # type: ignore -class TraversableResourcesAdapter: - def __init__(self, spec): - self.spec = spec - self.loader = LoaderAdapter(spec) - - def __getattr__(self, name): - return getattr(self.spec, name) - - -class LoaderAdapter: +class TraversableResourcesLoader: """ Adapt loaders to provide TraversableResources and other compatibility. @@ -47,8 +39,7 @@ return self.spec.origin def get_resource_reader(self, name): - # Python < 3.9 - from . import readers + from . import readers, _adapters def _zip_reader(spec): with suppress(AttributeError): @@ -66,6 +57,10 @@ reader = _available_reader(spec) return reader if hasattr(reader, 'files') else None + def _file_reader(spec): + if pathlib.Path(self.path).exists(): + return readers.FileReader(self) + return ( # native reader if it supplies 'files' _native_reader(self.spec) @@ -77,14 +72,16 @@ _namespace_reader(self.spec) or # local FileReader - readers.FileReader(self) + _file_reader(self.spec) + or _adapters.DegenerateFiles(self.spec) ) -def package_spec(package): +def wrap_spec(package): """ - Construct a minimal package spec suitable for - matching the interfaces this library relies upon - in later Python versions. + Construct a package spec with traversable compatibility + on the spec/loader/reader. """ - return TraversableResourcesAdapter(package.__spec__) + from . import _adapters + + return _adapters.SpecLoaderAdapter(package.__spec__, TraversableResourcesLoader) diff -Nru importlib-resources-5.1.0/importlib_resources/tests/test_reader.py importlib-resources-5.1.2/importlib_resources/tests/test_reader.py --- importlib-resources-5.1.0/importlib_resources/tests/test_reader.py 2021-01-19 03:22:15.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources/tests/test_reader.py 2021-03-04 18:46:52.000000000 +0000 @@ -1,5 +1,6 @@ import os.path import sys +import pathlib import unittest from importlib import import_module @@ -9,7 +10,8 @@ class MultiplexedPathTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.folder = os.path.abspath(os.path.join(__file__, '..', 'namespacedata01')) + path = pathlib.Path(__file__).parent / 'namespacedata01' + cls.folder = str(path) def test_init_no_paths(self): with self.assertRaises(FileNotFoundError): @@ -83,9 +85,15 @@ class NamespaceReaderTest(unittest.TestCase): + site_dir = str(pathlib.Path(__file__).parent) + @classmethod def setUpClass(cls): - sys.path.append(os.path.abspath(os.path.join(__file__, '..'))) + sys.path.append(cls.site_dir) + + @classmethod + def tearDownClass(cls): + sys.path.remove(cls.site_dir) def test_init_error(self): with self.assertRaises(ValueError): diff -Nru importlib-resources-5.1.0/importlib_resources/tests/test_resource.py importlib-resources-5.1.2/importlib_resources/tests/test_resource.py --- importlib-resources-5.1.0/importlib_resources/tests/test_resource.py 2021-01-19 03:22:15.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources/tests/test_resource.py 2021-03-04 18:46:52.000000000 +0000 @@ -1,9 +1,8 @@ -import os.path import sys import unittest import importlib_resources as resources import uuid -from pathlib import Path +import pathlib from . import data01 from . import zipdata01, zipdata02 @@ -150,10 +149,10 @@ modules = import_helper.modules_setup() self.addCleanup(import_helper.modules_cleanup, *modules) - data_path = Path(self.ZIP_MODULE.__file__) + data_path = pathlib.Path(self.ZIP_MODULE.__file__) data_dir = data_path.parent self.source_zip_path = data_dir / 'ziptestdata.zip' - self.zip_path = Path('{}.zip'.format(uuid.uuid4())).absolute() + self.zip_path = pathlib.Path('{}.zip'.format(uuid.uuid4())).absolute() self.zip_path.write_bytes(self.source_zip_path.read_bytes()) sys.path.append(str(self.zip_path)) self.data = import_module('ziptestdata') @@ -216,9 +215,15 @@ class ResourceFromNamespaceTest01(unittest.TestCase): + site_dir = str(pathlib.Path(__file__).parent) + @classmethod def setUpClass(cls): - sys.path.append(os.path.abspath(os.path.join(__file__, '..'))) + sys.path.append(cls.site_dir) + + @classmethod + def tearDownClass(cls): + sys.path.remove(cls.site_dir) def test_is_submodule_resource(self): self.assertTrue( diff -Nru importlib-resources-5.1.0/importlib_resources.egg-info/PKG-INFO importlib-resources-5.1.2/importlib_resources.egg-info/PKG-INFO --- importlib-resources-5.1.0/importlib_resources.egg-info/PKG-INFO 2021-01-19 03:22:35.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources.egg-info/PKG-INFO 2021-03-04 18:47:24.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: importlib-resources -Version: 5.1.0 +Version: 5.1.2 Summary: Read resources from Python packages Home-page: https://github.com/python/importlib_resources Author: Barry Warsaw diff -Nru importlib-resources-5.1.0/importlib_resources.egg-info/requires.txt importlib-resources-5.1.2/importlib_resources.egg-info/requires.txt --- importlib-resources-5.1.0/importlib_resources.egg-info/requires.txt 2021-01-19 03:22:35.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources.egg-info/requires.txt 2021-03-04 18:47:24.000000000 +0000 @@ -8,7 +8,7 @@ rst.linker>=1.9 [testing] -pytest!=3.7.3,>=3.5 +pytest>=4.6 pytest-checkdocs>=1.2.3 pytest-flake8 pytest-cov diff -Nru importlib-resources-5.1.0/importlib_resources.egg-info/SOURCES.txt importlib-resources-5.1.2/importlib_resources.egg-info/SOURCES.txt --- importlib-resources-5.1.0/importlib_resources.egg-info/SOURCES.txt 2021-01-19 03:22:35.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources.egg-info/SOURCES.txt 2021-03-04 18:47:24.000000000 +0000 @@ -1,4 +1,5 @@ .coveragerc +.editorconfig .flake8 .gitattributes .gitignore @@ -23,6 +24,7 @@ docs/migration.rst docs/using.rst importlib_resources/__init__.py +importlib_resources/_adapters.py importlib_resources/_common.py importlib_resources/_compat.py importlib_resources/_py3.py diff -Nru importlib-resources-5.1.0/importlib_resources.egg-info/top_level.txt importlib-resources-5.1.2/importlib_resources.egg-info/top_level.txt --- importlib-resources-5.1.0/importlib_resources.egg-info/top_level.txt 2021-01-19 03:22:35.000000000 +0000 +++ importlib-resources-5.1.2/importlib_resources.egg-info/top_level.txt 2021-03-04 18:47:24.000000000 +0000 @@ -1,2 +1 @@ -dist importlib_resources diff -Nru importlib-resources-5.1.0/PKG-INFO importlib-resources-5.1.2/PKG-INFO --- importlib-resources-5.1.0/PKG-INFO 2021-01-19 03:22:35.562694500 +0000 +++ importlib-resources-5.1.2/PKG-INFO 2021-03-04 18:47:24.554228300 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: importlib_resources -Version: 5.1.0 +Version: 5.1.2 Summary: Read resources from Python packages Home-page: https://github.com/python/importlib_resources Author: Barry Warsaw diff -Nru importlib-resources-5.1.0/pytest.ini importlib-resources-5.1.2/pytest.ini --- importlib-resources-5.1.0/pytest.ini 2021-01-19 03:22:15.000000000 +0000 +++ importlib-resources-5.1.2/pytest.ini 2021-03-04 18:46:52.000000000 +0000 @@ -5,5 +5,3 @@ # workaround for warning pytest-dev/pytest#6178 junit_family=xunit2 filterwarnings= - # https://github.com/pytest-dev/pytest/issues/6928 - ignore:direct construction of .*Item has been deprecated:DeprecationWarning diff -Nru importlib-resources-5.1.0/setup.cfg importlib-resources-5.1.2/setup.cfg --- importlib-resources-5.1.0/setup.cfg 2021-01-19 03:22:35.562694500 +0000 +++ importlib-resources-5.1.2/setup.cfg 2021-03-04 18:47:24.558228300 +0000 @@ -28,12 +28,13 @@ [options.packages.find] exclude = build* + dist* docs* tests* [options.extras_require] testing = - pytest >= 3.5, !=3.7.3 + pytest >= 4.6 pytest-checkdocs >= 1.2.3 pytest-flake8 pytest-black >= 0.3.7; python_implementation != "PyPy"