diff --git a/pyproject.toml b/pyproject.toml index d4c2b03..3a0ce22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -265,6 +265,8 @@ select = [ # "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions # "PTH", + # Ruff-specific rules => Fewer bugs and cleaner code + # "RUF", # flake8-self => No access to private members from outside # "SLF", # pyupgrade => Modern syntax for the targeted Python version @@ -559,6 +561,8 @@ select = [ "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions "PTH", + # Ruff-specific rules => Fewer bugs and cleaner code + "RUF", # flake8-self => No access to private members from outside "SLF", # flake8-print => no `print()` @@ -576,11 +580,20 @@ extend-ignore = [ "PT023", # An `elif` after a `return` keeps a case distinction together. "RET505", + # Some "# noqa" comments are only for `flake8`, which `ruff` cannot know. + "RUF100", # TODOs need neither an author nor an issue. "TD002", "TD003", ] +# Codes only `flake8` knows, kept in "# noqa" comments +external = [ + "B902", + "DOC", +] + + [tool.ruff.lint.per-file-ignores] # Top-levels of a sub-packages are intended to import a lot. diff --git a/src/velofy/configuration.py b/src/velofy/configuration.py index cc32629..1660de8 100644 --- a/src/velofy/configuration.py +++ b/src/velofy/configuration.py @@ -40,19 +40,19 @@ class Config: # Side lengths (in meters) for which pixel grids are created. # They are the basis for the aggregated demand forecasts. - GRID_SIDE_LENGTHS = [707, 1000, 1414] + GRID_SIDE_LENGTHS = (707, 1000, 1414) # Time steps (in minutes) used to aggregate the # individual orders into time series. - TIME_STEPS = [60] + TIME_STEPS = (60,) # Training horizons (in full weeks) used to train the forecasting models. # For now, we only use 7 and 8 weeks as that was the best performing in # a previous study (note:4f79e8fa). - TRAIN_HORIZONS = [7, 8] + TRAIN_HORIZONS = (7, 8) # The demand forecasting methods used in the simulations. - FORECASTING_METHODS = ["hets", "rtarima"] + FORECASTING_METHODS = ("hets", "rtarima") # Colors for the visualizations ins `folium`. RESTAURANT_COLOR = "red" diff --git a/src/velofy/db/pixels.py b/src/velofy/db/pixels.py index 981d821..61c5ecf 100644 --- a/src/velofy/db/pixels.py +++ b/src/velofy/db/pixels.py @@ -156,7 +156,7 @@ class Pixel(meta.Base): """Shortcut to the `.city.map` object.""" return self.grid.city.map - def draw( # noqa:C901,PLR0912 + def draw( self, *, restaurants: bool = True, diff --git a/tests/console/test_gridify.py b/tests/console/test_gridify.py index 660edb1..f730951 100644 --- a/tests/console/test_gridify.py +++ b/tests/console/test_gridify.py @@ -44,7 +44,7 @@ def test_two_pixels_with_two_addresses( side_length = max(city.total_x // 2, city.total_y // 2) + 1 # Hack the configuration regarding the grids to be created. - monkeypatch.setattr(velofy.config, "GRID_SIDE_LENGTHS", [side_length]) + monkeypatch.setattr(velofy.config, "GRID_SIDE_LENGTHS", (side_length,)) result = cli.invoke(gridify.gridify) diff --git a/tests/db/test_grids.py b/tests/db/test_grids.py index a0f7e30..9561d43 100644 --- a/tests/db/test_grids.py +++ b/tests/db/test_grids.py @@ -83,9 +83,7 @@ class TestGridification: all considered `Order.pickup_address` attributes for some orders. """ mock = mocker.Mock() - query = ( - mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501 - ) + query = mock.query.return_value.join.return_value.filter.return_value.all monkeypatch.setattr(db, "session", mock) return query diff --git a/tests/db/test_orders.py b/tests/db/test_orders.py index 7ad31f7..3691cdd 100644 --- a/tests/db/test_orders.py +++ b/tests/db/test_orders.py @@ -1150,7 +1150,7 @@ class TestProperties: @pytest.mark.db @pytest.mark.no_cover -def test_make_random_orders( # noqa:C901 +def test_make_random_orders( db_session, make_address, make_courier, diff --git a/tests/db/test_pixels.py b/tests/db/test_pixels.py index bfba927..636328b 100644 --- a/tests/db/test_pixels.py +++ b/tests/db/test_pixels.py @@ -121,9 +121,7 @@ class TestProperties: def _restaurants_mock(self, mocker, monkeypatch, restaurant): """A `Mock` whose `.return_value` is `[restaurant]`.""" mock = mocker.Mock() - query = ( - mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501 - ) + query = mock.query.return_value.join.return_value.filter.return_value.all query.return_value = [restaurant] monkeypatch.setattr(db, "session", mock) diff --git a/tests/forecasts/test_models.py b/tests/forecasts/test_models.py index 30b3f35..ce8173a 100644 --- a/tests/forecasts/test_models.py +++ b/tests/forecasts/test_models.py @@ -1,5 +1,7 @@ """Tests for the `velofy.forecasts.models` sub-package.""" +import typing as t + import pandas as pd import pytest @@ -45,7 +47,7 @@ class TestGenericForecastingModelProperties: assert isinstance(result, str) - unique_model_names = set() + unique_model_names: t.ClassVar[set[str]] = set() def test_each_model_has_a_unique_name(self, model_cls, order_history): """The `*Model.name` values must be unique across all `*Model`s. diff --git a/tests/forecasts/timify/test_aggregate_orders.py b/tests/forecasts/timify/test_aggregate_orders.py index 534aee5..9b625bf 100644 --- a/tests/forecasts/timify/test_aggregate_orders.py +++ b/tests/forecasts/timify/test_aggregate_orders.py @@ -26,9 +26,7 @@ class TestAggregateOrders: Note: This fixture also exists in `tests.db.test_grids`. """ mock = mocker.Mock() - query = ( - mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501 - ) + query = mock.query.return_value.join.return_value.filter.return_value.all monkeypatch.setattr(db_session, "query", mock.query) return query