Skip to content

Commit

Permalink
Don't depend on distutils
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wentasah committed Oct 16, 2024
1 parent 7758d06 commit 272eda3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
## Upcoming
* Improvements to the CarlaDataProvider:
- Added `spawn_actor` for a blueprint based actor creation similar to `World.spawn_actor`
* Allow using with Python 3.12

## CARLA ScenarioRunner 0.9.15
### :rocket: New Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.util import strtobool
import math

import carla
Expand Down
2 changes: 1 addition & 1 deletion srunner/scenarios/open_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from __future__ import print_function

from distutils.util import strtobool
from srunner.util import strtobool
import itertools
import os
import py_trees
Expand Down
2 changes: 1 addition & 1 deletion srunner/tools/openscenario_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from __future__ import print_function

from distutils.util import strtobool
from srunner.util import strtobool
import re
import copy
import datetime
Expand Down
14 changes: 14 additions & 0 deletions srunner/util.py
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit 272eda3

Please sign in to comment.