From 750978ed50809513a2b2eb01016e5ccf4d25939b Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 16 Oct 2024 23:04:40 +0200 Subject: [PATCH] Don't depend on distutils distutils are no longer available in Python 3.12. Therefore, we copy the strtobool function from distutils to our own module. This is in line with https://peps.python.org/pep-0632/#migration-advice. --- Docs/CHANGELOG.md | 1 + .../actorcontrols/simple_vehicle_control.py | 2 +- srunner/scenarios/open_scenario.py | 2 +- srunner/tools/openscenario_parser.py | 2 +- srunner/tools/util.py | 14 ++++++++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 srunner/tools/util.py diff --git a/Docs/CHANGELOG.md b/Docs/CHANGELOG.md index c6def0522..ab5194a49 100644 --- a/Docs/CHANGELOG.md +++ b/Docs/CHANGELOG.md @@ -15,6 +15,7 @@ ## Upcoming * Improvements to the CarlaDataProvider: - Added `spawn_actor` for a blueprint based actor creation similar to `World.spawn_actor` +* Implement `strtobool` formerly included in `distutils`, which is removed in Python 3.12. ## CARLA ScenarioRunner 0.9.15 ### :rocket: New Features diff --git a/srunner/scenariomanager/actorcontrols/simple_vehicle_control.py b/srunner/scenariomanager/actorcontrols/simple_vehicle_control.py index 5f1d58daa..7bfaf31d2 100644 --- a/srunner/scenariomanager/actorcontrols/simple_vehicle_control.py +++ b/srunner/scenariomanager/actorcontrols/simple_vehicle_control.py @@ -14,7 +14,7 @@ - Can only consider obstacles in forward facing reaching (i.e. in tight corners obstacles may be ignored). """ -from distutils.util import strtobool +from srunner.tools.util import strtobool import math import carla diff --git a/srunner/scenarios/open_scenario.py b/srunner/scenarios/open_scenario.py index 135375779..181e67d11 100644 --- a/srunner/scenarios/open_scenario.py +++ b/srunner/scenarios/open_scenario.py @@ -11,7 +11,7 @@ from __future__ import print_function -from distutils.util import strtobool +from srunner.tools.util import strtobool import itertools import os import py_trees diff --git a/srunner/tools/openscenario_parser.py b/srunner/tools/openscenario_parser.py index a32b5d6ea..9f0a22039 100644 --- a/srunner/tools/openscenario_parser.py +++ b/srunner/tools/openscenario_parser.py @@ -11,7 +11,7 @@ from __future__ import print_function -from distutils.util import strtobool +from srunner.tools.util import strtobool import re import copy import datetime diff --git a/srunner/tools/util.py b/srunner/tools/util.py new file mode 100644 index 000000000..feffb4b00 --- /dev/null +++ b/srunner/tools/util.py @@ -0,0 +1,14 @@ +def strtobool(val): + """Convert a string representation of truth to true (1) or false (0). + + True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values + are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if + 'val' is anything else. + """ + val = val.lower() + if val in ('y', 'yes', 't', 'true', 'on', '1'): + return 1 + elif val in ('n', 'no', 'f', 'false', 'off', '0'): + return 0 + else: + raise ValueError(f"invalid truth value {val!r}")