fix: use importlib_resources before python 3.9

This commit is contained in:
Lance Edgar 2024-07-02 09:58:30 -05:00
parent 5190730585
commit 3727959383
2 changed files with 9 additions and 8 deletions

View file

@ -35,11 +35,6 @@ import tempfile
import errno
import warnings
try:
import importlib.resources as importlib_resources
except ImportError:
import importlib_resources
from rattail.exceptions import PathNotFound
@ -222,9 +217,15 @@ def resource_path(path):
:rtype: string
"""
if not os.path.isabs(path) and ':' in path:
try:
from importlib.resources import files, as_file
except ImportError: # python < 3.9
from importlib_resources import files, as_file
package, filename = path.split(':')
ref = importlib_resources.files(package) / filename
with importlib_resources.as_file(ref) as path:
ref = files(package) / filename
with as_file(ref) as path:
return str(path)
return path

View file

@ -39,7 +39,7 @@ install_requires =
colander
humanize
importlib_metadata ; python_version < '3.8'
importlib_resources ; python_version < '3.8'
importlib_resources ; python_version < '3.9'
lockfile
makefun
Mako