fix: py3.8 compatibility

This commit is contained in:
2024-08-06 12:32:52 +08:00
parent 4e799034d7
commit 03696650ea
3 changed files with 18 additions and 3 deletions

View File

@ -0,0 +1,16 @@
import importlib.resources
import sys
def get_resource(path: str):
"""
A wrapper for `importlib.resources.files()` since it's not available in Python 3.8.
"""
if sys.version_info >= (3, 9, 0):
with importlib.resources.as_file(
importlib.resources.files(__name__).joinpath(path)
) as resource_path:
return resource_path
with importlib.resources.path(__name__, path) as resource_path:
return resource_path