Skip to content

Commit 1923197

Browse files
committed
Update docs to prefer the name 'anchor' to 'package', as the anchor may be a module.
1 parent 8864353 commit 1923197

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

docs/index.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ in Python packages. It provides functionality similar to ``pkg_resources``
66
`Basic Resource Access`_ API, but without all of the overhead and performance
77
problems of ``pkg_resources``.
88

9-
In our terminology, a *resource* is a file tree that is located within an
10-
importable `Python package`_. Resources can live on the file system or in a
9+
In our terminology, a *resource* is a file tree that is located alongside an
10+
importable `Python module`_. Resources can live on the file system or in a
1111
zip file, with support for other loader_ classes that implement the appropriate
1212
API for reading resources.
1313

@@ -43,5 +43,5 @@ Indices and tables
4343

4444

4545
.. _`Basic Resource Access`: http://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access
46-
.. _`Python package`: https://docs.python.org/3/reference/import.html#packages
46+
.. _`Python module`: https://docs.python.org/3/glossary.html#term-module
4747
.. _loader: https://docs.python.org/3/reference/import.html#finders-and-loaders

docs/using.rst

+22-16
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
===========================
66

77
``importlib_resources`` is a library that leverages Python's import system to
8-
provide access to *resources* within *packages*. Given that this library is
9-
built on top of the import system, it is highly efficient and easy to use.
10-
This library's philosophy is that, if you can import a package, you can access
11-
resources within that package. Resources can be opened or read, in either
12-
binary or text mode.
8+
provide access to *resources* within *packages* and alongside *modules*. Given
9+
that this library is built on top of the import system, it is highly efficient
10+
and easy to use. This library's philosophy is that, if one can import a
11+
module, one can access resources associated with that module. Resources can be
12+
opened or read, in either binary or text mode.
1313

1414
What exactly do we mean by "a resource"? It's easiest to think about the
1515
metaphor of files and directories on the file system, though it's important to
@@ -23,11 +23,14 @@ If you have a file system layout such as::
2323
one/
2424
__init__.py
2525
resource1.txt
26+
module1.py
2627
resources1/
2728
resource1.1.txt
2829
two/
2930
__init__.py
3031
resource2.txt
32+
standalone.py
33+
resource3.txt
3134

3235
then the directories are ``data``, ``data/one``, and ``data/two``. Each of
3336
these are also Python packages by virtue of the fact that they all contain
@@ -48,11 +51,14 @@ package directory, so
4851
``data/one/resource1.txt`` and ``data/two/resource2.txt`` are both resources,
4952
as are the ``__init__.py`` files in all the directories.
5053

51-
Resources are always accessed relative to the package that they live in.
52-
``resource1.txt`` and ``resources1/resource1.1.txt`` are resources within
53-
the ``data.one`` package, and
54-
``two/resource2.txt`` is a resource within the
55-
``data`` package.
54+
Resources in packages are always accessed relative to the package that they
55+
live in. ``resource1.txt`` and ``resources1/resource1.1.txt`` are resources
56+
within the ``data.one`` package, and ``two/resource2.txt`` is a resource
57+
within the ``data`` package.
58+
59+
Resources may also be referenced relative to another *anchor*, a module in a
60+
package (``data.one.module1``) or a standalone module (``standalone``). In
61+
this case, resources are loaded from the same loader that loaded that module.
5662

5763

5864
Example
@@ -103,13 +109,13 @@ using ``importlib_resources`` would look like::
103109
eml = files('email.tests.data').joinpath('message.eml').read_text()
104110

105111

106-
Packages or package names
107-
=========================
112+
Anchors
113+
=======
108114

109-
All of the ``importlib_resources`` APIs take a *package* as their first
110-
parameter, but this can either be a package name (as a ``str``) or an actual
111-
module object, though the module *must* be a package. If a string is
112-
passed in, it must name an importable Python package, and this is first
115+
All of the ``importlib_resources`` APIs take an *anchor* as their first
116+
parameter, which can either be a package name (as a ``str``) or an actual
117+
module object. If a string is
118+
passed in, it must name an importable Python module, and this is first
113119
imported. Thus the above example could also be written as::
114120

115121
import email.tests.data

importlib_resources/_common.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
from ._compat import wrap_spec
1313

1414
Package = Union[types.ModuleType, str]
15+
Anchor = Package
1516

1617

17-
def files(package: Package) -> Traversable:
18+
def files(package: Anchor) -> Traversable:
1819
"""
19-
Get a Traversable resource from a package
20+
Get a Traversable resource for an anchor.
2021
"""
2122
return from_package(resolve(package))
2223

0 commit comments

Comments
 (0)