Skip to content

Commit

Permalink
Compacter version checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daraan committed Apr 15, 2024
1 parent 6f0ae0e commit 26a3c73
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,28 @@
import argparse
from argparse import RawTextHelpFormatter
from datetime import datetime
from packaging.version import Version
try:
from packaging.version import Version
except ImportError:
from distutils.version import LooseVersion as Version # Python 2 fallback
import importlib
import inspect
import os
import signal
import sys
import time
import json

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"]))
def get_carla_version():
return Version(metadata("carla")["Version"])
except ModuleNotFoundError:
# backport checking for older Python versions
# backport checking for older Python versions; module is deprecated
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))

def get_carla_version():
return Version(pkg_resources.get_distribution("carla").version)

import carla

Expand All @@ -60,6 +59,9 @@ def assert_min_carla_version(v='0.9.15'):
# Version of scenario_runner
VERSION = '0.9.13'

# Minimum version of CARLA that is required
MIN_CARLA_VERSION = '0.9.15'


class ScenarioRunner(object):

Expand Down Expand Up @@ -106,7 +108,9 @@ 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)
assert_min_carla_version('0.9.15')
carla_version = get_carla_version()
if carla_version < Version(MIN_CARLA_VERSION):
raise ImportError("CARLA version {} or newer required. CARLA version found: {}".format(MIN_CARLA_VERSION, carla_version))

# 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 26a3c73

Please sign in to comment.