Skip to content

Commit

Permalink
Always use python 3.9’s importlib.resources
Browse files Browse the repository at this point in the history
Use backport otherwise, i.e. in 3.8 and before.
  • Loading branch information
Cimbali committed Mar 30, 2023
1 parent 11e2053 commit 30751f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions pympress/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import sys
import pathlib

try:
# Introduced in 3.7
if sys.version_info >= (3, 9):
# Using parts introduced in 3.9
import importlib.resources as importlib_resources
except ImportError:
else:
# Backport dependency
import importlib_resources

Expand Down Expand Up @@ -103,13 +103,9 @@ def __get_resource_path(*path_parts):
Returns:
:class:`~pathlib.Path`: The path to the resource
"""
try:
# Introduced in 3.9
resource = importlib_resources.asfile(importlib_resources.files('pympress').joinpath(*path_parts))
except AttributeError:
# Deprecated in 3.11
resource = importlib_resources.path('.'.join(('pympress', *path_parts[:-1])), path_parts[-1])
return _opened_resources.enter_context(resource)
# Introduced in 3.9
resource = importlib_resources.files('pympress').joinpath(*path_parts)
return _opened_resources.enter_context(importlib_resources.as_file(resource))


def close_opened_resources():
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ packages =
python_requires = >=3.4
install_requires =
watchdog
importlib_resources;python_version<"3.7"
importlib_resources >= 1.3;python_version<"3.9"
build_requires =
setuptools
babel
Expand Down

0 comments on commit 30751f8

Please sign in to comment.