Skip to content

Commit 4977b25

Browse files
Flix6xclaude
andcommitted
Merge chart-type-registry into 2802-chart-data-on-registry, bringing in main
Move this PR's API changelog entries along into main's open section, v3.0-38. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
2 parents d270088 + 6b7ca22 commit 4977b25

284 files changed

Lines changed: 32350 additions & 3447 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/hooks/pre-commit-check.sh‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ command -v python3 >/dev/null 2>&1 || exit 0
3131
target="$(printf '%s' "$payload" | python3 "$(dirname "${BASH_SOURCE[0]}")/pre_commit_target.py" 2>/dev/null || true)"
3232
[ -n "$target" ] || exit 0
3333

34+
# Commits from this session also land in repositories that do not use pre-commit at all, such as ones relying on their own git hooks.
35+
# Running `pre-commit run --all-files` there fails with "InvalidConfigError: .pre-commit-config.yaml is not a file", which says nothing about the commit.
36+
# Same fail-open rule as below: when the target has no config, there is nothing for this hook to check.
37+
[ -f "$target/.pre-commit-config.yaml" ] || exit 0
38+
3439
# Pick a runner for the target checkout.
3540
# `uv run` only works where the target is a uv project whose dependencies resolve,
3641
# which is not a given: commits from this session also land in worktrees of other repositories,

‎.github/agents/coordinator.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ See `.github/instructions/README.md` for the current file list.
107107
- Key invariants: acyclic asset trees, non-null flex_context, timezone-aware datetimes
108108
- Architectural layers: API (v3_0), CLI, Data Services, Models
109109
- Common pitfalls: N+1 queries, DST bugs, unit mismatches, serialization issues
110-
- CI/CD: GitHub Actions, Python 3.10-3.12 matrix, PostgreSQL 17.4
110+
- CI/CD: GitHub Actions, Python 3.11-3.12 matrix, PostgreSQL 17.4
111111
- Code quality: flake8, black, mypy via pre-commit hooks
112112

113113
### Schema parity across duplicated Marshmallow schemas

‎.github/agents/test-specialist.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ escalate to the Tooling & CI Specialist.
159159

160160
### CI
161161

162-
`.github/workflows/lint-and-test.yml` runs on Python 3.10-3.12 against a postgres:17.4 service container on Ubuntu runners: pre-commit checks,
162+
`.github/workflows/lint-and-test.yml` runs on Python 3.11-3.12 against a postgres:17.4 service container on Ubuntu runners: pre-commit checks,
163163
test execution with coverage (incl. doctests), Coveralls reporting.
164164

165165
## Interaction Rules

‎.github/agents/tooling-ci-specialist.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ git diff flexmeasures/ui/static/openapi-specs.json | grep -c '"Asia/'
110110

111111
### CI Matrix
112112

113-
- [ ] **Python versions**: Test on supported versions (3.10-3.12)
113+
- [ ] **Python versions**: Test on supported versions (3.11-3.12)
114114
- [ ] **Service versions**: PostgreSQL version matches production
115115
- [ ] **OS matrix**: Ubuntu latest (add others if needed)
116116
- [ ] **Fail-fast**: Usually false for comprehensive testing
@@ -202,7 +202,7 @@ This file defines standardized environment setup for GitHub Copilot agents. When
202202
**GitHub Actions workflows** (`.github/workflows/`):
203203

204204
1. **lint-and-test.yml**
205-
- Python versions: 3.10, 3.11, 3.12
205+
- Python versions: 3.11, 3.12
206206
- PostgreSQL: 17.4 service container
207207
- Coverage: Python 3.11 only
208208
- Caching: pip dependencies
@@ -349,5 +349,8 @@ or Python version support changes. Edit the relevant section in place — don't
349349
breaking the coverage check. Fix by adding `[tool.uv] environments` to `pyproject.toml` limiting resolution to actual target platforms,
350350
then regenerating `uv.lock`. After any significant `uv lock --upgrade`, run `uv sync --locked` locally and confirm exit code 0 before committing.
351351

352+
**A `uv.lock` merge conflict**: never merge the lockfile by hand; take main's and lock again with the required `uv` version.
353+
See `.github/instructions/dependencies.instructions.md`.
354+
352355
Before claiming a CI/tooling change works: run `pre-commit run --all-files` locally, and if it's a workflow change,
353356
verify it actually passes in CI on a branch — don't assume.

‎.github/instructions/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ Each `<topic>.instructions.md` file covers a cross-cutting convention that appli
1010
|------|-----------|-------|
1111
| `atomic-commits.instructions.md` | `**` | Commit discipline — one logical change per commit |
1212
| `changelog.instructions.md` | `**` | Changelog entry format and location |
13+
| `dependencies.instructions.md` | `pyproject.toml,uv.lock` | Resolving `uv.lock` conflicts, testing version ranges |
1314
| `docstrings.instructions.md` | `**/*.py` | RST docstring format, doctests |
1415
| `error-handling.instructions.md` | `**/*.py` | Catching specific exceptions |
16+
| `local-environment.instructions.md` | `**` | Never use a shared configuration; checking plugins |
1517
| `marshmallow-schemas.instructions.md` | `flexmeasures/data/schemas/**/*.py` | `data_key`, field naming, `load_default` |
1618
| `pre-commit-hooks.instructions.md` | `**` | Running hooks before every commit |
17-
| `testing.instructions.md` | `flexmeasures/**/tests/**/*.py` | Full suite, `db` vs `fresh_db`, `requesting_user` |
19+
| `testing.instructions.md` | `flexmeasures/**/tests/**/*.py` | Full suite and doctests, `db` vs `fresh_db`, the test database, `requesting_user` |
1820
| `timezone-awareness.instructions.md` | `**/*.py` | Always timezone-aware datetimes |
1921
| `ui-terminology.instructions.md` | `flexmeasures/ui/**` | "organisation" not "account" in user-facing text |
2022

‎.github/instructions/changelog.instructions.md‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,27 @@ Example for the main changelog:
2727
* Add cross-cutting Copilot instruction files to `.github/instructions/` [see `PR #XXXX <https://www.github.com/FlexMeasures/flexmeasures/pull/XXXX>`_]
2828
```
2929

30-
Replace `XXXX` with the actual PR number. If the PR number is not yet known, alert the maintainer.
30+
Replace `XXXX` with the PR number.
31+
For a PR that does not exist yet, fill in the most likely next number before pushing (see below), rather than leaving `XXXX`.
32+
33+
## Guessing the number of a PR that does not exist yet
34+
35+
Issues, PRs and discussions share one number sequence, and a new PR usually takes the next free number.
36+
So before pushing the branch for a new PR, fill in that number:
37+
38+
```bash
39+
R=FlexMeasures/flexmeasures
40+
N=$(( $(gh api "repos/$R/issues?state=all&per_page=1" --jq '.[0].number') + 1 ))
41+
curl -s -o /dev/null -w '%{http_code}\n' "https://github.com/$R/issues/$N" # 404: the number is still free
42+
```
43+
44+
The issues API lists issues and PRs, but not discussions, so check the web URL:
45+
it answers 404 only while no issue, PR or discussion has the number (otherwise 200, or a redirect).
46+
If it does not answer 404, try the next number.
47+
48+
After creating the PR, compare its number with the one filled in.
49+
If someone took the number in between, correct the entry and push again.
50+
Guessing right is common, and it saves a CI run for a commit that only fills in the number.
3151

3252
## Sections in `documentation/changelog.rst`
3353

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
applyTo: "pyproject.toml,uv.lock"
3+
---
4+
# Dependencies and the Lockfile
5+
6+
See `documentation/dev/dependency-management.rst` for how dependencies are managed and how `uv` is pinned.
7+
8+
## Resolving a `uv.lock` conflict
9+
10+
A conflict in `uv.lock` is almost never about the packages themselves.
11+
Different `uv` versions write environment markers differently, so two lockfiles can disagree on nearly every line while only a few packages differ.
12+
13+
**Never merge `uv.lock` by hand.** Both obvious ways of combining the two sides break it silently:
14+
15+
- Combining by package *name* drops one half of entries that are split by Python version
16+
(e.g. one version of a package for Python 3.11 and another for 3.12), which breaks one of the CI matrix's Python versions.
17+
- Combining by whole *line* keeps both spellings of every marker, which duplicates the package list.
18+
19+
Neither is caught by the tests, only by reading the diff. Instead, take main's lockfile and lock again:
20+
21+
```bash
22+
git checkout origin/main -- uv.lock
23+
uv lock # with the uv version that `required-version` in pyproject.toml names
24+
uv lock --check
25+
git diff --stat origin/main -- uv.lock
26+
git diff origin/main -- uv.lock | grep -E '^[+-](name|version) = ' # only the packages you meant to change
27+
```
28+
29+
A lockfile rewritten by a different `uv` version shows up as hundreds or thousands of changed lines; that diff should be a few lines.
30+
31+
## Supported version ranges
32+
33+
A dependency without an upper bound (e.g. `pandas>=2.2.1`) means every later major version is supported, too.
34+
Test a change against both ends of the range, without changing your environment:
35+
36+
```bash
37+
uv run --no-project --with "pandas==2.2.1" python probe.py
38+
uv run --no-project --with "pandas==3.*" python probe.py
39+
```
40+
41+
See `timezone-awareness.instructions.md` for what changed with pandas 3.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
applyTo: "**"
3+
---
4+
# Running FlexMeasures Locally
5+
6+
## Never run the CLI or the app against a shared configuration
7+
8+
A development configuration may point at a database or a Redis server that others use too:
9+
a shared Redis means queued jobs reach workers running other (possibly older) FlexMeasures code,
10+
and a shared database may hold real data.
11+
Commands such as `flexmeasures add forecasts --as-job` or `flexmeasures jobs run-automations` queue jobs there.
12+
13+
To try a change, use the test suite (it has its own database and Redis database), or isolated local services:
14+
15+
- Postgres and Redis of your own (e.g. Docker containers on non-standard ports),
16+
- a configuration file of your own, naming them,
17+
- and a separate `HOME`, because FlexMeasures also picks up `~/.flexmeasures.cfg` (see `find_flexmeasures_cfg` in `flexmeasures/utils/config_utils.py`).
18+
19+
If you queued something on a shared Redis by accident, delete those jobs, including any deferred jobs that wait for them.
20+
21+
Two test runs at once need a database and a Redis database each: see `testing.instructions.md`.
22+
23+
## Checking a change against plugins
24+
25+
Before changing or removing a function, a model attribute or a CLI option that plugins may use, search the plugins for it.
26+
Local clones are not enough: they can be on an old branch, and several plugin repositories may not be cloned at all.
27+
28+
- `git fetch` each local plugin clone and `git grep` its remote branch, not the working tree.
29+
- Search the organisations' repositories as well, e.g. `gh search code "<symbol>" --owner FlexMeasures`,
30+
and read the actual call sites, since substring hits are common (`asset_attributes` matches `set_attribute`).

‎.github/instructions/pre-commit-hooks.instructions.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ All hooks must pass with zero failures before committing.
2929
| **mypy** | Type annotations (via `ci/run_mypy.sh`) |
3030
| **generate-openapi-specs** | OpenAPI spec generation (local only, skipped in CI) |
3131

32+
## Use the pinned tool versions
33+
34+
The versions in `pyproject.toml` are the ones CI runs, and other versions disagree with them.
35+
A globally installed black from another release formats differently (for instance around multiline strings),
36+
so a file it calls clean can still be reformatted in CI.
37+
Run the hooks through `pre-commit` or `uv run`, which use the pins, rather than a `black` or `flake8` on your `PATH`.
38+
39+
`[tool.uv] required-version` in `pyproject.toml` gates every `uv` command in the checkout (`uv run`, `uv sync`, `uv lock`, and so the hooks too).
40+
With another `uv` version installed, update it to the required one rather than skipping hooks.
41+
3242
## Flake8 configuration
3343

3444
Max line length: 160. Max complexity: 13. Ignored rules: E501, W503, E203.

‎.github/instructions/testing.instructions.md‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,43 @@ Intermediate full test runs are encouraged when appropriate (e.g., after a signi
1717
During active development, targeted runs (`pytest path/to/test_module.py`) are acceptable for quick iteration,
1818
but must not substitute for the full suite at session close.
1919

20+
## Run the doctests too
21+
22+
CI runs `pytest --doctest-modules`, with a list of `--ignore`s and a `-k` filter (see the test step in `.github/workflows/lint-and-test.yml`).
23+
Neither `poe test` nor the `addopts` in `pyproject.toml` include doctests,
24+
so a green local run can still fail in CI on a docstring example alone, for instance after a dependency upgrade.
25+
Before pushing a dependency change or a docstring example, run the doctests with the same `--ignore` and `-k` arguments as the workflow.
26+
27+
A doctest that shows a pint `Quantity` should `print()` it rather than rely on its `repr`,
28+
because the `repr` differs between pint versions.
29+
30+
## Never migrate the test database
31+
32+
Do not run `flexmeasures db upgrade` (or `flask db upgrade`) against the test database to check a migration.
33+
Pytest owns that database: the `db` fixture runs `drop_all()` and `create_all()` and expects nothing else in it.
34+
The migration chain creates legacy tables (`power`, `price`, `weather`, `market`, `asset`, …) that are not in the current models,
35+
so `drop_all()` leaves them behind, and since `market` holds a foreign key onto `sensor`,
36+
every later `drop_all()` fails with `DependentObjectsStillExist` and the whole suite errors at setup.
37+
`flexmeasures db downgrade base` does not undo it either: an early revision's downgrade recreates a table that still exists, and the chain stops halfway.
38+
39+
Verify a migration on a scratch database instead.
40+
If the test database was migrated by accident, drop the legacy tables explicitly:
41+
42+
```sql
43+
DROP TABLE IF EXISTS power, price, weather, market, market_type, weather_sensor, weather_sensor_type,
44+
asset, asset_type, role, roles_users, alembic_version CASCADE;
45+
```
46+
47+
Pytest's own `drop_all()` then clears the model tables, and the database is empty again.
48+
49+
## Failures that only show up in a subset run
50+
51+
Some tests assert on warnings or on the deduplication of log records,
52+
which is process-global state that depends on what ran before them in the same process.
53+
Such tests can fail when only part of the suite runs (e.g. `pytest flexmeasures/utils flexmeasures/data`), yet pass in a full run.
54+
Before attributing a failure in a subset run to your change, run the same subset on the merge base and compare,
55+
or run the full suite.
56+
2057
## Run the full module after changing any test
2158

2259
When you fix or add a single test, always run the entire test module before closing:
@@ -148,6 +185,18 @@ asset.sensors_to_show = []
148185
asset.sensors_to_show = None
149186
```
150187

188+
## Scheduling tests: give each its own parent asset
189+
190+
`Sensor.__init__` moves legacy sensor attributes (such as `capacity_in_mw`) into the flex-model of the sensor's asset,
191+
and the module-scoped `flexible_devices` and `inflexible_devices` fixtures do this to the shared `building` asset.
192+
A scheduler triggered on `building` then merges `asset.get_flex_model()` (that asset and all its descendants) into the flex-model it was given,
193+
so a later test in the same module schedules an extra device it never asked for.
194+
Such tests pass on their own and fail in module order.
195+
196+
A test that schedules a multi-device flex-model should create a fresh parent asset of its own
197+
(see `_add_parent_site` in `flexmeasures/data/models/planning/tests/test_solver.py`),
198+
and pass `flex_context={}` explicitly.
199+
151200
## Authentication failures in tests
152201

153202
If you see unexpected `401 Unauthorized` in tests:

0 commit comments

Comments
 (0)