From db40fb720e9afb0236a27676e87a8bdd3f334891 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Fri, 26 Apr 2024 13:37:13 +0200 Subject: [PATCH] Workflow improvements and code quality passing (#1052) * CI: Checkout v4 and unit tests name correction * Small tweaks to ensure Code Quality passes --------- Co-authored-by: glopezdiest <58212725+glopezdiest@users.noreply.github.com> --- .github/workflows/static_code_check.yml | 4 ++-- .github/workflows/unit_test.yml | 4 ++-- srunner/scenariomanager/carla_data_provider.py | 4 +++- .../scenarioatomics/atomic_behaviors.py | 10 +++++----- srunner/scenarios/open_scenario.py | 6 +++--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/static_code_check.yml b/.github/workflows/static_code_check.yml index 2d452d712..0cf08f377 100644 --- a/.github/workflows/static_code_check.yml +++ b/.github/workflows/static_code_check.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Dependencies run: | @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Dependencies run: | diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index bfddce78a..3946e2c7f 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -1,4 +1,4 @@ -name: Static Code Analysis +name: Unit Tests on: push: @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Dependencies run: | diff --git a/srunner/scenariomanager/carla_data_provider.py b/srunner/scenariomanager/carla_data_provider.py index fccc1555a..f0a3495cd 100644 --- a/srunner/scenariomanager/carla_data_provider.py +++ b/srunner/scenariomanager/carla_data_provider.py @@ -303,8 +303,10 @@ def find_weather_presets(): """ Get weather presets from CARLA """ + def name(string): + return ' '.join(m.group(0) for m in rgx.finditer(string)) + rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)') - name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x)) presets = [x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x)] return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets] diff --git a/srunner/scenariomanager/scenarioatomics/atomic_behaviors.py b/srunner/scenariomanager/scenarioatomics/atomic_behaviors.py index f62e1aa94..5bac4339e 100644 --- a/srunner/scenariomanager/scenarioatomics/atomic_behaviors.py +++ b/srunner/scenariomanager/scenarioatomics/atomic_behaviors.py @@ -797,9 +797,9 @@ def initialise(self): # At the moment everything besides "shortest" will use the CARLA GlobalPlanner grp = CarlaDataProvider.get_global_route_planner() route = [] - for i, _ in enumerate(carla_route_elements): - if carla_route_elements[i][1] == "shortest": - route.append(carla_route_elements[i][0]) + for i, element in enumerate(carla_route_elements): + if element[1] == "shortest": + route.append(element[0]) else: if i == 0: mmap = CarlaDataProvider.get_map() @@ -812,12 +812,12 @@ def initialise(self): waypoint = ego_next_wp.transform.location else: waypoint = carla_route_elements[i - 1][0].location - waypoint_next = carla_route_elements[i][0].location + waypoint_next = element[0].location try: interpolated_trace = grp.trace_route(waypoint, waypoint_next) except networkx.NetworkXNoPath: print("WARNING: No route from {} to {} - Using direct path instead".format(waypoint, waypoint_next)) - route.append(carla_route_elements[i][0]) + route.append(element[0]) continue for wp_tuple in interpolated_trace: # The router sometimes produces points that go backward, or are almost identical diff --git a/srunner/scenarios/open_scenario.py b/srunner/scenarios/open_scenario.py index c7f58d067..135375779 100644 --- a/srunner/scenarios/open_scenario.py +++ b/srunner/scenarios/open_scenario.py @@ -392,9 +392,9 @@ def _create_behavior(self): for actor in sequence.iter("Actors"): for entity in actor.iter("EntityRef"): entity_name = entity.attrib.get('entityRef', None) - for k, _ in enumerate(joint_actor_list): - if (joint_actor_list[k] and - entity_name == joint_actor_list[k].attributes['role_name']): + for k, actor in enumerate(joint_actor_list): + if (actor and + entity_name == actor.attributes['role_name']): actor_ids.append(k) break