Skip to content

Commit

Permalink
python3.12 support
Browse files Browse the repository at this point in the history
Use importlib.resources instead of the deprecated pkg_resources.
  • Loading branch information
sirtoobii committed Nov 21, 2024
1 parent 19ac176 commit 94e7206
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions dronecan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
import os
import sys
import struct
import pkg_resources
try:
# pkg_resources is depreciated in favor of importlib.resources.*
# https://setuptools.pypa.io/en/latest/pkg_resources.html
from importlib.resources import files as importlib_files
USE_FALLBACK_PGK_RES = False
except ImportError:
# Only necessary in Python versions < 3.7
USE_FALLBACK_PGK_RES = True
import pkg_resources
import time
from logging import getLogger

Expand Down Expand Up @@ -124,7 +132,10 @@ def load_dsdl(*paths, **args):
# noinspection PyBroadException
try:
if not args.get("exclude_dist", None):
dsdl_path = pkg_resources.resource_filename(__name__, "dsdl_specs") # @UndefinedVariable
if USE_FALLBACK_PGK_RES:
dsdl_path = pkg_resources.resource_filename(__name__, "dsdl_specs") # @UndefinedVariable
else:
dsdl_path = importlib_files(__package__).joinpath("dsdl_specs")
# check if we are a package, if not directly use relative DSDL path
if not os.path.exists(dsdl_path):
DSDL_paths = [ "../../DSDL", "../../../../../DroneCAN/DSDL", "../../../../dsdl"]
Expand Down Expand Up @@ -194,7 +205,7 @@ def create_instance(*args, **kwargs):
if str(ext_namespace) != "uavcan":
# noinspection PyUnresolvedReferences
MODULE.thirdparty.__dict__[str(ext_namespace)] = root_namespace.__dict__[ext_namespace]

__all__ = ["dsdl", "transport", "load_dsdl", "DATATYPES", "TYPENAMES"]


Expand Down

0 comments on commit 94e7206

Please sign in to comment.