Commit 3ae6825
feat(annual): let a caller supply the storage backend to annual_cli.main()
StorageBase is already an abstraction — annual_weather.py and annual_tariff.py
only ever call self.storage.load()/save(), and AnnualPredictor takes whatever
storage it is given — but annual_cli.main() hard-coded StorageLocalFiles. The
only way to run the annual tool against a different backend was therefore to
fork the CLI, or to reimplement main() and with it the --machine stdout/stderr
contract, which is the fiddly part: the stdout redirect that stops a stray
print() from corrupting the one-JSON-object stdout a parent process parses.
main() now takes storage_factory, called as storage_factory(work_dir, log) —
exactly how StorageLocalFiles is constructed, so the default is that class
itself and the command line behaves as it always has.
The motivating case is embedding the annual tool in a long-lived service. There
a per-process work dir means every process re-downloads the same immutable ERA5
and Octopus data and none of it can be shared, which also multiplies requests
against the rate APIs. A shared backend (Redis, S3, a database) fixes both, and
now needs a factory rather than a fork.
Tests cover both paths: the default still constructs StorageLocalFiles, and a
supplied factory reaches AnnualPredictor and receives --work-dir and the run's
log callable. The new assertions were verified to fail without the change
(TypeError: unexpected keyword argument 'storage_factory'). The annual_cli,
annual_cli_machine, annual_cli_machine_end_to_end, annual_job and storage
suites all pass, and black 23.11.0 and ruff 0.11.4 (the pinned pre-commit
versions) report no changes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent e409e61 commit 3ae6825
2 files changed
Lines changed: 75 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
155 | 170 | | |
156 | 171 | | |
157 | 172 | | |
| |||
174 | 189 | | |
175 | 190 | | |
176 | 191 | | |
177 | | - | |
| 192 | + | |
178 | 193 | | |
179 | 194 | | |
180 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | | - | |
| 34 | + | |
33 | 35 | | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
237 | 240 | | |
238 | 241 | | |
239 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
240 | 296 | | |
241 | 297 | | |
242 | 298 | | |
| |||
0 commit comments