Skip to content

Commit fec99f3

Browse files
committed
Merge branch 'master' into feature/traversable
2 parents 344fb6a + ce2fa42 commit fec99f3

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

importlib_resources/__init__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,22 @@
1111
'path',
1212
'read_binary',
1313
'read_text',
14+
'Package',
15+
'Resource',
16+
'ResourceReader',
1417
]
1518

1619

17-
# Use the Python 3.7 stdlib implementation if available.
18-
if sys.version_info >= (3, 7):
19-
from importlib.resources import (
20-
Package, Resource, contents, is_resource, open_binary, open_text, path,
21-
read_binary, read_text)
22-
from importlib.abc import ResourceReader
23-
__all__.extend(['Package', 'Resource', 'ResourceReader'])
24-
elif sys.version_info >= (3,):
20+
if sys.version_info >= (3,):
2521
from importlib_resources._py3 import (
2622
Package, Resource, contents, is_resource, open_binary, open_text, path,
2723
read_binary, read_text)
2824
from importlib_resources.abc import ResourceReader
29-
__all__.extend(['Package', 'Resource', 'ResourceReader'])
3025
else:
3126
from importlib_resources._py2 import (
3227
contents, is_resource, open_binary, open_text, path, read_binary,
3328
read_text)
29+
del __all__[-3:]
3430

3531

3632
__version__ = read_text('importlib_resources', 'version.txt').strip()

importlib_resources/_py3.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def open_binary(package: Package, resource: Resource) -> BinaryIO:
7676
return reader.open_resource(resource)
7777
# Using pathlib doesn't work well here due to the lack of 'strict'
7878
# argument for pathlib.Path.resolve() prior to Python 3.6.
79-
absolute_package_path = os.path.abspath(package.__spec__.origin)
79+
absolute_package_path = os.path.abspath(
80+
package.__spec__.origin or 'non-existent file')
8081
package_path = os.path.dirname(absolute_package_path)
8182
full_path = os.path.join(package_path, resource)
8283
try:
@@ -179,10 +180,7 @@ def is_resource(package: Package, name: str) -> bool:
179180
reader = _get_resource_reader(package)
180181
if reader is not None:
181182
return reader.is_resource(name)
182-
try:
183-
package_contents = set(contents(package))
184-
except (NotADirectoryError, FileNotFoundError):
185-
return False
183+
package_contents = set(contents(package))
186184
if name not in package_contents:
187185
return False
188186
return (trees.from_package(package) / name).is_file()
@@ -201,7 +199,10 @@ def contents(package: Package) -> Iterable[str]:
201199
return reader.contents()
202200
# Is the package a namespace package? By definition, namespace packages
203201
# cannot have resources.
204-
if (package.__spec__.origin == 'namespace' and
205-
not package.__spec__.has_location):
202+
namespace = (
203+
package.__spec__.origin is None or
204+
package.__spec__.origin == 'namespace'
205+
)
206+
if namespace or not package.__spec__.has_location:
206207
return ()
207208
return list(item.name for item in trees.from_package(package).iterdir())

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ classifiers =
1717

1818
[options]
1919
python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*
20-
setup_requires =
21-
setuptools
22-
wheel
2320
install_requires =
2421
pathlib2; python_version < '3'
2522
typing; python_version < '3.5'

tox.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[tox]
2-
# Don't cover Python 3.7 since this is just a shim for that version. Do at
3-
# least make sure we don't regress!
4-
envlist = {py27,py35,py36}{,-cov,-diffcov},{py37,py38},qa,docs
2+
# Coverage is missing on later version of Python
3+
envlist = {py27,py35,py36}{,-cov,-diffcov},py37,py38,qa,docs
54
skip_missing_interpreters = True
65

76

0 commit comments

Comments
 (0)