Skip to content

Commit

Permalink
add ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
smaierhofer committed Dec 11, 2024
1 parent 5e8a175 commit c38c477
Show file tree
Hide file tree
Showing 214 changed files with 9,470 additions and 4,296 deletions.
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
options: "--check --verbose"
options: "--check --verbose"
2 changes: 1 addition & 1 deletion .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
python-version: "3.11"
- name: flake8 Lint
uses: py-actions/flake8@v2
uses: py-actions/flake8@v2
2 changes: 1 addition & 1 deletion .github/workflows/isort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: isort/isort-action@v1
- uses: isort/isort-action@v1
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.8
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
- Adding existing obstacles again
- Selecting obstacles with set-based prediction
- Bug when editing curved lanelets in the canvas
- lanelet2cr wrong final vertices assignment
- lanelet2cr wrong final vertices assignment
- Deleting unreferenced traffic signs/lights after deleting lanelet
- Map verification/repairing: Checking unique ID of traffic light cycle element
- Consider x-, y-translation for cr2lanelet conversion (and vice versa)
Expand Down Expand Up @@ -172,7 +172,7 @@

### Changed
- Default matplotlib area
- Generalized traffic sign conversion
- Generalized traffic sign conversion
- Lanelet2 to CommonRoad conversion: Generalize traffic sign conversion
- Packaging using poetry

Expand Down Expand Up @@ -213,7 +213,7 @@

### Fixed
- Preventing GUI crash when adding obstacle without existing scenario
- Conversion of straight euler spiral
- Conversion of straight euler spiral
- Floating point error in computation of Cartesian points of lane border in OpenDRIVE2CR conversion
- Various small bug fixes

Expand Down
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# taken from commonroad-dataset-converters
FROM python:3.10 AS build

RUN pip install poetry
WORKDIR /app

COPY crtemplate /app/crtemplate
COPY pyproject.toml /app/
COPY README.md /app/

RUN poetry export -o requirements.txt --without-hashes
RUN poetry build -f wheel

# FROM python:3.10-slim AS app

# RUN apt-get update && apt-get install -y gcc cmake

# COPY --from=build /app/requirements.txt /app/requirements.txt
# RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt && rm /app/requirements.txt

# ARG WHEEL_NAME="commonroad-template-2023.1-py3-non-any.whl"
# COPY --from=build /app/dist/${WHEEL_NAME} /app/
# RUN pip install /app/${WHEEL_NAME} && rm /app/${WHEEL_NAME}

ENTRYPOINT ["crtemplate"]
CMD ["--help"]
1 change: 0 additions & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,3 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

108 changes: 54 additions & 54 deletions README.md

Large diffs are not rendered by default.

30 changes: 22 additions & 8 deletions crdesigner/common/common_file_reader_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def transform_shape(shape: Shape, transformer: Transformer) -> Shape:
"""
shape_copy = copy.deepcopy(shape)
if isinstance(shape_copy, Rectangle) or isinstance(shape_copy, Circle):
shape_copy.center[0], shape_copy.center[1] = transformer.transform(shape_copy.center[0], shape_copy.center[1])
shape_copy.center[0], shape_copy.center[1] = transformer.transform(
shape_copy.center[0], shape_copy.center[1]
)
elif isinstance(shape_copy, Polygon):
for vertex in shape_copy.vertices:
vertex[0], vertex[1] = transformer.transform(vertex[0], vertex[1])
Expand Down Expand Up @@ -49,7 +51,8 @@ def project_planning_problem_set(
planning_problem.initial_state.position[0],
planning_problem.initial_state.position[1],
) = transformer.transform(
planning_problem.initial_state.position[0], planning_problem.initial_state.position[1]
planning_problem.initial_state.position[0],
planning_problem.initial_state.position[1],
)
if isinstance(planning_problem.initial_state.position, Shape):
planning_problem.initial_state.position = transform_shape(
Expand Down Expand Up @@ -116,7 +119,9 @@ def project_lanelet(lanelet: Lanelet, transformer: Transformer):
for right_vertex in lanelet.right_vertices:
right_vertex[0], right_vertex[1] = transformer.transform(right_vertex[0], right_vertex[1])
for center_vertex in lanelet.center_vertices:
center_vertex[0], center_vertex[1] = transformer.transform(center_vertex[0], center_vertex[1])
center_vertex[0], center_vertex[1] = transformer.transform(
center_vertex[0], center_vertex[1]
)
# transform stop line coordinates
if lanelet.stop_line is not None:
lanelet.stop_line.start[0], lanelet.stop_line.start[1] = transformer.transform(
Expand Down Expand Up @@ -147,11 +152,15 @@ def project_obstacles(scenario: Scenario, proj_string_from: str, proj_string_to:
if obstacle.initial_state:
if obstacle.initial_state.position:
if isinstance(obstacle.initial_state.position, ValidTypes.ARRAY):
obstacle.initial_state.position[0], obstacle.initial_state.position[1] = transformer.transform(
obstacle.initial_state.position[0], obstacle.initial_state.position[1]
obstacle.initial_state.position[0], obstacle.initial_state.position[1] = (
transformer.transform(
obstacle.initial_state.position[0], obstacle.initial_state.position[1]
)
)
if isinstance(obstacle.initial_state.position, Shape):
obstacle.initial_state.position = transform_shape(obstacle.initial_state.position, transformer)
obstacle.initial_state.position = transform_shape(
obstacle.initial_state.position, transformer
)

if obstacle.prediction:
if obstacle.prediction.occupancy_set:
Expand All @@ -175,7 +184,10 @@ def project_obstacles(scenario: Scenario, proj_string_from: str, proj_string_to:


def project_scenario_and_pps(
scenario: Scenario, planning_problem_set: PlanningProblemSet, proj_string_from: str, proj_string_to: str
scenario: Scenario,
planning_problem_set: PlanningProblemSet,
proj_string_from: str,
proj_string_to: str,
) -> [Scenario, PlanningProblemSet]:
"""
Function that performs a projection onto the entire scenario and a planning problem set.
Expand All @@ -197,6 +209,8 @@ def project_scenario_and_pps(
project_obstacles(scenario_copy, proj_string_from, proj_string_to)

# project the planning problem set
planning_problem_set = project_planning_problem_set(planning_problem_set, proj_string_from, proj_string_to)
planning_problem_set = project_planning_problem_set(
planning_problem_set, proj_string_from, proj_string_to
)

return scenario_copy, planning_problem_set
4 changes: 3 additions & 1 deletion crdesigner/common/config/config_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def __set__(self, instance, value: T):
:param value: The value to set the attribute to.
"""
if not isinstance(value, self.value_type) and value is not None:
raise TypeError(f"Expected type {self.value_type} for attribute {self.display_name}, got {type(value)}")
raise TypeError(
f"Expected type {self.value_type} for attribute {self.display_name}, got {type(value)}"
)
if self.options is not None:
if value not in self.options:
self._warning_wrong_setting()
Expand Down
8 changes: 6 additions & 2 deletions crdesigner/common/config/general_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ class GeneralConfig(BaseConfig):
# CommonRoad map/scenario author
author = Attribute("Max Mustermann", "CommonRoad map/scenario author")
# CommonRoad scenario/map author affiliation
affiliation = Attribute("Technical University of Munich", "CommonRoad scenario/map author affiliation")
affiliation = Attribute(
"Technical University of Munich", "CommonRoad scenario/map author affiliation"
)
# CommonRoad scenario/map source
source = Attribute("CommonRoad Scenario Designer", "CommonRoad scenario/map source")
# projection used
# additional tags for the benchmark
tags = Attribute("urban", "CommonRoad Tags")
# projection used for the CommonRoad scenario
proj_string_cr = Attribute(pseudo_mercator, "Projection string", "String used for the initialization of projection")
proj_string_cr = Attribute(
pseudo_mercator, "Projection string", "String used for the initialization of projection"
)

LAYOUT = [
[
Expand Down
29 changes: 22 additions & 7 deletions crdesigner/common/config/gui_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def validate_bing_key(key) -> bool:
return True

req = f"http://dev.virtualearth.net/REST/V1/Imagery/Metadata/Aerial?output=json&include=ImageryProviders&key={key}"
headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0"}
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0"
}
try:
with requests.session() as s:
# load cookies otherwise an HTTP error occurs
Expand Down Expand Up @@ -134,10 +136,16 @@ class GuiConfig(BaseConfig):
)
LEGEND: Attribute = Attribute(True, "Legend")
# The key to access bing maps
BING_MAPS_KEY: Attribute = Attribute(value="", display_name="Bing maps key", validation=validate_bing_key)
BING_MAPS_KEY: Attribute = Attribute(
value="", display_name="Bing maps key", validation=validate_bing_key
)
# Username and password to access LDBV maps
LDBV_USERNAME: Attribute = Attribute(value="", display_name="LDBV username", validation=validate_ldbv_credentials)
LDBV_PASSWORD: Attribute = Attribute(value="", display_name="LDBV password", validation=validate_ldbv_credentials)
LDBV_USERNAME: Attribute = Attribute(
value="", display_name="LDBV username", validation=validate_ldbv_credentials
)
LDBV_PASSWORD: Attribute = Attribute(
value="", display_name="LDBV password", validation=validate_ldbv_credentials
)

# projects the lane-network in a way that aligns well with aerial images
pseudo_mercator = Attribute(pseudo_mercator, "Pseudo Mercator")
Expand Down Expand Up @@ -230,7 +238,9 @@ def show_dynamic_obstacles(self) -> bool:
"""
return self.DRAW_DYNAMIC_OBSTACLES

def get_undetailed_params(self, lanelet_count: int = 0, traffic_sign_count: int = 0) -> Optional[LaneletParams]:
def get_undetailed_params(
self, lanelet_count: int = 0, traffic_sign_count: int = 0
) -> Optional[LaneletParams]:
"""
If the detailed display is enables checks if the scenario should be shown undetailed to gain performance.
Expand All @@ -255,7 +265,9 @@ def get_undetailed_params(self, lanelet_count: int = 0, traffic_sign_count: int
draw_line_markings=False,
)

def resize_lanelet_network_when_zoom(self, lanelet_count: int, traffic_sign_count: int, x: float, y: float) -> bool:
def resize_lanelet_network_when_zoom(
self, lanelet_count: int, traffic_sign_count: int, x: float, y: float
) -> bool:
"""
Checks wether the lanelet network should be resizued based if the lanelet is big or the zoom level
Expand Down Expand Up @@ -310,7 +322,10 @@ def enabled_curved_lanelet(self):
def sub_curved(self, method_to_sub=None):
for list_layout in gui_config.LAYOUT:
for attribute in list_layout:
if isinstance(attribute, Attribute) and attribute.display_name == "Enable editing of curved lanelets":
if (
isinstance(attribute, Attribute)
and attribute.display_name == "Enable editing of curved lanelets"
):
attribute.subscribe(method_to_sub)
return

Expand Down
41 changes: 32 additions & 9 deletions crdesigner/common/config/lanelet2_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class Lanelet2Config(BaseConfig):
)

autoware = Attribute(
False, "Autoware", "Boolean indicating whether the conversion " "should be autoware compatible"
False,
"Autoware",
"Boolean indicating whether the conversion " "should be autoware compatible",
)

use_local_coordinates = Attribute(
False, "Use local coordinates", "Boolean indicating whether local coordinates should be added"
False,
"Use local coordinates",
"Boolean indicating whether local coordinates should be added",
)

supported_countries = [TrafficSignIDGermany, TrafficSignIDZamunda, TrafficSignIDUsa]
Expand All @@ -34,7 +38,17 @@ class Lanelet2Config(BaseConfig):
}

supported_lanelet2_subtypes = Attribute(
["urban", "country", "highway", "interstate", "busLane", "bicycleLane", "exitRamp", "sidewalk", "crosswalk"],
[
"urban",
"country",
"highway",
"interstate",
"busLane",
"bicycleLane",
"exitRamp",
"sidewalk",
"crosswalk",
],
"Supported lanelet2 subtypes",
"Lanelet2 subtypes that are available in commonroad",
)
Expand All @@ -43,10 +57,14 @@ class Lanelet2Config(BaseConfig):

# lanelet2cr
node_distance_tolerance = Attribute(
0.01, "Node distance tolerance", "Value of the tolerance (in meters) for which we mark nodes as equal"
0.01,
"Node distance tolerance",
"Value of the tolerance (in meters) for which we mark nodes as equal",
)

priority_signs = Attribute(["PRIORITY", "RIGHT_OF_WAY"], "Priority signs", "List of priority signs")
priority_signs = Attribute(
["PRIORITY", "RIGHT_OF_WAY"], "Priority signs", "List of priority signs"
)

adjacent_way_distance_tolerance = Attribute(
0.05, "Adjacent way distance tolerance", "Threshold indicating adjacent way"
Expand All @@ -57,7 +75,9 @@ class Lanelet2Config(BaseConfig):
left_driving = Attribute(False, "Left Driving", "Map describes left driving system")

adjacencies = Attribute(
True, "Adjacencies", "Detect left and right adjacencies of lanelets if they do not share a common way"
True,
"Adjacencies",
"Detect left and right adjacencies of lanelets if they do not share a common way",
)

translate = Attribute(
Expand All @@ -70,7 +90,8 @@ class Lanelet2Config(BaseConfig):
allowed_tags = Attribute(
["type", "subtype", "one_way", "virtual", "location", "bicycle", "highway"],
"Allowed Tags",
"Lanelet tags which are considered for conversion. " "Lanelets with other tags are not converted.",
"Lanelet tags which are considered for conversion. "
"Lanelets with other tags are not converted.",
)

eps2_values = Attribute(
Expand All @@ -88,13 +109,15 @@ class Lanelet2Config(BaseConfig):
chaikins_initial_refinements = Attribute(
5,
"Initial CCS Refinements",
"Number of initial refinements of chaikins corner cutting algorithms " "for curvilinear coordinate system.",
"Number of initial refinements of chaikins corner cutting algorithms "
"for curvilinear coordinate system.",
)

chaikins_repeated_refinements = Attribute(
10,
"Max. Polyline Resampling Step",
"Number of repeated refinements of chaikins corner cutting algorithms " "for curvilinear coordinate system.",
"Number of repeated refinements of chaikins corner cutting algorithms "
"for curvilinear coordinate system.",
)

resampling_initial_step = Attribute(
Expand Down
Loading

0 comments on commit c38c477

Please sign in to comment.