Skip to content

Commit

Permalink
< python3.8 backward compatible version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Daraan committed Feb 21, 2024
1 parent 9bc7905 commit debcf30
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@
import sys
import time
import json
from importlib.metadata import metadata
try:
# requires Python 3.8+
from importlib.metadata import metadata
def assert_min_carla_version(v='0.9.15'):
md = metadata("carla")
if Version(md["Version"]) < Version(v):
raise ImportError("CARLA version {} or newer required. CARLA version found: {}".format(v, md["Version"]))
except ModuleNotFoundError:
# backport checking for older Python versions
import pkg_resources
def assert_min_carla_version(v='0.9.15'):
dist = pkg_resources.get_distribution("carla")
if Version(dist.version) < Version(v):
raise ImportError("CARLA version {} or newer required. CARLA version found: {}".format(v, dist))


import carla

Expand Down Expand Up @@ -92,9 +106,7 @@ def __init__(self, args):
# requests in the localhost at port 2000.
self.client = carla.Client(args.host, int(args.port))
self.client.set_timeout(self.client_timeout)
md = metadata("carla")
if Version(md["Version"]) < Version('0.9.15'):
raise ImportError("CARLA version 0.9.15 or newer required. CARLA version found: {}".format(md["Version"]))
assert_min_carla_version('0.9.15')

# Load agent if requested via command line args
# If something goes wrong an exception will be thrown by importlib (ok here)
Expand Down

0 comments on commit debcf30

Please sign in to comment.