Skip to content

Commit 7b3a847

Browse files
committed
api: correct how importlib_resources backport is used so it actually works.
1 parent 5e44365 commit 7b3a847

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/libusb_package/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616

1717
import atexit
1818
import ctypes.util
19-
import importlib.resources
2019
import functools
2120
import platform
2221
import sys
2322
from typing import (Any, Optional, TYPE_CHECKING)
2423

24+
# importlib.resources isn't available before Python 3.7, so if importing it
25+
# fails we import the backport.
26+
try:
27+
from importlib import resources
28+
except ImportError:
29+
import importlib_resources as resources
30+
2531
from ._version import version as __version__
2632

2733
if TYPE_CHECKING:
@@ -42,8 +48,8 @@
4248
@functools.lru_cache()
4349
def get_library_path() -> Optional["Path"]:
4450
"""@brief Returns the path to included library, if there is one."""
45-
if importlib.resources.is_resource(__name__, _LIBRARY_NAME):
46-
path_resource = importlib.resources.path(__name__, _LIBRARY_NAME)
51+
if resources.is_resource(__name__, _LIBRARY_NAME):
52+
path_resource = resources.path(__name__, _LIBRARY_NAME)
4753
path = path_resource.__enter__()
4854

4955
@atexit.register

0 commit comments

Comments
 (0)