Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/python/projectairsim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
]

dependencies = [
"importlib-resources>=5; python_version<'3.9'",
"pynng>=0.5.0",
"msgpack>=1.0.5",
"opencv-python>=4.2.0.32",
Expand Down
27 changes: 13 additions & 14 deletions client/python/projectairsim/src/projectairsim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import logging
import math
from typing import Dict, List, Tuple
import importlib.resources as resources

try:
from importlib.resources import files
except ImportError: # Python < 3.9
from importlib_resources import files

import msgpack
import numpy as np
import collections
Expand All @@ -25,20 +30,14 @@
def load_text_resource(resource_path: str) -> str:
"""Loads a package text resource and returns its contents.

Uses importlib.resources.files() when available (Python >= 3.9).
Falls back to pkg_resources for older Python versions.
Uses importlib.resources.files() on Python >= 3.9 and the
importlib-resources backport on older supported Python versions.
"""
if hasattr(resources, "files"):
# Preferred API: importlib.resources.files() (Python >= 3.9)
return (
resources.files(__package__)
.joinpath(resource_path)
.read_text(encoding="utf-8")
)
# Compatibility fallback for Python < 3.9
import pkg_resources

return pkg_resources.resource_string(__package__, resource_path).decode("utf-8")
return (
files(__package__)
.joinpath(*resource_path.split("/"))
.read_text(encoding="utf-8")
)


def get_pitch_between_traj_points(point1, point2):
Expand Down