Skip to content

Commit dad8a1f

Browse files
committed
mavproxy_map: use importlib
1 parent ee31a44 commit dad8a1f

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

MAVProxy/modules/mavproxy_map/mp_tile.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -618,20 +618,15 @@ def mp_icon(filename):
618618
# we have to jump through a lot of hoops to get an OpenCV image
619619
# when we may be in a package zip file
620620
try:
621-
import pkg_resources
622-
name = __name__
623-
if name == "__main__":
624-
name = "MAVProxy.modules.mavproxy_map.mp_tile"
625-
stream = pkg_resources.resource_stream(name, "data/%s" % filename).read()
626-
raw = np.fromstring(stream, dtype=np.uint8)
621+
import importlib.resources
622+
package = __package__ + ".data"
623+
if __name__ == "__main__":
624+
package = "MAVProxy.modules.mavproxy_map.data"
625+
with importlib.resources.open_binary(package, filename) as stream:
626+
raw = np.frombuffer(stream.read(), dtype=np.uint8)
627627
except Exception:
628-
try:
629-
stream = open(os.path.join(os.path.dirname(__file__), 'data', filename)).read()
630-
raw = np.fromstring(stream, dtype=np.uint8)
631-
except Exception:
632-
#we're in a Windows exe, where pkg_resources doesn't work
633-
import pkgutil
634-
raw = pkgutil.get_data( 'MAVProxy', 'modules//mavproxy_map//data//' + filename)
628+
stream = open(os.path.join(os.path.dirname(__file__), 'data', filename)).read()
629+
raw = np.fromstring(stream, dtype=np.uint8)
635630
img = cv2.imdecode(raw, cv2.IMREAD_COLOR)
636631
return img
637632

0 commit comments

Comments
 (0)