ilc-models 0.2.4__tar.gz → 0.3.1__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.
Files changed (25) hide show
  1. {ilc_models-0.2.4 → ilc_models-0.3.1}/CHANGELOG.md +32 -1
  2. {ilc_models-0.2.4 → ilc_models-0.3.1}/CLAUDE.md +15 -5
  3. {ilc_models-0.2.4 → ilc_models-0.3.1}/PKG-INFO +53 -9
  4. {ilc_models-0.2.4 → ilc_models-0.3.1}/README.md +49 -7
  5. ilc_models-0.3.1/docs/requirements.txt +37 -0
  6. {ilc_models-0.2.4 → ilc_models-0.3.1}/docs/source/conf.py +1 -1
  7. {ilc_models-0.2.4 → ilc_models-0.3.1}/docs/source/index.rst +12 -6
  8. {ilc_models-0.2.4 → ilc_models-0.3.1}/docs/source/usage.rst +81 -14
  9. {ilc_models-0.2.4 → ilc_models-0.3.1}/justfile +16 -1
  10. {ilc_models-0.2.4 → ilc_models-0.3.1}/pyproject.toml +35 -8
  11. {ilc_models-0.2.4 → ilc_models-0.3.1}/src/ilc_models/__init__.py +200 -16
  12. {ilc_models-0.2.4 → ilc_models-0.3.1}/tests/test_models.py +147 -9
  13. ilc_models-0.3.1/uv.lock +1220 -0
  14. ilc_models-0.2.4/docs/requirements.txt +0 -30
  15. ilc_models-0.2.4/uv.lock +0 -795
  16. {ilc_models-0.2.4 → ilc_models-0.3.1}/.claude/settings.local.json +0 -0
  17. {ilc_models-0.2.4 → ilc_models-0.3.1}/.gitignore +0 -0
  18. {ilc_models-0.2.4 → ilc_models-0.3.1}/.python-version +0 -0
  19. {ilc_models-0.2.4 → ilc_models-0.3.1}/.readthedocs.yaml +0 -0
  20. {ilc_models-0.2.4 → ilc_models-0.3.1}/LICENSE.txt +0 -0
  21. {ilc_models-0.2.4 → ilc_models-0.3.1}/docs/source/_static/.gitkeep +0 -0
  22. {ilc_models-0.2.4 → ilc_models-0.3.1}/docs/source/api.rst +0 -0
  23. {ilc_models-0.2.4 → ilc_models-0.3.1}/src/ilc_models/py.typed +0 -0
  24. {ilc_models-0.2.4 → ilc_models-0.3.1}/tests/__init__.py +0 -0
  25. {ilc_models-0.2.4 → ilc_models-0.3.1}/tests/conftest.py +0 -0
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.1] - 2026-10-25
4
+
5
+ ### Added
6
+
7
+ - Add required `username` and `status` (`"pending"` or `"active"`, default `"pending"`) fields to `UserPublic`, and so to `User`
8
+ - Add `username` and `status` parameters to `User.create()`; `username` defaults to the part of the email address before the `@`
9
+
10
+ ## [0.3.0] - 2026-10-19
11
+
12
+ ### Added
13
+
14
+ - Add `UserPublic` model, the public view of a user (`email`, validated as `EmailStr`)
15
+ - Add `User` model, the stored view of a user, extending `UserPublic` with an argon2 `password_hash` (hidden from `repr`)
16
+ - Add `User.create()`, `User.verify_password()`, `User.needs_rehash()` and `User.set_password()` methods
17
+ - A `User` can be built from either a plain text `password` (hashed on validation) or a stored `password_hash`, but not both
18
+
19
+ ### Changed
20
+
21
+ - Add `argon2-cffi` and `pydantic[email]` as runtime dependencies
22
+
23
+ ### Documentation
24
+
25
+ - Document the `User` and `UserPublic` models in the README and usage guide
26
+ - Correct the usage guide's description of `League.events()` and document how the `matches()` filters, deductions and `League.split` behave
27
+ - Complete missing `Returns:` sections and clarify several field descriptions in the docstrings
28
+ - Fix the docs requirements lockfile, which was missing the new dependencies and so broke the Read the Docs build
29
+
3
30
  ## [0.2.4] - 2026-08-23
4
31
 
5
32
  ### Added
@@ -50,7 +77,7 @@
50
77
 
51
78
  ### Changed
52
79
 
53
- - Convert `RowTuple` to `Typing.NamedTuple` type
80
+ - Convert `RowTuple` to `typing.NamedTuple` type
54
81
 
55
82
  ## [0.1.8] - 2025-07-26
56
83
 
@@ -104,6 +131,10 @@
104
131
 
105
132
  _Initial release._
106
133
 
134
+ [0.3.1]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.3.1
135
+
136
+ [0.3.0]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.3.0
137
+
107
138
  [0.2.4]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.4
108
139
 
109
140
  [0.2.3]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.3
@@ -10,6 +10,10 @@ Task runner is `just` (see `justfile`); Python tooling is `uv`.
10
10
  just check # ruff check --fix, ruff format, then `ty check` (Astral's type checker)
11
11
  just test # uv run pytest
12
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)
13
17
  just sync # ff-only merge dev -> main, push, switch back to dev
14
18
  just tag # tag main with v<version> from pyproject.toml and push
15
19
  just publish # rm -rf dist, uv build, then uv publish to PyPI
@@ -21,20 +25,26 @@ Single test / narrower runs:
21
25
  uv run pytest tests/test_models.py::TestLeagueTable
22
26
  uv run pytest tests/test_models.py::TestMatch::test_players_from_team
23
27
  uv run pytest -p no:randomly # pytest-randomly shuffles order; disable when bisecting a failure
24
- uvx tox # full matrix: Python 3.12 and 3.13
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`)
25
29
  ```
26
30
 
27
31
  There is no `[tool.pytest.ini_options]` section — pytest runs on defaults with `tests/` discovered from the repo root.
28
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
+
29
35
  ## Release workflow
30
36
 
31
37
  Work happens on `dev`; `main` only ever receives fast-forward merges via `just sync`.
32
38
 
33
- 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 `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.
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.
34
40
 
35
41
  ## Architecture
36
42
 
37
- Everything is one module: `src/ilc_models/__init__.py`. Pure Pydantic v2 models with no I/O and no dependency beyond `pydantic` — 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`.
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.
38
48
 
39
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.
40
50
 
@@ -64,7 +74,7 @@ Style conventions:
64
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.
65
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__`.
66
76
 
67
- 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.
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`.
68
78
 
69
79
  ## Tests
70
80
 
@@ -72,4 +82,4 @@ Run `just docs` to build the docs locally (`-W`, so any Napoleon/autodoc warning
72
82
 
73
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.
74
84
 
75
- Coverage sits at 99%; genuinely unreachable defensive branches are marked `# pragma: no cover`.
85
+ Coverage sits at 100%; genuinely unreachable defensive branches are marked `# pragma: no cover`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ilc-models
3
- Version: 0.2.4
3
+ Version: 0.3.1
4
4
  Summary: Data models for the ILC project
5
5
  Project-URL: Repository, https://github.com/fourtreestech/ilc-models
6
6
  Project-URL: Documentation, https://ilc-models.readthedocs.io/
@@ -12,29 +12,35 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: Natural Language :: English
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
15
16
  Classifier: Topic :: Software Development :: Libraries
16
17
  Classifier: Typing :: Typed
17
18
  Requires-Python: >=3.12
18
- Requires-Dist: pydantic>=2.12.5
19
+ Requires-Dist: argon2-cffi>=25.1.0
20
+ Requires-Dist: pydantic[email]>=2.12.5
19
21
  Description-Content-Type: text/markdown
20
22
 
21
23
  # ilc-models
22
24
 
23
- ![version](https://img.shields.io/badge/version-0.2.4-blue)
25
+ ![version](https://img.shields.io/badge/version-0.3.1-blue)
24
26
  ![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Ffourtreestech%2Filc-models%2Fmain%2Fpyproject.toml)
25
27
  ![coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)
26
28
 
27
29
  **ilc-models** contains all data models for the *ILC* project.
28
30
 
29
- It's a set of pure Pydantic v2 models with no I/O and no dependency beyond
30
- `pydantic` — a `League` of `Match` objects, each with its `Lineups`,
31
- `Goal`/`Card`/`Substitution` events, and the `TableRow` results computed
32
- from them. This package is the shared data contract used across the
33
- `ilc-api`, `ilc-app` and `ilc-admin` repositories, so a field change here is
34
- a breaking change for all three.
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.
35
39
 
36
40
  ## Installation
37
41
 
42
+ Requires Python 3.12 or later.
43
+
38
44
  ```bash
39
45
  pip install ilc-models
40
46
  ```
@@ -100,6 +106,37 @@ League
100
106
  every `Player` who has featured in the league, keyed by `player_id` as a
101
107
  string.
102
108
 
109
+ Users are modelled separately: `User` (the stored shape, including
110
+ `password_hash`) subclasses `UserPublic` (`email`, `username` and `status`).
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. `username`
130
+ defaults to the part of the email address before the `@`, and `status` to
131
+ `"pending"` (the other value is `"active"`); both can be passed as keyword
132
+ arguments. To load a user from the database, pass the stored hash instead:
133
+ `User(email=..., username=..., password_hash=...)`. Supplying both `password` and
134
+ `password_hash` raises an error.
135
+
136
+ > **Warning:** `User.model_dump()` includes `password_hash`. Anything that
137
+ > leaves the API should use `UserPublic` (e.g. FastAPI's
138
+ > `response_model=UserPublic`).
139
+
103
140
  ## Conventions worth knowing
104
141
 
105
142
  A few behaviours are deliberate and easy to trip over — see the [full
@@ -116,6 +153,12 @@ detail:
116
153
  - **`League.table()` models the Scottish-style split** — once a team has
117
154
  played more than `League.split` matches, the table freezes the top/bottom
118
155
  halves by position at the split point and sorts each half independently.
156
+ `League.split` is the number of matches each team plays before the split;
157
+ the default of `0` means no split.
158
+ - **The `team`, `teams`, `h2h` and `player` filters on `League.matches()`
159
+ are alternatives, not combinable.** If you pass more than one, only the
160
+ first applies, in that order. `League.match_players()` works the same way
161
+ (without `player`), and `Match.players()` prefers `teams` over `team`.
119
162
  - **Dates are validated ISO strings, not `date` objects.** `Match.kickoff`
120
163
  is a full offset-aware timestamp; `League.start`/`end` and
121
164
  `Deduction.date` are `yyyy-mm-dd`. Use `Match.date` to get a
@@ -140,6 +183,7 @@ just check # ruff check --fix, ruff format, then ty check (type checking)
140
183
  just test # run tests with pytest
141
184
  just cov # pytest with coverage, then regenerate the coverage badge
142
185
  just docs # build the Sphinx docs locally
186
+ just tox # run the tests across Python 3.12-3.14 and lowest/highest dependencies
143
187
  ```
144
188
 
145
189
  ## License
@@ -1,20 +1,24 @@
1
1
  # ilc-models
2
2
 
3
- ![version](https://img.shields.io/badge/version-0.2.4-blue)
3
+ ![version](https://img.shields.io/badge/version-0.3.1-blue)
4
4
  ![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Ffourtreestech%2Filc-models%2Fmain%2Fpyproject.toml)
5
5
  ![coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)
6
6
 
7
7
  **ilc-models** contains all data models for the *ILC* project.
8
8
 
9
- It's a set of pure Pydantic v2 models with no I/O and no dependency beyond
10
- `pydantic` — a `League` of `Match` objects, each with its `Lineups`,
11
- `Goal`/`Card`/`Substitution` events, and the `TableRow` results computed
12
- from them. This package is the shared data contract used across the
13
- `ilc-api`, `ilc-app` and `ilc-admin` repositories, so a field change here is
14
- a breaking change for all three.
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.
15
17
 
16
18
  ## Installation
17
19
 
20
+ Requires Python 3.12 or later.
21
+
18
22
  ```bash
19
23
  pip install ilc-models
20
24
  ```
@@ -80,6 +84,37 @@ League
80
84
  every `Player` who has featured in the league, keyed by `player_id` as a
81
85
  string.
82
86
 
87
+ Users are modelled separately: `User` (the stored shape, including
88
+ `password_hash`) subclasses `UserPublic` (`email`, `username` and `status`).
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. `username`
108
+ defaults to the part of the email address before the `@`, and `status` to
109
+ `"pending"` (the other value is `"active"`); both can be passed as keyword
110
+ arguments. To load a user from the database, pass the stored hash instead:
111
+ `User(email=..., username=..., password_hash=...)`. Supplying both `password` and
112
+ `password_hash` raises an error.
113
+
114
+ > **Warning:** `User.model_dump()` includes `password_hash`. Anything that
115
+ > leaves the API should use `UserPublic` (e.g. FastAPI's
116
+ > `response_model=UserPublic`).
117
+
83
118
  ## Conventions worth knowing
84
119
 
85
120
  A few behaviours are deliberate and easy to trip over — see the [full
@@ -96,6 +131,12 @@ detail:
96
131
  - **`League.table()` models the Scottish-style split** — once a team has
97
132
  played more than `League.split` matches, the table freezes the top/bottom
98
133
  halves by position at the split point and sorts each half independently.
134
+ `League.split` is the number of matches each team plays before the split;
135
+ the default of `0` means no split.
136
+ - **The `team`, `teams`, `h2h` and `player` filters on `League.matches()`
137
+ are alternatives, not combinable.** If you pass more than one, only the
138
+ first applies, in that order. `League.match_players()` works the same way
139
+ (without `player`), and `Match.players()` prefers `teams` over `team`.
99
140
  - **Dates are validated ISO strings, not `date` objects.** `Match.kickoff`
100
141
  is a full offset-aware timestamp; `League.start`/`end` and
101
142
  `Deduction.date` are `yyyy-mm-dd`. Use `Match.date` to get a
@@ -120,6 +161,7 @@ just check # ruff check --fix, ruff format, then ty check (type checking)
120
161
  just test # run tests with pytest
121
162
  just cov # pytest with coverage, then regenerate the coverage badge
122
163
  just docs # build the Sphinx docs locally
164
+ just tox # run the tests across Python 3.12-3.14 and lowest/highest dependencies
123
165
  ```
124
166
 
125
167
  ## License
@@ -0,0 +1,37 @@
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.10.23
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.12 ; 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.1 ; python_full_version < '3.13'
26
+ sphinx==9.2.0 ; python_full_version >= '3.13'
27
+ sphinx-rtd-theme==3.1.0
28
+ sphinxcontrib-applehelp==2.0.0
29
+ sphinxcontrib-devhelp==2.0.0
30
+ sphinxcontrib-htmlhelp==2.1.0
31
+ sphinxcontrib-jquery==4.1
32
+ sphinxcontrib-jsmath==2.0.0
33
+ sphinxcontrib-qthelp==2.0.0
34
+ sphinxcontrib-serializinghtml==2.0.0
35
+ typing-extensions==4.16.0
36
+ typing-inspection==0.4.4
37
+ urllib3==2.8.0
@@ -15,7 +15,7 @@ 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.2.4"
18
+ release = "0.3.1"
19
19
 
20
20
  # -- General configuration ---------------------------------------------------
21
21
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -3,11 +3,13 @@ ilc-models
3
3
 
4
4
  **Data models for the *ILC* project**
5
5
 
6
- `ilc-models` is a set of pure Pydantic v2 models with no I/O and no
7
- dependency beyond `pydantic`. It forms the shared data contract used across
8
- the `ilc-api`, `ilc-app` and `ilc-admin` repositories - a `League` of
9
- `Match` objects, each with its `Lineups`, `Goal`/`Card`/`Substitution`
10
- events, and the `TableRow` results computed from them.
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.
11
13
 
12
14
  ::
13
15
 
@@ -44,10 +46,14 @@ For more detail see the :doc:`usage` documentation.
44
46
  Installation
45
47
  ------------
46
48
 
47
- To install, run::
49
+ `ilc-models` requires Python 3.12 or later. To install, run::
48
50
 
49
51
  (.venv) $ pip install ilc-models
50
52
 
53
+ Or with `uv <https://docs.astral.sh/uv/>`_::
54
+
55
+ $ uv add ilc-models
56
+
51
57
  .. toctree::
52
58
  :maxdepth: 2
53
59
  :caption: Contents:
@@ -5,6 +5,8 @@ Usage
5
5
  configure and nothing that talks to a network or a database - you build model
6
6
  instances (typically from JSON returned by an upstream API, or from
7
7
  `model_validate`), pass them around, and call the methods described below.
8
+ The only behaviour beyond plain Pydantic validation is the password hashing
9
+ done by `User`, described under `Users`_.
8
10
 
9
11
  Model map
10
12
  ---------
@@ -140,20 +142,29 @@ Leagues
140
142
  `start`, `end`, `current`, `coverage`), the season data (`teams`, `rounds`,
141
143
  `excluded`, `deductions`, `split`), and every `Player` seen in the league,
142
144
  keyed by `player_id` as a string (`players`). `title` combines `name` with
143
- the season derived from `start`/`end`, e.g. Premiership 2025/26.
144
-
145
- `matches(team=, teams=, h2h=)` returns every match across all rounds,
146
- filtered by the same rules as `Match.involves`/`involves_any`/`h2h`, sorted
147
- by date and then home team name. `match_players(team=, teams=, h2h=)` layers
148
- `Match.players` over that filtered match list to return every player
149
- involved, in first-seen order. `head_to_head(teams)` predates
150
- `matches(h2h=...)` and returns the same result; prefer the parameterised
151
- `matches()`/`match_players()` filters for new code.
145
+ the season derived from `start`/`end`, e.g. Premiership 2025/26. `split` is
146
+ the number of matches each team plays before the league splits into top and
147
+ bottom halves (see `League tables`_); the default of `0` means no split.
148
+
149
+ `matches(team=, teams=, h2h=, player=)` returns every match across all
150
+ rounds, sorted by date and then home team name. The first four filters
151
+ follow the same rules as `Match.involves`, `Match.involves_any`,
152
+ `Match.h2h` and `Match.players` (for `player`). They are alternatives, not
153
+ combinable: if you pass more than one, only the first applies, in the order
154
+ `team`, `teams`, `h2h`, `player`.
155
+
156
+ `match_players(team=, teams=, h2h=)` applies the same match filter, then
157
+ layers `Match.players` over the result to return every player involved, in
158
+ first-seen order. The same precedence applies, and `team`/`teams` also
159
+ restrict which players are returned from each match. `head_to_head(teams)`
160
+ predates `matches(h2h=...)` and returns the same result; prefer the
161
+ parameterised `matches()`/`match_players()` filters for new code.
152
162
 
153
163
  `events(player)` returns every `EventInfo` (event plus match date, teams and
154
- score) in which `player` is involved across the league, including a
155
- synthesised `LineupStatus` for any match where the player appears in a
156
- lineup but has no other event.
164
+ score) in which `player` is involved across the league. For each match where
165
+ the player appears in a lineup, this includes a `LineupStatus` (synthesised
166
+ on the fly, not stored) recording whether they started or were a substitute,
167
+ followed by any goals, cards or substitutions involving them.
157
168
 
158
169
  `update_player(old, new, team=)` walks every match and replaces `old` with
159
170
  `new` wherever it's found - in lineups and in event player references -
@@ -201,8 +212,10 @@ and each half is then sorted independently. An odd number of teams puts the
201
212
  extra team into the top half.
202
213
 
203
214
  Points deductions apply if `Deduction.date` is the empty string (applied
204
- from the start of the season) or falls on or before the last match date
205
- processed - a deduction dated after the table's cutoff is not yet applied.
215
+ from the start of the season) or falls on or before the table's cutoff, which
216
+ is the date of the last match counted - or `date`, if that argument stopped
217
+ the table early. A deduction dated after the cutoff is not yet applied, and
218
+ if no matches have been played only undated deductions apply.
206
219
 
207
220
  Date validation
208
221
  ----------------
@@ -225,6 +238,53 @@ value like month 19 or 29 February in a non-leap year raises `ValueError`
225
238
  even though it matches the format. Use `Match.date` to get a `datetime.date`
226
239
  from `kickoff` rather than parsing the string yourself.
227
240
 
241
+ The one exception is `EventInfo.date`, which is a real `datetime.date`: it is
242
+ produced by `League.events` from `Match.date`.
243
+
244
+ Users
245
+ -----
246
+
247
+ `UserPublic` is the shape that is safe to send out of the API: it holds only
248
+ `email` (validated as an email address), `username` and `status` (`"pending"`
249
+ or `"active"`, defaulting to `"pending"`). `User` is the stored shape, a
250
+ subclass of `UserPublic` that adds `password_hash`, an argon2 hash of the
251
+ user's password. Fields that must never leave the API belong on `User` only,
252
+ so API endpoints should declare `response_model=UserPublic`.
253
+
254
+ There are two ways to build a `User`:
255
+
256
+ * From a plain text password, which is hashed and not kept::
257
+
258
+ user = User.create("alice@example.com", "s3cret")
259
+ # username defaults to "alice" and status to "pending"; override with
260
+ # User.create(..., username="al", status="active")
261
+ # equivalent: User.model_validate(
262
+ # {"email": ..., "username": ..., "password": ...}
263
+ # )
264
+
265
+ * From a hash loaded from the database::
266
+
267
+ user = User(
268
+ email="alice@example.com", username="alice", password_hash=stored_hash
269
+ )
270
+
271
+ Supplying both `password` and `password_hash` raises a `ValidationError`, as
272
+ does an empty or non-string password. `password_hash` is left out of the
273
+ `repr` so it doesn't end up in logs, but it *is* included in `model_dump()`.
274
+
275
+ `verify_password(attempt)` returns `True` if the attempt matches, and `False`
276
+ if it doesn't or if the stored hash is malformed. It never modifies the user.
277
+ To upgrade a hash made with outdated parameters, check `needs_rehash()` after
278
+ a successful login, call `set_password()`, and then persist the user - the
279
+ models do no I/O, so saving is the caller's job::
280
+
281
+ if user.verify_password(attempt) and user.needs_rehash():
282
+ user.set_password(attempt)
283
+ save(user) # your own persistence code
284
+
285
+ `set_password(password)` raises `ValueError` if the password is empty or not
286
+ a string.
287
+
228
288
  Serialisation
229
289
  -------------
230
290
 
@@ -235,3 +295,10 @@ applies - this is how the models cross between `ilc-api`, `ilc-app` and
235
295
  data = match.model_dump()
236
296
  restored = Match.model_validate(data)
237
297
  assert restored == match
298
+
299
+ .. warning::
300
+
301
+ `User.model_dump()` includes `password_hash`. Before sending a user
302
+ anywhere outside the API, convert it to the public shape::
303
+
304
+ public = UserPublic.model_validate(user.model_dump())
@@ -1,5 +1,5 @@
1
1
  # Read version from pyproject.toml
2
- version := `grep '^version' pyproject.toml | cut -d'"' -f2`
2
+ version := `grep '^version = "' pyproject.toml | cut -d'"' -f2`
3
3
 
4
4
  # Default: list available tasks
5
5
  default:
@@ -19,10 +19,25 @@ cov:
19
19
  uv run pytest --cov --cov-report term-missing --cov-report json
20
20
  uv run cov-badge
21
21
 
22
+ # Upgrade dependencies
23
+ upgrade:
24
+ uv lock --upgrade
25
+ uv sync
26
+ uv export --no-default-groups --group docs --no-emit-project --no-hashes --no-header --no-annotate -q > docs/requirements.txt
27
+ uvx tox
28
+
29
+ # Run tox
30
+ tox:
31
+ uvx tox
32
+
22
33
  # Build the docs
23
34
  docs:
24
35
  uv run --group docs sphinx-build -W --keep-going -b html docs/source docs/build/html
25
36
 
37
+ # Bump patch version
38
+ bump:
39
+ uvx bumpver update --patch
40
+
26
41
  # Merge dev into main and push
27
42
  sync:
28
43
  git switch main
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ilc-models"
3
- version = "0.2.4"
3
+ version = "0.3.1"
4
4
  description = "Data models for the ILC project"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -9,7 +9,8 @@ authors = [
9
9
  requires-python = ">=3.12"
10
10
  license = "MIT"
11
11
  dependencies = [
12
- "pydantic>=2.12.5",
12
+ "argon2-cffi>=25.1.0",
13
+ "pydantic[email]>=2.12.5",
13
14
  ]
14
15
  classifiers = [
15
16
  "Development Status :: 4 - Beta",
@@ -19,6 +20,7 @@ classifiers = [
19
20
  "Typing :: Typed",
20
21
  "Programming Language :: Python :: 3.12",
21
22
  "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
22
24
  ]
23
25
 
24
26
  [project.urls]
@@ -30,7 +32,7 @@ requires = ["hatchling"]
30
32
  build-backend = "hatchling.build"
31
33
 
32
34
  [tool.bumpver]
33
- current_version = "0.2.4"
35
+ current_version = "0.3.1"
34
36
  version_pattern = "MAJOR.MINOR.PATCH"
35
37
  commit_message = "Bump version {old_version} -> {new_version}"
36
38
  tag_message = "{new_version}"
@@ -55,6 +57,9 @@ push = false
55
57
  'release = "{version}"'
56
58
  ]
57
59
 
60
+ [tool.uv]
61
+ default-groups = ["dev", "test"]
62
+
58
63
  [tool.ruff.lint]
59
64
  select = ["F", "I", "B", "C4", "SIM", "RUF", "D", "D401"]
60
65
 
@@ -66,23 +71,45 @@ convention = "google"
66
71
  "docs/*" = ["D"]
67
72
 
68
73
  [tool.tox]
69
- requires = ["tox>=4.25"]
70
- env_list = ["3.13", "3.12"]
74
+ requires = ["tox>=4.24", "tox-uv>=1.37.0"]
75
+ env_list = ["3.14", "3.13", "3.12", "lowest", "highest"]
71
76
 
72
77
  [tool.tox.env_run_base]
73
78
  description = "Run tests under {base_python}"
74
- deps = ["pytest>=9", "pytest-cov>=7", "pytest-randomly>=4", "ilc_provider>=0.1.3"]
79
+ runner = "uv-venv-lock-runner"
80
+ package = "editable"
81
+ dependency_groups = ["test"]
75
82
  commands = [["pytest"]]
76
83
 
84
+ [tool.tox.env.lowest]
85
+ description = "Run tests under {base_python} with lowest dependency versions"
86
+ runner = "uv-venv-runner"
87
+ base_python = ["python3.12"]
88
+ skip_install = true
89
+ dependency_groups = []
90
+ allowlist_externals = ["uv"]
91
+ commands_pre = [["uv", "pip", "install", "--resolution", "lowest", "-e", ".", "--group", "pyproject.toml:test", "tzdata>=2025.1", "cffi>=1.16.0", "argon2-cffi-bindings>=21.2.0", "pycparser>=2.21"]]
92
+
93
+ [tool.tox.env.highest]
94
+ description = "Run tests under {base_python} with highest dependency versions"
95
+ runner = "uv-venv-runner"
96
+ base_python = ["python3.14"]
97
+ skip_install = true
98
+ dependency_groups = []
99
+ allowlist_externals = ["uv"]
100
+ commands_pre = [["uv", "pip", "install", "--resolution", "highest", "--upgrade", "-e", ".", "--group", "pyproject.toml:test"]]
101
+
77
102
  [dependency-groups]
78
103
  dev = [
79
104
  "cov-badge>=0.1.1",
80
105
  "faker>=40.1.2",
106
+ "pytest-cov>=7.0.0",
107
+ "rich>=14.2.0",
108
+ ]
109
+ test = [
81
110
  "ilc-provider>=0.1.3",
82
111
  "pytest>=9.0.2",
83
- "pytest-cov>=7.0.0",
84
112
  "pytest-randomly>=4.0.1",
85
- "rich>=14.2.0",
86
113
  ]
87
114
  docs = [
88
115
  "sphinx>=9.1.0",