Skip to content

Commit

Permalink
Switch to ruff for python fomatting / linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ozaq committed Apr 25, 2024
1 parent 561aaf0 commit 7c31d21
Show file tree
Hide file tree
Showing 54 changed files with 214 additions and 236 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
with:
python-version: "3.12"
- name: Install dependencies
run: pip install black==24.4.0 isort==5.13.2 jupyter-black==0.3.4
run: pip install ruff

- name: Run checks
run: ./scripts/ci/check_format.sh
Expand Down
2 changes: 1 addition & 1 deletion container/perf-measurement/container_perf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def build_jupedsim():
def run_test(test, args, build_dir, result_dir):
test_env = os.environ.copy()
test_env["PYTHONPATH"] = (
f"/src/python_modules/jupedsim:/src/python_modules/jupedsim_visualizer:/build/lib"
"/src/python_modules/jupedsim:/src/python_modules/jupedsim_visualizer:/build/lib"
)

perf_data_file_name = f"{test}.perf.data"
Expand Down
3 changes: 1 addition & 2 deletions examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import pathlib
import sys

from shapely import GeometryCollection, Polygon

import jupedsim as jps
from shapely import GeometryCollection, Polygon


def main():
Expand Down
7 changes: 2 additions & 5 deletions examples/example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import pathlib
import sys

from shapely import GeometryCollection, Polygon

import jupedsim as jps
from shapely import GeometryCollection, Polygon


def main():
Expand All @@ -16,9 +15,7 @@ def main():
jps.set_warning_callback(lambda x: print(x))
jps.set_error_callback(lambda x: print(x))

area = GeometryCollection(
Polygon([(0, 0), (100, 0), (100, 100), (0, 100)])
)
area = GeometryCollection(Polygon([(0, 0), (100, 0), (100, 100), (0, 100)]))

simulation = jps.Simulation(
model=jps.CollisionFreeSpeedModel(),
Expand Down
4 changes: 1 addition & 3 deletions examples/example3.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def main():
]
)
queue = simulation.get_stage(stage_id)
exit = simulation.add_exit_stage(
[(99, 40), (99, 60), (100, 60), (100, 40)]
)
exit = simulation.add_exit_stage([(99, 40), (99, 60), (100, 60), (100, 40)])

journey = jps.JourneyDescription([stage_id, exit])
journey.set_transition_for_stage(
Expand Down
4 changes: 1 addition & 3 deletions examples/example4.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def main():
exit_left = simulation.add_exit_stage(
[(-24, -8), (-24, 8), (-23, 8), (-23, -8)]
)
exit_top = simulation.add_exit_stage(
[(-8, 24), (8, 24), (8, 23), (-8, 23)]
)
exit_top = simulation.add_exit_stage([(-8, 24), (8, 24), (8, 23), (-8, 23)])
exit_right = simulation.add_exit_stage(
[(24, -8), (24, 8), (23, 8), (23, -8)]
)
Expand Down
4 changes: 1 addition & 3 deletions examples/example5.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def main():
),
)

exit_top = simulation.add_exit_stage(
[(-2, 24), (2, 24), (2, 25), (-2, 25)]
)
exit_top = simulation.add_exit_stage([(-2, 24), (2, 24), (2, 25), (-2, 25)])
exit_right = simulation.add_exit_stage(
[(34, -2), (34, 2), (35, 2), (35, -2)]
)
Expand Down
3 changes: 1 addition & 2 deletions examples/example6.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import pathlib
import sys

import shapely

import jupedsim as jps
import shapely


def main():
Expand Down
6 changes: 2 additions & 4 deletions notebooks/corner-SocialForce.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@
},
"outputs": [],
"source": [
"from shapely import GeometryCollection, Polygon, to_wkt\n",
"import pathlib\n",
"\n",
"import jupedsim as jps\n",
"import pedpy\n",
"import pandas as pd\n",
"import numpy as np\n",
"from numpy.random import normal # normal distribution of free movement speed\n",
"import matplotlib.pyplot as plt"
"from shapely import Polygon"
]
},
{
Expand Down
6 changes: 2 additions & 4 deletions notebooks/corner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@
},
"outputs": [],
"source": [
"from shapely import GeometryCollection, Polygon, to_wkt\n",
"import pathlib\n",
"\n",
"import jupedsim as jps\n",
"import pedpy\n",
"import pandas as pd\n",
"import numpy as np\n",
"from numpy.random import normal # normal distribution of free movement speed\n",
"import matplotlib.pyplot as plt"
"from shapely import Polygon"
]
},
{
Expand Down
18 changes: 7 additions & 11 deletions notebooks/double-bottleneck.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
},
"outputs": [],
"source": [
"from shapely import GeometryCollection, Polygon, to_wkt\n",
"import pathlib\n",
"\n",
"import jupedsim as jps\n",
"from numpy.random import normal # normal distribution of free movement speed\n",
"import pedpy\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"import pedpy\n",
"from numpy.random import normal # normal distribution of free movement speed\n",
"from shapely import GeometryCollection, Polygon"
]
},
{
Expand Down Expand Up @@ -548,9 +548,7 @@
"corridor_narrow = Polygon([(10, 4.6), (28, 4.6), (28, 5.4), (10, 5.4)])\n",
"area_narrow = GeometryCollection(corridor_narrow.union(room1.union(room2)))\n",
"walkable_area_narrow = pedpy.WalkableArea(area_narrow.geoms[0])\n",
"pedpy.plot_walkable_area(walkable_area=walkable_area_narrow).set_aspect(\n",
" \"equal\"\n",
")"
"pedpy.plot_walkable_area(walkable_area=walkable_area_narrow).set_aspect(\"equal\")"
]
},
{
Expand Down Expand Up @@ -633,9 +631,7 @@
"source": [
"from jupedsim.internal.notebook_utils import animate, read_sqlite_file\n",
"\n",
"trajectory_data_narrow, walkable_area = read_sqlite_file(\n",
" trajectory_file_narrow\n",
")\n",
"trajectory_data_narrow, walkable_area = read_sqlite_file(trajectory_file_narrow)\n",
"animate(trajectory_data_narrow, walkable_area)"
]
},
Expand Down
14 changes: 7 additions & 7 deletions notebooks/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from pedpy import plot_walkable_area, WalkableArea\n",
"from pedpy import WalkableArea, plot_walkable_area\n",
"\n",
"plot_walkable_area(walkable_area=WalkableArea(geometry)).set_aspect(\"equal\")\n",
"plt.show()"
Expand Down Expand Up @@ -188,7 +188,7 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from pedpy import plot_measurement_setup, WalkableArea, MeasurementArea\n",
"from pedpy import MeasurementArea, WalkableArea, plot_measurement_setup\n",
"\n",
"# We will use PedPy's plotting functionality, but it has no concept of exits\n",
"# hence we will show the exit as measurement area\n",
Expand Down Expand Up @@ -236,9 +236,7 @@
" header=None,\n",
" names=[\"id\", \"frame\", \"x\", \"y\", \"z\"],\n",
")\n",
"start_positions = experiment_data[experiment_data.frame == 0][\n",
" [\"x\", \"y\"]\n",
"].values"
"start_positions = experiment_data[experiment_data.frame == 0][[\"x\", \"y\"]].values"
]
},
{
Expand All @@ -263,9 +261,10 @@
"metadata": {},
"outputs": [],
"source": [
"import jupedsim as jps\n",
"import pathlib\n",
"\n",
"import jupedsim as jps\n",
"\n",
"trajectory_file = \"bottleneck_cfsm.sqlite\"\n",
"simulation_cfsm = jps.Simulation(\n",
" model=jps.CollisionFreeSpeedModel(),\n",
Expand Down Expand Up @@ -429,9 +428,10 @@
},
"outputs": [],
"source": [
"import pedpy\n",
"import pathlib\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import pedpy\n",
"\n",
"experimental_trajectories = pedpy.load_trajectory(\n",
" trajectory_file=pathlib.Path(\"demo-data/bottleneck/040_c_56_h-.txt\")\n",
Expand Down
24 changes: 10 additions & 14 deletions notebooks/journey.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@
},
"outputs": [],
"source": [
"from shapely import Polygon\n",
"import pathlib\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"import jupedsim as jps\n",
"import pedpy\n",
"from pedpy.column_identifier import ID_COL, FRAME_COL\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pedpy\n",
"from matplotlib.patches import Circle\n",
"from shapely import Polygon\n",
"\n",
"%matplotlib inline"
]
Expand Down Expand Up @@ -112,9 +111,7 @@
"plt.fill(x, y, alpha=0.1)\n",
"plt.plot(x, y, color=\"white\")\n",
"centroid = distribution_polygon.centroid\n",
"plt.text(\n",
" centroid.x, centroid.y, \"Start\", ha=\"center\", va=\"center\", fontsize=10\n",
")\n",
"plt.text(centroid.x, centroid.y, \"Start\", ha=\"center\", va=\"center\", fontsize=10)\n",
"\n",
"x, y = Polygon(exit_polygon).exterior.xy\n",
"plt.fill(x, y, alpha=0.1)\n",
Expand All @@ -132,7 +129,7 @@
")\n",
"ax.add_patch(circle)\n",
"ax.annotate(\n",
" f\"Switch\",\n",
" \"Switch\",\n",
" (switch_point[0], switch_point[1]),\n",
" textcoords=\"offset points\",\n",
" xytext=(-5, -15),\n",
Expand Down Expand Up @@ -200,9 +197,7 @@
"metadata": {},
"outputs": [],
"source": [
"def shortest_path(\n",
" simulation: jps.Simulation, switch_id, waypoint_ids, exit_id\n",
"):\n",
"def shortest_path(simulation: jps.Simulation, switch_id, waypoint_ids, exit_id):\n",
" \"\"\"Build a journey with fixed transitions for a given simulation.\"\"\"\n",
"\n",
" journey = jps.JourneyDescription([switch_id, *waypoint_ids, exit_id])\n",
Expand Down Expand Up @@ -467,9 +462,10 @@
"metadata": {},
"outputs": [],
"source": [
"from scipy import stats\n",
"from typing import Tuple\n",
"\n",
"import numpy.typing as npt\n",
"from scipy import stats\n",
"\n",
"\n",
"def calculate_density_average_classic(\n",
Expand Down Expand Up @@ -512,7 +508,6 @@
"\n",
"\n",
"def plot_classical_density_profile(data, walkable_area, name, dx, rho_max):\n",
" vmax = rho_max\n",
" geominX, geominY, geomaxX, geomaxY = walkable_area.bounds\n",
" title = f\"<b>{name}</b>\"\n",
" fig = make_subplots(rows=1, cols=1, subplot_titles=([title]))\n",
Expand Down Expand Up @@ -564,6 +559,7 @@
"outputs": [],
"source": [
"import math\n",
"\n",
"import plotly.graph_objects as go\n",
"\n",
"dx = 0.5\n",
Expand Down
11 changes: 5 additions & 6 deletions notebooks/lane-formation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"outputs": [],
"source": [
"import pathlib\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"import jupedsim as jps\n",
"from shapely import Polygon\n",
"import pedpy\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pedpy\n",
"from shapely import Polygon\n",
"\n",
"%matplotlib inline"
]
Expand Down Expand Up @@ -170,8 +170,7 @@
" simulation.add_exit_stage(exit_polygon_right),\n",
" ]\n",
" journeys = [\n",
" simulation.add_journey(jps.JourneyDescription([exit]))\n",
" for exit in exits\n",
" simulation.add_journey(jps.JourneyDescription([exit])) for exit in exits\n",
" ]\n",
"\n",
" # first group\n",
Expand Down
11 changes: 4 additions & 7 deletions notebooks/motivation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
},
"outputs": [],
"source": [
"from shapely import Polygon\n",
"import pathlib\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"import jupedsim as jps\n",
"import pedpy\n",
"import matplotlib.pyplot as plt\n",
"import pedpy\n",
"from shapely import Polygon\n",
"\n",
"%matplotlib inline"
]
Expand Down Expand Up @@ -82,9 +81,7 @@
" plt.fill(x, y, alpha=0.1)\n",
" plt.plot(x, y, color=\"white\")\n",
" centroid = Polygon(area).centroid\n",
" plt.text(\n",
" centroid.x, centroid.y, name, ha=\"center\", va=\"center\", fontsize=8\n",
" )"
" plt.text(centroid.x, centroid.y, name, ha=\"center\", va=\"center\", fontsize=8)"
]
},
{
Expand Down
19 changes: 7 additions & 12 deletions notebooks/queues_waiting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@
},
"outputs": [],
"source": [
"from shapely import from_wkt, Polygon, intersection\n",
"import pedpy\n",
"import pathlib\n",
"\n",
"import jupedsim as jps\n",
"import matplotlib.pyplot as plt\n",
"import pedpy\n",
"from matplotlib.patches import Circle\n",
"import pathlib\n",
"import pandas as pd\n",
"import numpy as np\n",
"from numpy.random import normal # normal distribution of free movement speed"
"from numpy.random import normal # normal distribution of free movement speed\n",
"from shapely import Polygon, from_wkt, intersection"
]
},
{
Expand Down Expand Up @@ -577,8 +575,7 @@
"gate_offsets = [0 for i in range(number_of_gates)]\n",
"\n",
"while (\n",
" simulation.agent_count() > 0\n",
" and simulation.iteration_count() < 5 * 60 * 100\n",
" simulation.agent_count() > 0 and simulation.iteration_count() < 5 * 60 * 100\n",
"):\n",
" for i in range(number_of_gates):\n",
" if queue_gates[i].count_enqueued() == 0:\n",
Expand Down Expand Up @@ -808,9 +805,7 @@
"source": [
"from jupedsim.internal.notebook_utils import animate, read_sqlite_file\n",
"\n",
"trajectory_data_uneven, walkable_area = read_sqlite_file(\n",
" trajectory_file_uneven\n",
")\n",
"trajectory_data_uneven, walkable_area = read_sqlite_file(trajectory_file_uneven)\n",
"animate(trajectory_data_uneven, walkable_area, every_nth_frame=5)"
]
},
Expand Down
Loading

0 comments on commit 7c31d21

Please sign in to comment.