Commit graph

511 commits

Author SHA1 Message Date
8b5e66d70b
Install only nox and pre-commit in CI
All checks were successful
CI / Tests (test-types) (push) Successful in 2m3s
CI / Tests (test) (push) Successful in 2m6s
CI / Tests (test-with-3.15) (push) Successful in 2m10s
CI / Lint (push) Successful in 2m20s
CI / Tests (test-with-3.13) (push) Successful in 2m21s
The `nox` sessions install `velofy` and its dependencies themselves;
so, a full `uv sync` only duplicated that work.
2026-12-03 01:12:31 +01:00
53746966ac
Cache uv between CI runs
All jobs restore built wheels (e.g., `rpy2`) and the Python versions
instead of building or fetching them again.

Only the "lint" job saves the cache, pruned to what is expensive to rebuild,
and only when its key changed; so, five jobs do not compress the same archive
in parallel, and unchanged runs skip the 15s of packing.
2026-12-03 01:12:30 +01:00
e1cdac4cfa
Run the CI checks in parallel jobs
The test sessions run as a matrix, each with its own database.

This also adds the "test-with" sessions to CI;
so, the setup installs all `SUPPORTED_PYTHONS` via `uv`,
as `nox` would otherwise pick the system Python 3.13,
which lacks the headers to build `rpy2`.
2026-12-03 01:12:29 +01:00
49276bb9cf
Pull the CI setup into a composite action
The upcoming parallel jobs share it.
2026-12-03 01:12:28 +01:00
cc45b78e5d
Rename the CI job and add a timeout
The version in the name broke the required status check
when 3.14 became the `MAIN_PYTHON`.

The timeout ensures the CI server stays ready
even when something goes badly wrong.
2026-12-03 01:12:28 +01:00
9be63c3fef
Merge branch 'python-3.14' into develop
All checks were successful
CI / Checks (Python 3.14) (push) Successful in 2m43s
Reviewed-on: #20
2026-12-02 22:30:07 +01:00
2a64958a93
Make Python 3.14 the MAIN_VERSION
All checks were successful
CI / Checks (Python 3.14) (push) Successful in 2m46s
`requires-python` stays at ">=3.13"; so, `uv.lock` is unchanged
and 3.13 is tested with the "test-with" session.
2026-12-02 21:54:16 +01:00
df53ce7bc4
Pin MAIN_PYTHON in the "init-project" session
Otherwise, `uv` creates ".venv" with the newest installed Python.
2026-12-02 21:49:17 +01:00
67917ae3f6
Type check against the oldest Python version
Without a configured version, `mypy` and `pyright`
check against the Python that runs them.

With `MAIN_PYTHON` at 3.14, they would accept
`stdlib` APIs and `typing` features new in 3.14.

Yet, `requires-python` promises 3.13;
so, the type checkers must flag such code.

`black` and `ruff` already target 3.13 for the same reason.
2026-12-02 21:42:06 +01:00
b947337bd1
Remove flake8-return
It crashes on Python 3.14 (`ast.NameConstant` is gone) and is unmaintained.

`ruff` covers its rules.
2026-12-02 21:39:21 +01:00
80d2573f0d
Remove flake8-pie
It crashes on Python 3.14 (`ast.Str` is gone) and is unmaintained.

`ruff` covers its rules.
2026-12-02 21:27:27 +01:00
5609e8ec6e
Test with Python 3.14 and 3.15
The new "test-with" session runs the test suite with non-main Python versions;
yet, `MAIN_PYTHON` stays at 3.13
2026-12-02 17:43:05 +01:00
a85d426b6e
Merge branch 'alembic-api' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
Reviewed-on: #19
2026-12-02 14:05:17 +01:00
35d0c7b409
Test reading the database revision
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m50s
In the "sequentially" variant of the test database,
`current_db_revision()` must return the head of the migrations;
in the "all_at_once" variant, there is no version table.
2026-12-02 13:56:04 +01:00
2add322a25
Test the revision lock of the CLI stages
The `@db_revision` decorator no longer skips its check under `TESTING`.

The tests replace `current_db_revision()` with the revision they need.
2026-12-02 13:42:04 +01:00
eb059c1ea5
Read the database revision with the Alembic API
The `@db_revision` decorator no longer runs `alembic current` in a subprocess,
which only worked from the project folder and reported any failure as a wrong revision.

Also, its docstring now explains that it locks completed stages of the data pipeline.
2026-12-02 13:35:37 +01:00
ef7b41e675
Merge branch 'directions-json' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
Reviewed-on: #18
2026-12-02 11:43:02 +01:00
664dccee02
Store the directions of paths as JSON arrays
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m46s
The data migration converts the 42 existing rows
from a JSON-encoded string into a JSON array.
2026-12-02 11:23:01 +01:00
bbd7d6a279
Store Path._directions as a JSON array
The column is of type `JSON`,
but the code stored a JSON-encoded string in it;
so, the data was encoded twice.

A later data migration converts the existing rows.
2026-12-02 09:03:49 +01:00
2b1dd6af35
Merge branch 'sqlalchemy-select' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m46s
Reviewed-on: #17
2026-12-02 00:38:24 +01:00
fc185fa3c0
Create the engine and the session on first use
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
The global `db.session` is now a `scoped_session`,
like, for example, in Flask-SQLAlchemy.

Importing the package no longer creates an engine;
so, the placeholder for the tests is obsolete.

The `db_session` fixture replaces `db.session` with `monkeypatch`
such that it is reset after each test.

Tests without the fixture get a placeholder that fails loudly
instead of opening a real session,
which would block the `DROP SCHEMA` at the end of the test run.
2026-12-02 00:23:41 +01:00
9d98021b11
Request the db_session fixture
The test queries the database but relied on the
global `db.session` that the previous test had left behind.
2026-12-02 00:19:51 +01:00
bc2e3f439d
Count with .scalar_one() in velofy.console.gridify
A `COUNT` always returns exactly one row; `.scalar_one()`
is typed as `int` and is used for all other counts as well.
2026-12-01 23:51:00 +01:00
185a37f7d4
Query with select() in the forecasting models
`Session.query()` is the legacy API in SQLAlchemy 2.x.

`.one_or_none()` expresses that the unique constraint
on the five filtered columns allows at most one cached `Forecast`.
2026-12-01 23:48:36 +01:00
2eb6b5769f
Query with select() in Pixel
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The addresses with restaurants are now selected with a subquery in one statement.

The `_restaurants_mock` fixture mocks the new call chain.
2026-12-01 23:45:35 +01:00
0dc3e11a63
Query with select() in Customer
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The delivery and pickup addresses are now selected with subqueries in one statement each.
2026-12-01 23:39:44 +01:00
54e21109e7
Query with select() in Restaurant
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The delivery addresses are now selected with a subquery in one statement.
2026-12-01 23:37:57 +01:00
9d2a4139b7
Query with select() in City
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The addresses with restaurants are now selected with a subquery in one statement.
2026-12-01 23:35:21 +01:00
53e1859ee8
Query with select() in Grid and Path
`Session.query()` is the legacy API in SQLAlchemy 2.x.

Unlike `Query`, `select()` does not deduplicate single entities from a `JOIN`;
so, `Grid.gridify()` calls `.unique()` explicitly.

The `addresses_mock` fixtures mock the new call chain.
2026-12-01 23:29:39 +01:00
1f5a39f83a
Query with select() in velofy.console
`Session.query()` is the legacy API in SQLAlchemy 2.x.
2026-12-01 23:21:00 +01:00
c1f04c65aa
Count rows with select() in the tests
`Session.query()` is the legacy API in SQLAlchemy 2.x.
2026-12-01 23:17:57 +01:00
455af6dfdb
Merge branch 'orm-review' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m46s
Reviewed-on: #16
2026-12-01 23:06:03 +01:00
248c1ae600
Ignore the foreign keys into the original data
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
The migrations create foreign keys from the `CLEAN_SCHEMA`
into the `ORIGINAL_SCHEMA` to ensure the cleaned data still
refer to the original data.

The ORM models do not know the original tables.
Also, print the `diff` as indented JSON.
2026-12-01 22:58:01 +01:00
25ed8c744b
Recreate checks stored by an old PostgreSQL version
Before version 14, PostgreSQL stored `EXTRACT(...)` as `date_part(...)`,
and the rendering of `IN (...)` changed as well.

The checks created in 2021 express the same rules as the ORM models
but render differently. See the docstring of the migration for details.
2026-12-01 22:56:12 +01:00
69d3be4a53
Rename constraints to follow the naming convention
Earlier migrations named some constraints without `op.f()`,
a column rename did not rename the unique constraint containing the column,
and the "ordered_timestamps_N" checks in "orders" were shifted by one
compared to the ORM.

See the docstring of the migration for details.
2026-12-01 22:49:36 +01:00
7d53abc057
Avoid lazy loads in .__repr__()
`ReplaySimulation`, `ReplayedOrder`, and `Forecast` accessed
relationships in their `.__repr__()`, which emits queries
or fails for detached instances.

They now use the foreign key columns.
2026-12-01 22:34:38 +01:00
1f9d0effae
Cache City.map with functools.cached_property
This replaces the manual caching in the uninitialized
`._map` attribute with a `hasattr()` check.

`.clear_map()` now only discards the cached map.
2026-12-01 22:27:28 +01:00
2a627072d8
Make grids.side_length not nullable
The ORM always defined `Grid.side_length` with `nullable=False`,
but the migration that created the "grids" table did not; the
live database contains no `NULL`s.
2026-12-01 22:20:06 +01:00
db2e00216d
Simplify the docstrings of the migrations
The "Revision" and "Revises" lines and the revision hashes in `upgrade()`
and `downgrade()` repeated the `revision` and `down_revision` variables;
the creation date is in the file name.
2026-12-01 22:20:06 +01:00
f532aae588
Test grids with the same side length in different cities
Regression test for the removed `unique=True` on `Grid.side_length`.
2026-12-01 22:20:06 +01:00
b36a3d1cd6
Allow the same Grid.side_length across cities
The `unique=True` on `Grid.side_length`
made the side length unique across all cities.

The intended rule is the `UniqueConstraint("city_id", "side_length")`,
which the migrations already implement; so, no migration is needed.
2026-12-01 21:58:29 +01:00
731299bb6e
Add nox session "verify-db-objects"
The new "verify-db-objects" session creates the ORM objects
with `.create_all()` in a temporary database and compares
them with the `CLEAN_SCHEMA` of a "live" database using `sqlalchemy-diff`
2026-12-01 21:53:31 +01:00
69b9d53704
Merge branch 'add-typeguard' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
Reviewed-on: #15
2026-12-01 17:54:25 +01:00
cfd8d33049
Rename the "doctest" session into "test-docstrings"
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m46s
2026-12-01 17:14:48 +01:00
f47c87f51f
Add the "test-types" session as a pre-commit hook 2026-12-01 17:14:47 +01:00
2f313e7e3a
Pull out the TEST_DEPENDENCIES 2026-12-01 17:13:14 +01:00
5f7d3108de
Check the type annotations at runtime with typeguard 2026-12-01 17:07:00 +01:00
893b6bd8f1
Seed the random fake data in the tests 2026-12-01 15:51:24 +01:00
e4711875ca
Use a pd.DataFrame as the sentinel in test_totals_is_cached 2026-12-01 15:46:54 +01:00
f92fd35ce3
Revert to bare pd.Series in OrderHistory
`typeguard` evaluates the annotations at runtime where `pd.Series[int]` raises a `TypeError`
2026-12-01 15:31:58 +01:00