ilc-models 0.2.3__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ilc_models-0.3.0/.claude/settings.local.json +7 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/.gitignore +1 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/CHANGELOG.md +44 -1
- ilc_models-0.3.0/CLAUDE.md +85 -0
- ilc_models-0.3.0/PKG-INFO +189 -0
- ilc_models-0.3.0/README.md +167 -0
- ilc_models-0.3.0/docs/requirements.txt +36 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/docs/source/conf.py +21 -1
- ilc_models-0.3.0/docs/source/index.rst +62 -0
- ilc_models-0.3.0/docs/source/usage.rst +297 -0
- ilc_models-0.3.0/justfile +60 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/pyproject.toml +44 -12
- ilc_models-0.3.0/src/ilc_models/__init__.py +1600 -0
- ilc_models-0.3.0/tests/__init__.py +0 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/tests/test_models.py +245 -17
- ilc_models-0.3.0/uv.lock +1168 -0
- ilc_models-0.2.3/PKG-INFO +0 -32
- ilc_models-0.2.3/README.md +0 -13
- ilc_models-0.2.3/check.zsh +0 -17
- ilc_models-0.2.3/coverage.zsh +0 -3
- ilc_models-0.2.3/docs/requirements.txt +0 -30
- ilc_models-0.2.3/docs/source/index.rst +0 -10
- ilc_models-0.2.3/src/ilc_models/__init__.py +0 -1295
- ilc_models-0.2.3/uv.lock +0 -828
- {ilc_models-0.2.3 → ilc_models-0.3.0}/.python-version +0 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/.readthedocs.yaml +0 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/LICENSE.txt +0 -0
- /ilc_models-0.2.3/src/ilc_models/py.typed → /ilc_models-0.3.0/docs/source/_static/.gitkeep +0 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/docs/source/api.rst +0 -0
- /ilc_models-0.2.3/tests/__init__.py → /ilc_models-0.3.0/src/ilc_models/py.typed +0 -0
- {ilc_models-0.2.3 → ilc_models-0.3.0}/tests/conftest.py +0 -0
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.0] - 2026-10-19
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add `UserPublic` model, the public view of a user (`email`, validated as `EmailStr`)
|
|
8
|
+
- Add `User` model, the stored view of a user, extending `UserPublic` with an argon2 `password_hash` (hidden from `repr`)
|
|
9
|
+
- Add `User.create()`, `User.verify_password()`, `User.needs_rehash()` and `User.set_password()` methods
|
|
10
|
+
- A `User` can be built from either a plain text `password` (hashed on validation) or a stored `password_hash`, but not both
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Add `argon2-cffi` and `pydantic[email]` as runtime dependencies
|
|
15
|
+
|
|
16
|
+
### Documentation
|
|
17
|
+
|
|
18
|
+
- Document the `User` and `UserPublic` models in the README and usage guide
|
|
19
|
+
- Correct the usage guide's description of `League.events()` and document how the `matches()` filters, deductions and `League.split` behave
|
|
20
|
+
- Complete missing `Returns:` sections and clarify several field descriptions in the docstrings
|
|
21
|
+
- Fix the docs requirements lockfile, which was missing the new dependencies and so broke the Read the Docs build
|
|
22
|
+
|
|
23
|
+
## [0.2.4] - 2026-08-23
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Add `Match.event_team()` method
|
|
28
|
+
- Add `Match.played_for()` method
|
|
29
|
+
- Add `player` parameter to `League.matches()` method
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- Fix `TableRow.from_tuple()` losing the `deducted` field, so `as_tuple()`/`from_tuple()` round-trips no longer silently drop points deductions
|
|
34
|
+
- Fix date validation to reject impossible calendar dates such as month 19 or 29 February in a non-leap year, as well as malformed ones, on `Player.dob`, `Match.kickoff`, `Deduction.date` and `League.start`/`end`
|
|
35
|
+
|
|
36
|
+
### Documentation
|
|
37
|
+
|
|
38
|
+
- Convert docstrings to Google style, correct inaccurate content, add missing documentation, standardise mood/markup
|
|
39
|
+
- Expand `README.md` and the Sphinx docs with a model map, worked examples, and the package's non-obvious conventions
|
|
40
|
+
- Add a Read the Docs link to the project metadata
|
|
41
|
+
|
|
3
42
|
## [0.2.3] - 2026-02-05
|
|
4
43
|
|
|
5
44
|
### Changed
|
|
@@ -31,7 +70,7 @@
|
|
|
31
70
|
|
|
32
71
|
### Changed
|
|
33
72
|
|
|
34
|
-
- Convert `RowTuple` to `
|
|
73
|
+
- Convert `RowTuple` to `typing.NamedTuple` type
|
|
35
74
|
|
|
36
75
|
## [0.1.8] - 2025-07-26
|
|
37
76
|
|
|
@@ -85,6 +124,10 @@
|
|
|
85
124
|
|
|
86
125
|
_Initial release._
|
|
87
126
|
|
|
127
|
+
[Unreleased]: https://github.com/fourtreestech/ilc-models/compare/v0.2.4...HEAD
|
|
128
|
+
|
|
129
|
+
[0.2.4]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.4
|
|
130
|
+
|
|
88
131
|
[0.2.3]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.3
|
|
89
132
|
|
|
90
133
|
[0.2.2]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.2
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
Task runner is `just` (see `justfile`); Python tooling is `uv`.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
just check # ruff check --fix, ruff format, then `ty check` (Astral's type checker)
|
|
11
|
+
just test # uv run pytest
|
|
12
|
+
just cov # pytest with coverage + regenerate the README coverage badge via cov-badge
|
|
13
|
+
just upgrade # uv lock --upgrade, uv sync, regenerate docs/requirements.txt, then run tox
|
|
14
|
+
just tox # uvx tox
|
|
15
|
+
just docs # sphinx-build -W --keep-going into docs/build/html
|
|
16
|
+
just bump # uvx bumpver update --patch (commits; doesn't tag or push)
|
|
17
|
+
just sync # ff-only merge dev -> main, push, switch back to dev
|
|
18
|
+
just tag # tag main with v<version> from pyproject.toml and push
|
|
19
|
+
just publish # rm -rf dist, uv build, then uv publish to PyPI
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Single test / narrower runs:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
uv run pytest tests/test_models.py::TestLeagueTable
|
|
26
|
+
uv run pytest tests/test_models.py::TestMatch::test_players_from_team
|
|
27
|
+
uv run pytest -p no:randomly # pytest-randomly shuffles order; disable when bisecting a failure
|
|
28
|
+
uvx tox # full matrix: Python 3.12, 3.13, 3.14 (pinned to `uv.lock`), plus `lowest` (3.12 with the lowest dependency versions, including transitive ones) and `highest` (3.14 with the newest releases, ignoring `uv.lock`)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
There is no `[tool.pytest.ini_options]` section — pytest runs on defaults with `tests/` discovered from the repo root.
|
|
32
|
+
|
|
33
|
+
tox and tox-uv versions come only from `[tool.tox] requires` in `pyproject.toml`: `uvx tox` provisions them into `.tox/.tox`. Don't add them to a dependency group, or the `uvx tox` and `uv run tox` routes can drift apart.
|
|
34
|
+
|
|
35
|
+
## Release workflow
|
|
36
|
+
|
|
37
|
+
Work happens on `dev`; `main` only ever receives fast-forward merges via `just sync`.
|
|
38
|
+
|
|
39
|
+
The version string lives in **four** places, kept in sync by bumpver (`[tool.bumpver.file_patterns]` in `pyproject.toml`): `pyproject.toml`, the README badge, `src/ilc_models/__init__.py::__version__`, and `docs/source/conf.py::release`. Never hand-edit them — run `just bump`, which wraps `uvx bumpver update --patch` (bumpver is not a project dependency; it commits but does not tag or push). Then add a `CHANGELOG.md` entry by hand (including the link reference at the bottom), run `just tag`, and finally `just publish` to build and upload to PyPI. `just publish` authenticates via a PyPI API token (`pypi-…`) read from `.pypi.token` at the repo root — gitignored, so a fresh clone needs it recreated by hand.
|
|
40
|
+
|
|
41
|
+
## Architecture
|
|
42
|
+
|
|
43
|
+
Everything is one module: `src/ilc_models/__init__.py`. Pydantic v2 models with no I/O — this package is the data contract shared across the ILC repos, so a field change here is a breaking change for `ilc-api`, `ilc-app`, and `ilc-admin`. Its only dependencies are `pydantic[email]` (for `EmailStr`) and `argon2-cffi`, which `User` uses for password hashing through the private module-level `_ph` hasher; don't add any others.
|
|
44
|
+
|
|
45
|
+
`User` is the stored shape (Mongo), including `password_hash`, so `model_dump()` includes it. `UserPublic` is the API response shape with no secrets, and `User` subclasses it. Fields that must never leave the API go on `User` only; `ilc-api` should declare `response_model=UserPublic`.
|
|
46
|
+
|
|
47
|
+
`User.verify_password()` never modifies the user. To upgrade outdated hashes, the caller does `if user.verify_password(attempt) and user.needs_rehash(): user.set_password(attempt)` and then persists the user.
|
|
48
|
+
|
|
49
|
+
Containment: `League` → `rounds: dict[str, list[Match]]` → `Match` → `Lineups` → `Lineup` → `list[tuple[shirt_no, BasePlayer]]`. Events (`Goal`, `Card`, `Substitution`, `LineupStatus`) subclass the abstract `BaseEvent`, each carrying a frozen `event_type` literal discriminator and implementing `players()`; the `Event` union type aliases them.
|
|
50
|
+
|
|
51
|
+
### Conventions that are easy to violate
|
|
52
|
+
|
|
53
|
+
**`Goal.team` is the team credited with the goal, not the scorer's team.** For an own goal (`goal_type == "O"`) the scorer belongs to the *opposing* team. `Match.event_team(event)` is the single place that resolves the team a given event's players actually play for, flipping it for own goals and passing everything else through unchanged — `Match.players()`, `League.update_player()`, and `League.player_teams()` all call it rather than re-deriving the flip. New code that filters players or events by team should call `Match.event_team()` too, or it will misattribute own goals.
|
|
54
|
+
|
|
55
|
+
**`BasePlayer.__eq__` compares `player_id` alone**, falling back to `name` only when both IDs are `0`. This is deliberate: the upstream API spells player names differently in event payloads versus player downloads. Consequently `player in some_list` is an ID-based membership test throughout, and `Player` equality inherits this (it ignores `first_name`, `dob`, etc.).
|
|
56
|
+
|
|
57
|
+
**`TableRow.__gt__` reverses team-name ordering on ties**, so that the `sorted(..., reverse=True)` in `League.table()` yields alphabetical order among equal teams. Do not "fix" the apparent inversion.
|
|
58
|
+
|
|
59
|
+
**`League.table()` models the Scottish-style split.** Once any team has played more than `League.split` matches, the table freezes the top/bottom halves by position at the split point — computed by recursing into `self.table(split_point=True)` — and sorts each half independently. An odd team count puts the extra team in the top half. Points deductions apply only when `Deduction.date` is empty (season-start) or falls on/before the last match processed, which is why the loop tracks `last_date`.
|
|
60
|
+
|
|
61
|
+
**Dates are validated ISO strings, not `date` objects.** `Match.kickoff` requires a full offset-aware timestamp (strict `Field(pattern=...)`), `League.start`/`end` require `yyyy-mm-dd`. Four `WrapValidator` helpers layer a real-calendar check (via `datetime.date`/`datetime.datetime`) on top of each field's regex, so month 19 or 29 February in a non-leap year raises `ValueError` rather than validating: `validate_dob` and `validate_deduction_date` additionally accept the empty string, and `validate_dob` normalises `yyyy-m-d` to zero-padded form; `validate_kickoff` and `validate_date` run after the `Field(pattern=...)` on `Match.kickoff` and `League.start`/`end` respectively. Derive `datetime.date` via `Match.date`.
|
|
62
|
+
|
|
63
|
+
**`EventTime.plus` is only legal at the end of a half** (45/90/105/120), enforced by a `model_validator(mode="after")`.
|
|
64
|
+
|
|
65
|
+
`League.head_to_head()` predates `League.matches(h2h=...)`; prefer the parameterised `matches()`/`match_players()` filters (`team`, `teams`, `h2h`) for new code.
|
|
66
|
+
|
|
67
|
+
## Docs and docstrings
|
|
68
|
+
|
|
69
|
+
Sphinx autodoc renders the whole module (`docs/source/api.rst` → `automodule:: ilc_models`) and publishes to Read the Docs. Public members need Google-style docstrings matching the existing ones (`Args:` / `Attributes:` / `Returns:` / `Raises:`, parsed by `sphinx.ext.napoleon`). `ruff`'s `D`/`D401` rules (Google convention, see `[tool.ruff.lint.pydocstyle]`) enforce presence and imperative mood as part of `just check`; `tests/*` and `docs/*` are exempted via `per-file-ignores`.
|
|
70
|
+
|
|
71
|
+
Style conventions:
|
|
72
|
+
- Method/function summaries are imperative ("Return the …", "Get the …", "Sort the …"); class summaries stay descriptive ("Represents a goal.").
|
|
73
|
+
- Cross-reference with single backticks only (`` `ClassName` ``, `` `ValueError` ``) — `default_role = "literal"` in `conf.py` renders them as code, so `:class:`/`:exc:`/`:attr:` roles and double backticks are unnecessary and should not be used.
|
|
74
|
+
- Pydantic model fields are documented as `Attributes:` on the class docstring rather than `Args:`, with `(default=…)` noted where a field has one. **Exception:** don't add an `Attributes:` section to a `NamedTuple` (e.g. `RowTuple`) — its fields are separate real attributes that autodoc already documents individually, and a Napoleon `Attributes:` block for the same names produces a "duplicate object description" warning that fails `-W` builds. Describe `NamedTuple` fields in prose instead.
|
|
75
|
+
- Types are omitted from `Args:`/`Attributes:`/`Returns:` entries — `autodoc_typehints = "description"` and `napoleon_attr_annotations` pull them from the annotations instead, so only the description goes in the docstring. This also means **a method's return type only renders if its docstring has a `Returns:` section** (`autodoc_typehints_description_target = "documented_params"`), so every method with a non-`None` return needs one, including dunders like `__eq__`/`__gt__`/`__len__`/`__bool__`/`__str__`.
|
|
76
|
+
|
|
77
|
+
Run `just docs` to build the docs locally (`-W`, so any Napoleon/autodoc warning fails the build). `docs/requirements.txt` is a pinned lockfile for the RTD build and must be updated when the docs dependency group changes; `just upgrade` regenerates it with `uv export`.
|
|
78
|
+
|
|
79
|
+
## Tests
|
|
80
|
+
|
|
81
|
+
`tests/test_models.py` is a single file of `Test<Model>` classes. Fixtures come from the sibling `ilc_provider` package's Faker provider, exposed as the session-scoped `ilc_fake` fixture in `tests/conftest.py` (`ilc_fake.league()`, `.match()`, `.player()`, `.base_player()`, `.lineup()`, `.table_row()`, …) — prefer these over hand-built models.
|
|
82
|
+
|
|
83
|
+
Two hazards: `pytest-randomly` shuffles test order, and the `fake_league` fixture is session-scoped but holds mutable models, so a test that mutates it can leak into others. Build a fresh `ilc_fake.league()` when mutating.
|
|
84
|
+
|
|
85
|
+
Coverage sits at 100%; genuinely unreachable defensive branches are marked `# pragma: no cover`.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ilc-models
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Data models for the ILC project
|
|
5
|
+
Project-URL: Repository, https://github.com/fourtreestech/ilc-models
|
|
6
|
+
Project-URL: Documentation, https://ilc-models.readthedocs.io/
|
|
7
|
+
Author-email: Neil Martin <neil@fourtrees.tech>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Requires-Dist: argon2-cffi>=25.1.0
|
|
20
|
+
Requires-Dist: pydantic[email]>=2.12.5
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# ilc-models
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+

|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
**ilc-models** contains all data models for the *ILC* project.
|
|
30
|
+
|
|
31
|
+
It's a set of pure Pydantic v2 models with no I/O — a `League` of `Match`
|
|
32
|
+
objects, each with its `Lineups`, `Goal`/`Card`/`Substitution` events, and
|
|
33
|
+
the `TableRow` results computed from them, plus `User` and `UserPublic`
|
|
34
|
+
models for accounts. Its only dependencies are `pydantic` (with the email
|
|
35
|
+
extra) and `argon2-cffi`, which `User` uses to hash passwords. This package
|
|
36
|
+
is the shared data contract used across the `ilc-api`, `ilc-app` and
|
|
37
|
+
`ilc-admin` repositories, so a field change here is a breaking change for
|
|
38
|
+
all three.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
Requires Python 3.12 or later.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install ilc-models
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
uv add ilc-models
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from ilc_models import League, Match, Teams, Score
|
|
58
|
+
|
|
59
|
+
league = League(
|
|
60
|
+
league_id=1,
|
|
61
|
+
name="Premiership",
|
|
62
|
+
year=2025,
|
|
63
|
+
start="2025-08-01",
|
|
64
|
+
end="2026-05-01",
|
|
65
|
+
current=True,
|
|
66
|
+
coverage={"lineups": True},
|
|
67
|
+
teams=["Team A", "Team B"],
|
|
68
|
+
rounds={
|
|
69
|
+
"1": [
|
|
70
|
+
Match(
|
|
71
|
+
match_id=1,
|
|
72
|
+
kickoff="2025-08-09T15:00:00+01:00",
|
|
73
|
+
round="1",
|
|
74
|
+
teams=Teams(home="Team A", away="Team B"),
|
|
75
|
+
status="FT",
|
|
76
|
+
score=Score(home=2, away=1),
|
|
77
|
+
)
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
for row in league.table():
|
|
83
|
+
print(row)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Model map
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
League
|
|
90
|
+
rounds: dict[str, list[Match]]
|
|
91
|
+
Match
|
|
92
|
+
teams: Teams # home / away team names
|
|
93
|
+
score: Score # home / away goals
|
|
94
|
+
goals: list[Goal]
|
|
95
|
+
cards: list[Card]
|
|
96
|
+
substitutions: list[Substitution]
|
|
97
|
+
lineups: Lineups
|
|
98
|
+
home: Lineup
|
|
99
|
+
away: Lineup
|
|
100
|
+
starting: list[tuple[int, BasePlayer]] # shirt_no, player
|
|
101
|
+
subs: list[tuple[int, BasePlayer]]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`Goal`, `Card`, `Substitution` and `LineupStatus` all subclass the abstract
|
|
105
|
+
`BaseEvent` and are aliased together as `Event`. `League.players` holds
|
|
106
|
+
every `Player` who has featured in the league, keyed by `player_id` as a
|
|
107
|
+
string.
|
|
108
|
+
|
|
109
|
+
Users are modelled separately: `User` (the stored shape, including
|
|
110
|
+
`password_hash`) subclasses `UserPublic` (just `email`).
|
|
111
|
+
|
|
112
|
+
## Users
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from ilc_models import User
|
|
116
|
+
|
|
117
|
+
user = User.create("alice@example.com", "correct horse battery staple")
|
|
118
|
+
|
|
119
|
+
user.verify_password("correct horse battery staple") # True
|
|
120
|
+
user.verify_password("wrong") # False
|
|
121
|
+
|
|
122
|
+
# After a successful login, upgrade the hash if its parameters are outdated
|
|
123
|
+
attempt = "correct horse battery staple"
|
|
124
|
+
if user.verify_password(attempt) and user.needs_rehash():
|
|
125
|
+
user.set_password(attempt)
|
|
126
|
+
# ...then persist the user
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`User.create` hashes the password with argon2 and never stores it. To load a
|
|
130
|
+
user from the database, pass the stored hash instead:
|
|
131
|
+
`User(email=..., password_hash=...)`. Supplying both `password` and
|
|
132
|
+
`password_hash` raises an error.
|
|
133
|
+
|
|
134
|
+
> **Warning:** `User.model_dump()` includes `password_hash`. Anything that
|
|
135
|
+
> leaves the API should use `UserPublic` (e.g. FastAPI's
|
|
136
|
+
> `response_model=UserPublic`).
|
|
137
|
+
|
|
138
|
+
## Conventions worth knowing
|
|
139
|
+
|
|
140
|
+
A few behaviours are deliberate and easy to trip over — see the [full
|
|
141
|
+
usage guide](https://ilc-models.readthedocs.io/en/latest/usage.html) for
|
|
142
|
+
detail:
|
|
143
|
+
|
|
144
|
+
- **`Goal.team` is the team credited with the goal, not the scorer's team.**
|
|
145
|
+
For an own goal the scorer belongs to the opposing team — call
|
|
146
|
+
`Match.event_team(event)` to resolve the team a player in an event
|
|
147
|
+
actually plays for.
|
|
148
|
+
- **Player equality compares `player_id` alone** (falling back to `name`
|
|
149
|
+
only when both IDs are `0`), because the upstream API spells player names
|
|
150
|
+
differently in event payloads versus player downloads.
|
|
151
|
+
- **`League.table()` models the Scottish-style split** — once a team has
|
|
152
|
+
played more than `League.split` matches, the table freezes the top/bottom
|
|
153
|
+
halves by position at the split point and sorts each half independently.
|
|
154
|
+
`League.split` is the number of matches each team plays before the split;
|
|
155
|
+
the default of `0` means no split.
|
|
156
|
+
- **The `team`, `teams`, `h2h` and `player` filters on `League.matches()`
|
|
157
|
+
are alternatives, not combinable.** If you pass more than one, only the
|
|
158
|
+
first applies, in that order. `League.match_players()` works the same way
|
|
159
|
+
(without `player`), and `Match.players()` prefers `teams` over `team`.
|
|
160
|
+
- **Dates are validated ISO strings, not `date` objects.** `Match.kickoff`
|
|
161
|
+
is a full offset-aware timestamp; `League.start`/`end` and
|
|
162
|
+
`Deduction.date` are `yyyy-mm-dd`. Use `Match.date` to get a
|
|
163
|
+
`datetime.date`.
|
|
164
|
+
- **`EventTime.plus` (stoppage time) is only valid at the end of a half** —
|
|
165
|
+
i.e. when `minutes` is 45, 90, 105 or 120.
|
|
166
|
+
|
|
167
|
+
## Documentation
|
|
168
|
+
|
|
169
|
+
Full API reference and usage guide:
|
|
170
|
+
[ilc-models.readthedocs.io](https://ilc-models.readthedocs.io/)
|
|
171
|
+
|
|
172
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release history.
|
|
173
|
+
|
|
174
|
+
## Development
|
|
175
|
+
|
|
176
|
+
Task runner is [`just`](https://github.com/casey/just); Python tooling is
|
|
177
|
+
[`uv`](https://docs.astral.sh/uv/).
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
just check # ruff check --fix, ruff format, then ty check (type checking)
|
|
181
|
+
just test # run tests with pytest
|
|
182
|
+
just cov # pytest with coverage, then regenerate the coverage badge
|
|
183
|
+
just docs # build the Sphinx docs locally
|
|
184
|
+
just tox # run the tests across Python 3.12-3.14 and lowest/highest dependencies
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT — see [LICENSE.txt](./LICENSE.txt).
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# ilc-models
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**ilc-models** contains all data models for the *ILC* project.
|
|
8
|
+
|
|
9
|
+
It's a set of pure Pydantic v2 models with no I/O — a `League` of `Match`
|
|
10
|
+
objects, each with its `Lineups`, `Goal`/`Card`/`Substitution` events, and
|
|
11
|
+
the `TableRow` results computed from them, plus `User` and `UserPublic`
|
|
12
|
+
models for accounts. Its only dependencies are `pydantic` (with the email
|
|
13
|
+
extra) and `argon2-cffi`, which `User` uses to hash passwords. This package
|
|
14
|
+
is the shared data contract used across the `ilc-api`, `ilc-app` and
|
|
15
|
+
`ilc-admin` repositories, so a field change here is a breaking change for
|
|
16
|
+
all three.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Requires Python 3.12 or later.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install ilc-models
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
uv add ilc-models
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from ilc_models import League, Match, Teams, Score
|
|
36
|
+
|
|
37
|
+
league = League(
|
|
38
|
+
league_id=1,
|
|
39
|
+
name="Premiership",
|
|
40
|
+
year=2025,
|
|
41
|
+
start="2025-08-01",
|
|
42
|
+
end="2026-05-01",
|
|
43
|
+
current=True,
|
|
44
|
+
coverage={"lineups": True},
|
|
45
|
+
teams=["Team A", "Team B"],
|
|
46
|
+
rounds={
|
|
47
|
+
"1": [
|
|
48
|
+
Match(
|
|
49
|
+
match_id=1,
|
|
50
|
+
kickoff="2025-08-09T15:00:00+01:00",
|
|
51
|
+
round="1",
|
|
52
|
+
teams=Teams(home="Team A", away="Team B"),
|
|
53
|
+
status="FT",
|
|
54
|
+
score=Score(home=2, away=1),
|
|
55
|
+
)
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
for row in league.table():
|
|
61
|
+
print(row)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Model map
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
League
|
|
68
|
+
rounds: dict[str, list[Match]]
|
|
69
|
+
Match
|
|
70
|
+
teams: Teams # home / away team names
|
|
71
|
+
score: Score # home / away goals
|
|
72
|
+
goals: list[Goal]
|
|
73
|
+
cards: list[Card]
|
|
74
|
+
substitutions: list[Substitution]
|
|
75
|
+
lineups: Lineups
|
|
76
|
+
home: Lineup
|
|
77
|
+
away: Lineup
|
|
78
|
+
starting: list[tuple[int, BasePlayer]] # shirt_no, player
|
|
79
|
+
subs: list[tuple[int, BasePlayer]]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`Goal`, `Card`, `Substitution` and `LineupStatus` all subclass the abstract
|
|
83
|
+
`BaseEvent` and are aliased together as `Event`. `League.players` holds
|
|
84
|
+
every `Player` who has featured in the league, keyed by `player_id` as a
|
|
85
|
+
string.
|
|
86
|
+
|
|
87
|
+
Users are modelled separately: `User` (the stored shape, including
|
|
88
|
+
`password_hash`) subclasses `UserPublic` (just `email`).
|
|
89
|
+
|
|
90
|
+
## Users
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from ilc_models import User
|
|
94
|
+
|
|
95
|
+
user = User.create("alice@example.com", "correct horse battery staple")
|
|
96
|
+
|
|
97
|
+
user.verify_password("correct horse battery staple") # True
|
|
98
|
+
user.verify_password("wrong") # False
|
|
99
|
+
|
|
100
|
+
# After a successful login, upgrade the hash if its parameters are outdated
|
|
101
|
+
attempt = "correct horse battery staple"
|
|
102
|
+
if user.verify_password(attempt) and user.needs_rehash():
|
|
103
|
+
user.set_password(attempt)
|
|
104
|
+
# ...then persist the user
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`User.create` hashes the password with argon2 and never stores it. To load a
|
|
108
|
+
user from the database, pass the stored hash instead:
|
|
109
|
+
`User(email=..., password_hash=...)`. Supplying both `password` and
|
|
110
|
+
`password_hash` raises an error.
|
|
111
|
+
|
|
112
|
+
> **Warning:** `User.model_dump()` includes `password_hash`. Anything that
|
|
113
|
+
> leaves the API should use `UserPublic` (e.g. FastAPI's
|
|
114
|
+
> `response_model=UserPublic`).
|
|
115
|
+
|
|
116
|
+
## Conventions worth knowing
|
|
117
|
+
|
|
118
|
+
A few behaviours are deliberate and easy to trip over — see the [full
|
|
119
|
+
usage guide](https://ilc-models.readthedocs.io/en/latest/usage.html) for
|
|
120
|
+
detail:
|
|
121
|
+
|
|
122
|
+
- **`Goal.team` is the team credited with the goal, not the scorer's team.**
|
|
123
|
+
For an own goal the scorer belongs to the opposing team — call
|
|
124
|
+
`Match.event_team(event)` to resolve the team a player in an event
|
|
125
|
+
actually plays for.
|
|
126
|
+
- **Player equality compares `player_id` alone** (falling back to `name`
|
|
127
|
+
only when both IDs are `0`), because the upstream API spells player names
|
|
128
|
+
differently in event payloads versus player downloads.
|
|
129
|
+
- **`League.table()` models the Scottish-style split** — once a team has
|
|
130
|
+
played more than `League.split` matches, the table freezes the top/bottom
|
|
131
|
+
halves by position at the split point and sorts each half independently.
|
|
132
|
+
`League.split` is the number of matches each team plays before the split;
|
|
133
|
+
the default of `0` means no split.
|
|
134
|
+
- **The `team`, `teams`, `h2h` and `player` filters on `League.matches()`
|
|
135
|
+
are alternatives, not combinable.** If you pass more than one, only the
|
|
136
|
+
first applies, in that order. `League.match_players()` works the same way
|
|
137
|
+
(without `player`), and `Match.players()` prefers `teams` over `team`.
|
|
138
|
+
- **Dates are validated ISO strings, not `date` objects.** `Match.kickoff`
|
|
139
|
+
is a full offset-aware timestamp; `League.start`/`end` and
|
|
140
|
+
`Deduction.date` are `yyyy-mm-dd`. Use `Match.date` to get a
|
|
141
|
+
`datetime.date`.
|
|
142
|
+
- **`EventTime.plus` (stoppage time) is only valid at the end of a half** —
|
|
143
|
+
i.e. when `minutes` is 45, 90, 105 or 120.
|
|
144
|
+
|
|
145
|
+
## Documentation
|
|
146
|
+
|
|
147
|
+
Full API reference and usage guide:
|
|
148
|
+
[ilc-models.readthedocs.io](https://ilc-models.readthedocs.io/)
|
|
149
|
+
|
|
150
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release history.
|
|
151
|
+
|
|
152
|
+
## Development
|
|
153
|
+
|
|
154
|
+
Task runner is [`just`](https://github.com/casey/just); Python tooling is
|
|
155
|
+
[`uv`](https://docs.astral.sh/uv/).
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
just check # ruff check --fix, ruff format, then ty check (type checking)
|
|
159
|
+
just test # run tests with pytest
|
|
160
|
+
just cov # pytest with coverage, then regenerate the coverage badge
|
|
161
|
+
just docs # build the Sphinx docs locally
|
|
162
|
+
just tox # run the tests across Python 3.12-3.14 and lowest/highest dependencies
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
MIT — see [LICENSE.txt](./LICENSE.txt).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
alabaster==1.0.0
|
|
2
|
+
annotated-types==0.8.0
|
|
3
|
+
argon2-cffi==25.1.0
|
|
4
|
+
argon2-cffi-bindings==26.1.0
|
|
5
|
+
babel==2.18.0
|
|
6
|
+
certifi==2026.7.22
|
|
7
|
+
cffi==2.1.1
|
|
8
|
+
charset-normalizer==3.5.2
|
|
9
|
+
colorama==0.4.6 ; sys_platform == 'win32'
|
|
10
|
+
dnspython==2.9.0
|
|
11
|
+
docutils==0.22.4
|
|
12
|
+
email-validator==2.3.0
|
|
13
|
+
idna==3.20
|
|
14
|
+
imagesize==2.0.1
|
|
15
|
+
jinja2==3.1.6
|
|
16
|
+
markupsafe==3.0.4
|
|
17
|
+
packaging==26.3
|
|
18
|
+
pycparser==3.11 ; implementation_name != 'PyPy'
|
|
19
|
+
pydantic==2.14.1
|
|
20
|
+
pydantic-core==2.50.1
|
|
21
|
+
pygments==2.21.0
|
|
22
|
+
requests==2.34.2
|
|
23
|
+
roman-numerals==4.1.0
|
|
24
|
+
snowballstemmer==3.1.1
|
|
25
|
+
sphinx==9.1.0
|
|
26
|
+
sphinx-rtd-theme==3.1.0
|
|
27
|
+
sphinxcontrib-applehelp==2.0.0
|
|
28
|
+
sphinxcontrib-devhelp==2.0.0
|
|
29
|
+
sphinxcontrib-htmlhelp==2.1.0
|
|
30
|
+
sphinxcontrib-jquery==4.1
|
|
31
|
+
sphinxcontrib-jsmath==1.0.1
|
|
32
|
+
sphinxcontrib-qthelp==2.0.0
|
|
33
|
+
sphinxcontrib-serializinghtml==2.0.0
|
|
34
|
+
typing-extensions==4.16.0
|
|
35
|
+
typing-inspection==0.4.4
|
|
36
|
+
urllib3==2.8.0
|
|
@@ -15,13 +15,14 @@ sys.path.insert(0, str(Path("..", "..", "src").resolve()))
|
|
|
15
15
|
project = "ilc-models"
|
|
16
16
|
copyright = "2025, Neil Martin"
|
|
17
17
|
author = "Neil Martin"
|
|
18
|
-
release = "0.
|
|
18
|
+
release = "0.3.0"
|
|
19
19
|
|
|
20
20
|
# -- General configuration ---------------------------------------------------
|
|
21
21
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
22
22
|
|
|
23
23
|
extensions = [
|
|
24
24
|
"sphinx.ext.autodoc",
|
|
25
|
+
"sphinx.ext.napoleon",
|
|
25
26
|
"sphinx.ext.duration",
|
|
26
27
|
"sphinx.ext.intersphinx",
|
|
27
28
|
"sphinx.ext.viewcode",
|
|
@@ -31,10 +32,29 @@ extensions = [
|
|
|
31
32
|
templates_path = ["_templates"]
|
|
32
33
|
exclude_patterns = []
|
|
33
34
|
|
|
35
|
+
# Render single backticks as literals rather than italic title references
|
|
36
|
+
default_role = "literal"
|
|
37
|
+
|
|
34
38
|
intersphinx_mapping = {
|
|
35
39
|
"python": ("https://docs.python.org/3", None),
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
# -- Napoleon (Google-style docstrings) ---------------------------------------
|
|
43
|
+
# https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
|
|
44
|
+
|
|
45
|
+
napoleon_google_docstring = True
|
|
46
|
+
napoleon_numpy_docstring = False
|
|
47
|
+
napoleon_use_param = True
|
|
48
|
+
napoleon_use_rtype = True
|
|
49
|
+
napoleon_use_ivar = False
|
|
50
|
+
napoleon_attr_annotations = True
|
|
51
|
+
napoleon_preprocess_types = True
|
|
52
|
+
|
|
53
|
+
# -- Autodoc -------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
autodoc_typehints = "description"
|
|
56
|
+
autodoc_typehints_description_target = "documented_params"
|
|
57
|
+
|
|
38
58
|
# -- Options for HTML output -------------------------------------------------
|
|
39
59
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
40
60
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
ilc-models
|
|
2
|
+
==========
|
|
3
|
+
|
|
4
|
+
**Data models for the *ILC* project**
|
|
5
|
+
|
|
6
|
+
`ilc-models` is a set of pure Pydantic v2 models with no I/O. It forms the
|
|
7
|
+
shared data contract used across the `ilc-api`, `ilc-app` and `ilc-admin`
|
|
8
|
+
repositories - a `League` of `Match` objects, each with its `Lineups`,
|
|
9
|
+
`Goal`/`Card`/`Substitution` events, and the `TableRow` results computed
|
|
10
|
+
from them, plus `User` and `UserPublic` models for accounts. Its only
|
|
11
|
+
dependencies are `pydantic` (with the email extra) and `argon2-cffi`, which
|
|
12
|
+
`User` uses to hash passwords.
|
|
13
|
+
|
|
14
|
+
::
|
|
15
|
+
|
|
16
|
+
from ilc_models import League, Match, Teams, Score
|
|
17
|
+
|
|
18
|
+
league = League(
|
|
19
|
+
league_id=1,
|
|
20
|
+
name="Premiership",
|
|
21
|
+
year=2025,
|
|
22
|
+
start="2025-08-01",
|
|
23
|
+
end="2026-05-01",
|
|
24
|
+
current=True,
|
|
25
|
+
coverage={"lineups": True},
|
|
26
|
+
teams=["Team A", "Team B"],
|
|
27
|
+
rounds={
|
|
28
|
+
"1": [
|
|
29
|
+
Match(
|
|
30
|
+
match_id=1,
|
|
31
|
+
kickoff="2025-08-09T15:00:00+01:00",
|
|
32
|
+
round="1",
|
|
33
|
+
teams=Teams(home="Team A", away="Team B"),
|
|
34
|
+
status="FT",
|
|
35
|
+
score=Score(home=2, away=1),
|
|
36
|
+
)
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
for row in league.table():
|
|
42
|
+
print(row)
|
|
43
|
+
|
|
44
|
+
For more detail see the :doc:`usage` documentation.
|
|
45
|
+
|
|
46
|
+
Installation
|
|
47
|
+
------------
|
|
48
|
+
|
|
49
|
+
`ilc-models` requires Python 3.12 or later. To install, run::
|
|
50
|
+
|
|
51
|
+
(.venv) $ pip install ilc-models
|
|
52
|
+
|
|
53
|
+
Or with `uv <https://docs.astral.sh/uv/>`_::
|
|
54
|
+
|
|
55
|
+
$ uv add ilc-models
|
|
56
|
+
|
|
57
|
+
.. toctree::
|
|
58
|
+
:maxdepth: 2
|
|
59
|
+
:caption: Contents:
|
|
60
|
+
|
|
61
|
+
usage
|
|
62
|
+
api
|