Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-importlib-resources for openSUSE:Factory checked in at 2022-11-01 13:40:28 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-importlib-resources (Old) and /work/SRC/openSUSE:Factory/.python-importlib-resources.new.2275 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-importlib-resources" Tue Nov 1 13:40:28 2022 rev:5 rq:1032378 version:5.10.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-importlib-resources/python-importlib-resources.changes 2022-09-17 20:08:23.792820492 +0200 +++ /work/SRC/openSUSE:Factory/.python-importlib-resources.new.2275/python-importlib-resources.changes 2022-11-01 13:40:29.895235374 +0100 @@ -1,0 +2,10 @@ +Fri Oct 28 17:45:02 UTC 2022 - Yogalakshmi Arunachalam <yarunacha...@suse.com> + +- Update to v5.10.0 + * #203: Lifted restriction on modules passed to files. Now modules need not be a package and if a non-package module is passed, + resources will be resolved adjacent to those modules, even for modules not found in any package. For example, + files(import_module('mod.py')) will resolve resources found at the root. The parameter to files was renamed from 'package' to 'anchor', + with a compatibility shim for those passing by keyword. + * #259: files no longer requires the anchor to be specified and can infer the anchor from the caller's scope (defaults to the caller's module). + +------------------------------------------------------------------- Old: ---- importlib_resources-5.9.0.tar.gz New: ---- importlib_resources-5.10.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-importlib-resources.spec ++++++ --- /var/tmp/diff_new_pack.G8SJP5/_old 2022-11-01 13:40:30.675239523 +0100 +++ /var/tmp/diff_new_pack.G8SJP5/_new 2022-11-01 13:40:30.683239565 +0100 @@ -19,7 +19,7 @@ %{?!python_module:%define python3-%{**}} %define skip_python2 1 Name: python-importlib-resources -Version: 5.9.0 +Version: 5.10.0 Release: 0 Summary: Read resources from Python packages License: Apache-2.0 ++++++ importlib_resources-5.9.0.tar.gz -> importlib_resources-5.10.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/.coveragerc new/importlib_resources-5.10.0/.coveragerc --- old/importlib_resources-5.9.0/.coveragerc 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/.coveragerc 2022-10-08 03:09:43.000000000 +0200 @@ -6,6 +6,7 @@ */_itertools.py */_legacy.py */simple.py + */_path.py [report] show_missing = True diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/.github/workflows/main.yml new/importlib_resources-5.10.0/.github/workflows/main.yml --- old/importlib_resources-5.9.0/.github/workflows/main.yml 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/.github/workflows/main.yml 2022-10-08 03:09:43.000000000 +0200 @@ -7,22 +7,26 @@ strategy: matrix: python: - # Build on pre-releases until stable, then stable releases. - # actions/setup-python#213 - - ~3.7.0-0 - - ~3.10.0-0 - - ~3.11.0-0 + - "3.7" + - "3.10" + - "3.11" + # Workaround for actions/setup-python#508 + dev: + - -dev platform: - ubuntu-latest - macos-latest - windows-latest + include: + - python: pypy3.9 + platform: ubuntu-latest runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v3 - name: Setup Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python }} + python-version: ${{ matrix.python }}${{ matrix.dev }} - name: Install tox run: | python -m pip install tox @@ -70,9 +74,9 @@ steps: - uses: actions/checkout@v3 - name: Setup Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: 3.11-dev - name: Install tox run: | python -m pip install tox diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/.readthedocs.yml new/importlib_resources-5.10.0/.readthedocs.yml --- old/importlib_resources-5.9.0/.readthedocs.yml 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/.readthedocs.yml 2022-10-08 03:09:43.000000000 +0200 @@ -4,3 +4,10 @@ - path: . extra_requirements: - docs + +# workaround for readthedocs/readthedocs.org#9623 +build: + # workaround for readthedocs/readthedocs.org#9635 + os: ubuntu-22.04 + tools: + python: "3" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/CHANGES.rst new/importlib_resources-5.10.0/CHANGES.rst --- old/importlib_resources-5.9.0/CHANGES.rst 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/CHANGES.rst 2022-10-08 03:09:43.000000000 +0200 @@ -1,3 +1,19 @@ +v5.10.0 +======= + +* #203: Lifted restriction on modules passed to ``files``. + Now modules need not be a package and if a non-package + module is passed, resources will be resolved adjacent to + those modules, even for modules not found in any package. + For example, ``files(import_module('mod.py'))`` will + resolve resources found at the root. The parameter to + files was renamed from 'package' to 'anchor', with a + compatibility shim for those passing by keyword. + +* #259: ``files`` no longer requires the anchor to be + specified and can infer the anchor from the caller's scope + (defaults to the caller's module). + v5.9.0 ====== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/PKG-INFO new/importlib_resources-5.10.0/PKG-INFO --- old/importlib_resources-5.9.0/PKG-INFO 2022-07-22 18:46:53.769731800 +0200 +++ new/importlib_resources-5.10.0/PKG-INFO 2022-10-08 03:10:24.264437700 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: importlib_resources -Version: 5.9.0 +Version: 5.10.0 Summary: Read resources from Python packages Home-page: https://github.com/python/importlib_resources Author: Barry Warsaw diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/docs/conf.py new/importlib_resources-5.10.0/docs/conf.py --- old/importlib_resources-5.9.0/docs/conf.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/docs/conf.py 2022-10-08 03:09:43.000000000 +0200 @@ -1,10 +1,16 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -extensions = ['sphinx.ext.autodoc', 'jaraco.packaging.sphinx', 'rst.linker'] +extensions = [ + 'sphinx.ext.autodoc', + 'jaraco.packaging.sphinx', +] master_doc = "index" +html_theme = "furo" +# Link dates and other references in the changelog +extensions += ['rst.linker'] link_files = { '../CHANGES.rst': dict( using=dict(GH='https://github.com'), @@ -29,7 +35,7 @@ ), } -# Be strict about any broken references: +# Be strict about any broken references nitpicky = True # Include Python intersphinx mapping to prevent failures @@ -39,4 +45,7 @@ 'python': ('https://docs.python.org/3', None), } +# Preserve authored syntax for defaults +autodoc_preserve_defaults = True + extensions += ['jaraco.tidelift'] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/docs/index.rst new/importlib_resources-5.10.0/docs/index.rst --- old/importlib_resources-5.9.0/docs/index.rst 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/docs/index.rst 2022-10-08 03:09:43.000000000 +0200 @@ -6,8 +6,8 @@ `Basic Resource Access`_ API, but without all of the overhead and performance problems of ``pkg_resources``. -In our terminology, a *resource* is a file tree that is located within an -importable `Python package`_. Resources can live on the file system or in a +In our terminology, a *resource* is a file tree that is located alongside an +importable `Python module`_. Resources can live on the file system or in a zip file, with support for other loader_ classes that implement the appropriate API for reading resources. @@ -43,5 +43,5 @@ .. _`Basic Resource Access`: http://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access -.. _`Python package`: https://docs.python.org/3/reference/import.html#packages +.. _`Python module`: https://docs.python.org/3/glossary.html#term-module .. _loader: https://docs.python.org/3/reference/import.html#finders-and-loaders diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/docs/using.rst new/importlib_resources-5.10.0/docs/using.rst --- old/importlib_resources-5.9.0/docs/using.rst 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/docs/using.rst 2022-10-08 03:09:43.000000000 +0200 @@ -5,11 +5,11 @@ =========================== ``importlib_resources`` is a library that leverages Python's import system to -provide access to *resources* within *packages*. Given that this library is -built on top of the import system, it is highly efficient and easy to use. -This library's philosophy is that, if you can import a package, you can access -resources within that package. Resources can be opened or read, in either -binary or text mode. +provide access to *resources* within *packages* and alongside *modules*. Given +that this library is built on top of the import system, it is highly efficient +and easy to use. This library's philosophy is that, if one can import a +module, one can access resources associated with that module. Resources can be +opened or read, in either binary or text mode. What exactly do we mean by "a resource"? It's easiest to think about the metaphor of files and directories on the file system, though it's important to @@ -23,11 +23,14 @@ one/ __init__.py resource1.txt + module1.py resources1/ resource1.1.txt two/ __init__.py resource2.txt + standalone.py + resource3.txt then the directories are ``data``, ``data/one``, and ``data/two``. Each of these are also Python packages by virtue of the fact that they all contain @@ -48,11 +51,14 @@ ``data/one/resource1.txt`` and ``data/two/resource2.txt`` are both resources, as are the ``__init__.py`` files in all the directories. -Resources are always accessed relative to the package that they live in. -``resource1.txt`` and ``resources1/resource1.1.txt`` are resources within -the ``data.one`` package, and -``two/resource2.txt`` is a resource within the -``data`` package. +Resources in packages are always accessed relative to the package that they +live in. ``resource1.txt`` and ``resources1/resource1.1.txt`` are resources +within the ``data.one`` package, and ``two/resource2.txt`` is a resource +within the ``data`` package. + +Resources may also be referenced relative to another *anchor*, a module in a +package (``data.one.module1``) or a standalone module (``standalone``). In +this case, resources are loaded from the same loader that loaded that module. Example @@ -103,14 +109,14 @@ eml = files('email.tests.data').joinpath('message.eml').read_text() -Packages or package names -========================= +Anchors +======= -All of the ``importlib_resources`` APIs take a *package* as their first -parameter, but this can either be a package name (as a ``str``) or an actual -module object, though the module *must* be a package. If a string is -passed in, it must name an importable Python package, and this is first -imported. Thus the above example could also be written as:: +The ``importlib_resources`` ``files`` API takes an *anchor* as its first +parameter, which can either be a package name (as a ``str``) or an actual +module object. If a string is passed in, it must name an importable Python +module, which is imported prior to loading any resources. Thus the above +example could also be written as:: import email.tests.data eml = files(email.tests.data).joinpath('message.eml').read_text() @@ -119,18 +125,18 @@ File system or zip file ======================= -In general you never have to worry whether your package is on the file system -or in a zip file, as the ``importlib_resources`` APIs hide those details from -you. Sometimes though, you need a path to an actual file on the file system. +A consumer need not worry whether any given package is on the file system +or in a zip file, as the ``importlib_resources`` APIs abstracts those details. +Sometimes though, the user needs a path to an actual file on the file system. For example, some SSL APIs require a certificate file to be specified by a real file system path, and C's ``dlopen()`` function also requires a real file system path. -To support this, ``importlib_resources`` provides an API that will extract the -resource from a zip file to a temporary file, and return the file system path -to this temporary file as a :py:class:`pathlib.Path` object. In order to -properly clean up this temporary file, what's actually returned is a context -manager that you can use in a ``with``-statement:: +To support this need, ``importlib_resources`` provides an API to extract the +resource from a zip file to a temporary file or folder and return the file +system path to this materialized resource as a :py:class:`pathlib.Path` +object. In order to properly clean up this temporary file, what's actually +returned is a context manager for use in a ``with``-statement:: from importlib_resources import files, as_file @@ -138,29 +144,7 @@ with as_file(source) as eml: third_party_api_requiring_file_system_path(eml) -You can use all the standard :py:mod:`contextlib` APIs to manage this context -manager. - -.. attention:: - - There is an odd interaction with Python 3.4, 3.5, and 3.6 regarding adding - zip or wheel file paths to ``sys.path``. Due to limitations in `zipimport - <https://docs.python.org/3/library/zipimport.html>`_, which can't be - changed without breaking backward compatibility, you **must** use an - absolute path to the zip/wheel file. If you use a relative path, you will - not be able to find resources inside these zip files. E.g.: - - **No**:: - - sys.path.append('relative/path/to/foo.whl') - files('foo') # This will fail! - - **Yes**:: - - sys.path.append(os.path.abspath('relative/path/to/foo.whl')) - files('foo') - -Both relative and absolute paths work for Python 3.7 and newer. +Use all the standard :py:mod:`contextlib` APIs to manage this context manager. Migrating from Legacy diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/__init__.py new/importlib_resources-5.10.0/importlib_resources/__init__.py --- old/importlib_resources-5.9.0/importlib_resources/__init__.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources/__init__.py 2022-10-08 03:09:43.000000000 +0200 @@ -17,7 +17,7 @@ Resource, ) -from importlib_resources.abc import ResourceReader +from .abc import ResourceReader __all__ = [ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/_common.py new/importlib_resources-5.10.0/importlib_resources/_common.py --- old/importlib_resources-5.9.0/importlib_resources/_common.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources/_common.py 2022-10-08 03:09:43.000000000 +0200 @@ -5,25 +5,58 @@ import contextlib import types import importlib +import inspect +import warnings +import itertools -from typing import Union, Optional +from typing import Union, Optional, cast from .abc import ResourceReader, Traversable from ._compat import wrap_spec Package = Union[types.ModuleType, str] +Anchor = Package -def files(package): - # type: (Package) -> Traversable +def package_to_anchor(func): """ - Get a Traversable resource from a package + Replace 'package' parameter as 'anchor' and warn about the change. + + Other errors should fall through. + + >>> files('a', 'b') + Traceback (most recent call last): + TypeError: files() takes from 0 to 1 positional arguments but 2 were given + """ + undefined = object() + + @functools.wraps(func) + def wrapper(anchor=undefined, package=undefined): + if package is not undefined: + if anchor is not undefined: + return func(anchor, package) + warnings.warn( + "First parameter to files is renamed to 'anchor'", + DeprecationWarning, + stacklevel=2, + ) + return func(package) + elif anchor is undefined: + return func() + return func(anchor) + + return wrapper + + +@package_to_anchor +def files(anchor: Optional[Anchor] = None) -> Traversable: + """ + Get a Traversable resource for an anchor. """ - return from_package(get_package(package)) + return from_package(resolve(anchor)) -def get_resource_reader(package): - # type: (types.ModuleType) -> Optional[ResourceReader] +def get_resource_reader(package: types.ModuleType) -> Optional[ResourceReader]: """ Return the package's loader if it's a ResourceReader. """ @@ -39,24 +72,39 @@ return reader(spec.name) # type: ignore -def resolve(cand): - # type: (Package) -> types.ModuleType - return cand if isinstance(cand, types.ModuleType) else importlib.import_module(cand) +@functools.singledispatch +def resolve(cand: Optional[Anchor]) -> types.ModuleType: + return cast(types.ModuleType, cand) -def get_package(package): - # type: (Package) -> types.ModuleType - """Take a package name or module object and return the module. +@resolve.register +def _(cand: str) -> types.ModuleType: + return importlib.import_module(cand) - Raise an exception if the resolved module is not a package. + +@resolve.register +def _(cand: None) -> types.ModuleType: + return resolve(_infer_caller().f_globals['__name__']) + + +def _infer_caller(): + """ + Walk the stack and find the frame of the first caller not in this module. """ - resolved = resolve(package) - if wrap_spec(resolved).submodule_search_locations is None: - raise TypeError(f'{package!r} is not a package') - return resolved + + def is_this_file(frame_info): + return frame_info.filename == __file__ + + def is_wrapper(frame_info): + return frame_info.function == 'wrapper' + + not_this_file = itertools.filterfalse(is_this_file, inspect.stack()) + # also exclude 'wrapper' due to singledispatch in the call stack + callers = itertools.filterfalse(is_wrapper, not_this_file) + return next(callers).frame -def from_package(package): +def from_package(package: types.ModuleType): """ Return a Traversable object for the given package. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/_legacy.py new/importlib_resources-5.10.0/importlib_resources/_legacy.py --- old/importlib_resources-5.9.0/importlib_resources/_legacy.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources/_legacy.py 2022-10-08 03:09:43.000000000 +0200 @@ -27,8 +27,7 @@ return wrapper -def normalize_path(path): - # type: (Any) -> str +def normalize_path(path: Any) -> str: """Normalize a path by ensuring it is a string. If the resulting string contains path separators, an exception is raised. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/abc.py new/importlib_resources-5.10.0/importlib_resources/abc.py --- old/importlib_resources-5.9.0/importlib_resources/abc.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources/abc.py 2022-10-08 03:09:43.000000000 +0200 @@ -139,7 +139,8 @@ accepted by io.TextIOWrapper. """ - @abc.abstractproperty + @property + @abc.abstractmethod def name(self) -> str: """ The base name of this object without any parent references. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/simple.py new/importlib_resources-5.10.0/importlib_resources/simple.py --- old/importlib_resources-5.9.0/importlib_resources/simple.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources/simple.py 2022-10-08 03:09:43.000000000 +0200 @@ -16,31 +16,28 @@ provider. """ - @abc.abstractproperty - def package(self): - # type: () -> str + @property + @abc.abstractmethod + def package(self) -> str: """ The name of the package for which this reader loads resources. """ @abc.abstractmethod - def children(self): - # type: () -> List['SimpleReader'] + def children(self) -> List['SimpleReader']: """ Obtain an iterable of SimpleReader for available child containers (e.g. directories). """ @abc.abstractmethod - def resources(self): - # type: () -> List[str] + def resources(self) -> List[str]: """ Obtain available named resources for this virtual package. """ @abc.abstractmethod - def open_binary(self, resource): - # type: (str) -> BinaryIO + def open_binary(self, resource: str) -> BinaryIO: """ Obtain a File-like for a named resource. """ @@ -50,13 +47,35 @@ return self.package.split('.')[-1] +class ResourceContainer(Traversable): + """ + Traversable container for a package's resources via its reader. + """ + + def __init__(self, reader: SimpleReader): + self.reader = reader + + def is_dir(self): + return True + + def is_file(self): + return False + + def iterdir(self): + files = (ResourceHandle(self, name) for name in self.reader.resources) + dirs = map(ResourceContainer, self.reader.children()) + return itertools.chain(files, dirs) + + def open(self, *args, **kwargs): + raise IsADirectoryError() + + class ResourceHandle(Traversable): """ Handle to a named resource in a ResourceReader. """ - def __init__(self, parent, name): - # type: (ResourceContainer, str) -> None + def __init__(self, parent: ResourceContainer, name: str): self.parent = parent self.name = name # type: ignore @@ -76,30 +95,6 @@ raise RuntimeError("Cannot traverse into a resource") -class ResourceContainer(Traversable): - """ - Traversable container for a package's resources via its reader. - """ - - def __init__(self, reader): - # type: (SimpleReader) -> None - self.reader = reader - - def is_dir(self): - return True - - def is_file(self): - return False - - def iterdir(self): - files = (ResourceHandle(self, name) for name in self.reader.resources) - dirs = map(ResourceContainer, self.reader.children()) - return itertools.chain(files, dirs) - - def open(self, *args, **kwargs): - raise IsADirectoryError() - - class TraversableReader(TraversableResources, SimpleReader): """ A TraversableResources based on SimpleReader. Resource providers diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/tests/_compat.py new/importlib_resources-5.10.0/importlib_resources/tests/_compat.py --- old/importlib_resources-5.9.0/importlib_resources/tests/_compat.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources/tests/_compat.py 2022-10-08 03:09:43.000000000 +0200 @@ -6,7 +6,20 @@ except ImportError: # Python 3.9 and earlier class import_helper: # type: ignore - from test.support import modules_setup, modules_cleanup + 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: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/tests/_path.py new/importlib_resources-5.10.0/importlib_resources/tests/_path.py --- old/importlib_resources-5.9.0/importlib_resources/tests/_path.py 1970-01-01 01:00:00.000000000 +0100 +++ new/importlib_resources-5.10.0/importlib_resources/tests/_path.py 2022-10-08 03:09:43.000000000 +0200 @@ -0,0 +1,50 @@ +import pathlib +import functools + + +#### +# from jaraco.path 3.4 + + +def build(spec, prefix=pathlib.Path()): + """ + Build a set of files/directories, as described by the spec. + + Each key represents a pathname, and the value represents + the content. Content may be a nested directory. + + >>> spec = { + ... 'README.txt': "A README file", + ... "foo": { + ... "__init__.py": "", + ... "bar": { + ... "__init__.py": "", + ... }, + ... "baz.py": "# Some code", + ... } + ... } + >>> tmpdir = getfixture('tmpdir') + >>> build(spec, tmpdir) + """ + for name, contents in spec.items(): + create(contents, pathlib.Path(prefix) / name) + + +@functools.singledispatch +def create(content, path): + path.mkdir(exist_ok=True) + build(content, prefix=path) # type: ignore + + +@create.register +def _(content: bytes, path): + path.write_bytes(content) + + +@create.register +def _(content: str, path): + path.write_text(content) + + +# end from jaraco.path +#### diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/tests/test_files.py new/importlib_resources-5.10.0/importlib_resources/tests/test_files.py --- old/importlib_resources-5.9.0/importlib_resources/tests/test_files.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources/tests/test_files.py 2022-10-08 03:09:43.000000000 +0200 @@ -1,10 +1,23 @@ import typing +import textwrap import unittest +import warnings +import importlib +import contextlib import importlib_resources as resources -from importlib_resources.abc import Traversable +from ..abc import Traversable from . import data01 from . import util +from . import _path +from ._compat import os_helper, import_helper + + +@contextlib.contextmanager +def suppress_known_deprecation(): + with warnings.catch_warnings(record=True) as ctx: + warnings.simplefilter('default', category=DeprecationWarning) + yield ctx class FilesTests: @@ -25,6 +38,14 @@ def test_traversable(self): assert isinstance(resources.files(self.data), Traversable) + def test_old_parameter(self): + """ + Files used to take a 'package' parameter. Make sure anyone + passing by name is still supported. + """ + with suppress_known_deprecation(): + resources.files(package=self.data) + class OpenDiskTests(FilesTests, unittest.TestCase): def setUp(self): @@ -42,5 +63,50 @@ self.data = namespacedata01 +class SiteDir: + def setUp(self): + self.fixtures = contextlib.ExitStack() + 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()) + + +class ModulesFilesTests(SiteDir, unittest.TestCase): + def test_module_resources(self): + """ + A module can have resources found adjacent to the module. + """ + spec = { + 'mod.py': '', + 'res.txt': 'resources are the best', + } + _path.build(spec, self.site_dir) + import mod + + actual = resources.files(mod).joinpath('res.txt').read_text() + assert actual == spec['res.txt'] + + +class ImplicitContextFilesTests(SiteDir, unittest.TestCase): + def test_implicit_files(self): + """ + Without any parameter, files() will infer the location as the caller. + """ + spec = { + 'somepkg': { + '__init__.py': textwrap.dedent( + """ + import importlib_resources as res + val = res.files().joinpath('res.txt').read_text() + """ + ), + 'res.txt': 'resources are the best', + }, + } + _path.build(spec, self.site_dir) + assert importlib.import_module('somepkg').val == 'resources are the best' + + if __name__ == '__main__': unittest.main() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources/tests/util.py new/importlib_resources-5.10.0/importlib_resources/tests/util.py --- old/importlib_resources-5.9.0/importlib_resources/tests/util.py 2022-07-22 18:46:22.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources/tests/util.py 2022-10-08 03:09:43.000000000 +0200 @@ -3,7 +3,7 @@ import io import sys import types -from pathlib import Path, PurePath +import pathlib from . import data01 from . import zipdata01 @@ -94,7 +94,7 @@ def test_pathlib_path(self): # Passing in a pathlib.PurePath object for the path should succeed. - path = PurePath('utf-8.file') + path = pathlib.PurePath('utf-8.file') self.execute(data01, path) def test_importing_module_as_side_effect(self): @@ -102,17 +102,6 @@ del sys.modules[data01.__name__] self.execute(data01.__name__, 'utf-8.file') - def test_non_package_by_name(self): - # The anchor package cannot be a module. - with self.assertRaises(TypeError): - self.execute(__name__, 'utf-8.file') - - def test_non_package_by_package(self): - # The anchor package cannot be a module. - with self.assertRaises(TypeError): - module = sys.modules['importlib_resources.tests.util'] - self.execute(module, 'utf-8.file') - def test_missing_path(self): # Attempting to open or read or request the path for a # non-existent path should succeed if open_resource @@ -144,7 +133,7 @@ @classmethod def setUpClass(cls): - data_path = Path(cls.ZIP_MODULE.__file__) + data_path = pathlib.Path(cls.ZIP_MODULE.__file__) data_dir = data_path.parent cls._zip_path = str(data_dir / 'ziptestdata.zip') sys.path.append(cls._zip_path) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources.egg-info/PKG-INFO new/importlib_resources-5.10.0/importlib_resources.egg-info/PKG-INFO --- old/importlib_resources-5.9.0/importlib_resources.egg-info/PKG-INFO 2022-07-22 18:46:53.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources.egg-info/PKG-INFO 2022-10-08 03:10:24.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: importlib-resources -Version: 5.9.0 +Version: 5.10.0 Summary: Read resources from Python packages Home-page: https://github.com/python/importlib_resources Author: Barry Warsaw diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources.egg-info/SOURCES.txt new/importlib_resources-5.10.0/importlib_resources.egg-info/SOURCES.txt --- old/importlib_resources-5.9.0/importlib_resources.egg-info/SOURCES.txt 2022-07-22 18:46:53.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources.egg-info/SOURCES.txt 2022-10-08 03:10:24.000000000 +0200 @@ -39,6 +39,7 @@ importlib_resources.egg-info/top_level.txt importlib_resources/tests/__init__.py importlib_resources/tests/_compat.py +importlib_resources/tests/_path.py importlib_resources/tests/test_compatibilty_files.py importlib_resources/tests/test_contents.py importlib_resources/tests/test_files.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/importlib_resources.egg-info/requires.txt new/importlib_resources-5.10.0/importlib_resources.egg-info/requires.txt --- old/importlib_resources-5.9.0/importlib_resources.egg-info/requires.txt 2022-07-22 18:46:53.000000000 +0200 +++ new/importlib_resources-5.10.0/importlib_resources.egg-info/requires.txt 2022-10-08 03:10:24.000000000 +0200 @@ -3,15 +3,17 @@ zipp>=3.1.0 [docs] -sphinx +sphinx>=3.5 jaraco.packaging>=9 rst.linker>=1.9 +furo jaraco.tidelift>=1.4 [testing] pytest>=6 pytest-checkdocs>=2.4 pytest-flake8 +flake8<5 pytest-cov pytest-enabler>=1.3 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/importlib_resources-5.9.0/setup.cfg new/importlib_resources-5.10.0/setup.cfg --- old/importlib_resources-5.9.0/setup.cfg 2022-07-22 18:46:53.769731800 +0200 +++ new/importlib_resources-5.10.0/setup.cfg 2022-10-08 03:10:24.264437700 +0200 @@ -33,6 +33,7 @@ pytest >= 6 pytest-checkdocs >= 2.4 pytest-flake8 + flake8 < 5 pytest-black >= 0.3.7; \ python_implementation != "PyPy" pytest-cov @@ -40,9 +41,10 @@ python_implementation != "PyPy" pytest-enabler >= 1.3 docs = - sphinx + sphinx >= 3.5 jaraco.packaging >= 9 rst.linker >= 1.9 + furo jaraco.tidelift >= 1.4 [egg_info]