fix: use importlib_resources
before python 3.9
This commit is contained in:
parent
5190730585
commit
3727959383
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue