Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward compatible upgrade to fix deprecation warnings concerning LooseVersion and pkg_resources for Python3.8+ #1058

Merged
merged 4 commits into from
May 3, 2024
Merged
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
26 changes: 21 additions & 5 deletions scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,28 @@
import argparse
from argparse import RawTextHelpFormatter
from datetime import datetime
from distutils.version import LooseVersion
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
import pkg_resources

try:
# requires Python 3.8+
from importlib.metadata import metadata
def get_carla_version():
return Version(metadata("carla")["Version"])
except ModuleNotFoundError:
# backport checking for older Python versions; module is deprecated
import pkg_resources
def get_carla_version():
return Version(pkg_resources.get_distribution("carla").version)

import carla

Expand All @@ -46,6 +59,9 @@
# 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 @@ -91,9 +107,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)
dist = pkg_resources.get_distribution("carla")
if LooseVersion(dist.version) < LooseVersion('0.9.15'):
raise ImportError("CARLA version 0.9.15 or newer required. CARLA version found: {}".format(dist))
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
Loading