Skip to content

Commit b79f0e8

Browse files
committed
Merge remote-tracking branch 'origin/dev' into docs/249-338-doc-corrections
# Conflicts: # CHANGELOG.md
2 parents 12135c6 + b53e2f7 commit b79f0e8

30 files changed

Lines changed: 1429 additions & 134 deletions

‎.github/workflows/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ CI/CD workflows for the Stickler project.
99
| `security.yaml` | PR, push to `dev`/`main` | Bandit + ASH security scans; uploads `security-reports` artifact |
1010
| `security-pr-comment.yaml` | `workflow_run` after Security Scan | Posts/updates the ASH summary as a PR comment |
1111
| `docs.yml` | push to `main` (src/docs paths) | Deploys MkDocs site to GitHub Pages |
12+
| `docs-check.yml` | PR (docs/source/dependency/workflow paths) | Builds docs with the docs group and rejects link/navigation diagnostics; cancels superseded builds; no deployment |
1213
| `workflow.yml` | release published | Builds and publishes to PyPI and TestPyPI (trusted publishing via OIDC) |
1314

1415
## Conventions
1516

17+
`Check Documentation` must remain a non-required check: its path filter means
18+
unrelated PRs do not report a status. Making it required would leave those PRs
19+
waiting indefinitely.
20+
1621
- **SHA pinning**: all `uses:` references are pinned to full 40-character
1722
commit SHAs with a trailing `# vX.Y.Z` comment (supply-chain hardening;
1823
mutable tags can be repointed). Dependabot (`.github/dependabot.yml`)

‎.github/workflows/docs-check.yml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Check Documentation
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'docs/**'
7+
- 'src/**'
8+
- 'pyproject.toml'
9+
- 'uv.lock'
10+
- '.github/workflows/docs-check.yml'
11+
12+
permissions:
13+
contents: read
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
24+
with:
25+
persist-credentials: false
26+
- name: Set up uv
27+
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
28+
with:
29+
python-version: "3.12"
30+
- name: Build and check documentation links
31+
run: uv run --frozen --only-group docs python docs/check_links.py

‎CHANGELOG.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ Each release links to full notes on the
6060
later on subscripting
6161
([#350](https://github.com/awslabs/stickler/issues/350))
6262

63+
- **Breaking:** a `None` element in a list is now absent. It is left out
64+
before matching, so it is never paired, counted or scored, and a list of only
65+
`None` is an empty list. A float `NaN` element counts as `None`; an empty
66+
string is still a value. This holds for lists of models and of primitives,
67+
in `compare_with()` and `compare()`, and reports keep each element's
68+
original index. Counting a `None` as an element credited two of them as a
69+
true positive, and counted a missed row as a false discovery, or as a true
70+
positive in a list of models, so recall stayed at `1.0`. For lists holding a
71+
`None`:
72+
- `[A, None]` against `[A, None]` is 1 TP, not 2;
73+
- `[A, B, C]` against `[A, None, C]` is 2 TP and 1 FN, where the missed `B`
74+
was an FD in a list of strings and a TP in a list of models;
75+
- `[A]` against `[None]` is an FN and `[None]` against `[A]` an FA, both
76+
previously FD, except a model against `None`, which was a TP;
77+
- `[None]` against `[None]` is a TN, not a TP.
78+
79+
It also removes the order dependence these lists had. What a list held was
80+
read from its first element, so `[None, Model]` was treated as a list of
81+
primitives: the class gate and field-by-field scoring were skipped, and a
82+
`Cat` scored against a `Dog` got `0.961` with no warning
83+
([#386](https://github.com/awslabs/stickler/issues/386)). The element class's
84+
`match_threshold` was likewise replaced by the parent's
85+
([#322](https://github.com/awslabs/stickler/issues/322)). See
86+
[`None` elements in a list](https://awslabs.github.io/stickler/Advanced/classification-logic/#none-elements-in-a-list)
87+
6388
### Fixed
6489

6590
- **A `RootModel` is now refused when the evaluator is built, instead of failing
@@ -108,6 +133,22 @@ Each release links to full notes on the
108133
Keyed on the leaf name alone, the first model built in a process silenced every
109134
later one carrying the same typo.
110135

136+
- **The pretty printers no longer report success over results that carry no
137+
non-match records.** `print_non_matches` and `print_evaluation_results` printed
138+
`✅ No non-matches found - all fields matched successfully!` for `EvalResult.raw`
139+
or a `compare_with()` dict computed without `document_non_matches=True`,
140+
including one with a wrong field, because that dict has no `non_matches` key
141+
and the printers fell back to the always-empty `confusion_matrix["non_matches"]`
142+
placeholder. They now say the records are missing and how to collect them. The
143+
same applies to a bulk `ProcessEvaluation` built with
144+
`document_non_matches=False`. `print_non_matches` on input that is not a result
145+
at all now prints an error. An empty record list still prints a success
146+
message, now `✅ No non-matches found.` without the `all_fields_matched`
147+
wording removed in #287. An `evaluator_format=True` dict still prints that
148+
success without records, because it always carries a `non_matches` list,
149+
empty unless records were requested
150+
([#298](https://github.com/awslabs/stickler/issues/298))
151+
111152
### Documentation
112153

113154
- Corrected the last row of the 1.0.0 table under "The element gate judges a

‎docs/Makefile‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# automatic navigation generation from directory structure.
66

77
# Declare phony targets (targets that don't represent files)
8-
.PHONY: install docs build deploy clean
8+
.PHONY: install docs build check deploy clean
99

1010
# install: Install all documentation dependencies
1111
#
@@ -35,18 +35,19 @@ docs:
3535

3636
# build: Build static site for production
3737
#
38-
# Generates the complete static site in the site/ directory. This validates:
39-
# - All Markdown files compile correctly
40-
# - Internal links resolve properly
41-
# - API documentation generates without errors
42-
# - Theme assets are bundled correctly
38+
# Generates the complete static site in site/ and reports diagnostics.
39+
# Warnings do not fail an ordinary build; use make check to enforce them.
4340
#
4441
# The site/ directory can be served by any static web server.
4542
#
4643
# Usage: make build
4744
build:
4845
uv run mkdocs build
4946

47+
# check: Build the site and enforce the pull-request documentation gate
48+
check:
49+
uv run --frozen --only-group docs python check_links.py
50+
5051
# deploy: Deploy site to GitHub Pages
5152
#
5253
# Builds the site and deploys it to the gh-pages branch using MkDocs' built-in
@@ -70,4 +71,4 @@ deploy:
7071
#
7172
# Usage: make clean
7273
clean:
73-
rm -rf site/
74+
rm -rf site/

‎docs/README.md‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,30 @@ Verify the site builds without errors:
4747
uv run mkdocs build
4848
```
4949

50-
This generates the static site in `site/` and validates all internal links and references.
50+
This generates the static site in `site/` and reports link diagnostics. An ordinary
51+
build does not fail on warnings; use the checker below to enforce them. Link
52+
validation levels are shared in `mkdocs.yml`, so `mkdocs serve` shows them too.
53+
54+
To run the pull-request check from the repository root:
55+
56+
```bash
57+
uv run --frozen python docs/check_links.py
58+
uv run --frozen pytest tests/test_docs_build.py
59+
```
60+
61+
The checker fails on logged MkDocs warnings and errors, including awesome-nav
62+
failures, orphan pages, missing pages/images/anchors, broken API references, and
63+
unrecognized or absolute links. It tolerates each of the six existing griffe
64+
annotation warnings once per build, identified by logger, file and message in
65+
`check_links.py`. Line numbers may change; duplicate or changed warnings and all
66+
errors fail. All warnings remain visible, and no autorefs warning is exempt. Python
67+
warnings such as `DeprecationWarning` are not routed into the gate. External URLs
68+
are not fetched. Run `make check` from this directory for the same gate.
69+
The read-only `docs-check.yml` workflow
70+
runs for documentation, source, dependency, or checker-workflow changes and never
71+
deploys the site. Its `uv run --only-group docs` installs the docs group without
72+
installing the project; the regular test workflow runs
73+
the checker's tests.
5174

5275
## Deployment
5376

@@ -68,4 +91,4 @@ Automatic deployment is configured in `.github/workflows/docs.yml`. The workflow
6891

6992
---
7093

71-
> **Note**: A `Makefile` is provided for convenience with targets: `install`, `docs`, `build`, `deploy`, and `clean`.
94+
> **Note**: A `Makefile` is provided for convenience with targets: `install`, `docs`, `build`, `check`, `deploy`, and `clean`.

‎docs/check_links.py‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""Build docs, tolerating each of six known annotation warnings once per build.
2+
3+
Python warnings (such as DeprecationWarning) are not routed into this gate.
4+
"""
5+
6+
import argparse
7+
import logging
8+
import re
9+
from pathlib import Path
10+
11+
from mkdocs.commands.build import build
12+
from mkdocs.config import load_config
13+
from mkdocs.exceptions import MkDocsException
14+
15+
# Issue #355's existing annotation warnings. Files and messages stay explicit;
16+
# line numbers can move without changing the diagnostic.
17+
_GRIFFE_WARNINGS = {
18+
"griffe: src/stickler/structured_object_evaluator/" + warning
19+
for warning in (
20+
"bulk_structured_model_evaluator.py: No type or annotation for parameter 'df'",
21+
"models/structured_model.py: No type or annotation for parameter '**kwargs'",
22+
"models/structured_model.py: No type or annotation for returned value 1",
23+
"models/comparable_field.py: No type or annotation for parameter '**field_kwargs'",
24+
"models/comparable_field.py: No type or annotation for returned value 1",
25+
"models/field.py: No type or annotation for parameter '**kwargs'",
26+
)
27+
}
28+
29+
30+
class _LinkWarnings(logging.Handler):
31+
def __init__(self):
32+
super().__init__(level=logging.WARNING)
33+
self.count = 0
34+
self.remaining_warnings = _GRIFFE_WARNINGS.copy()
35+
36+
def emit(self, record):
37+
message = record.getMessage().replace("\\", "/")
38+
if record.levelno == logging.WARNING and record.name == "mkdocs.plugins.griffe":
39+
# griffe uses absolute paths when invoked from docs/ (make check).
40+
message = re.sub(
41+
r"^griffe: (?:.*?/)?(src/stickler/[^:]+):\d+: ",
42+
r"griffe: \1: ",
43+
message,
44+
)
45+
if message in self.remaining_warnings:
46+
self.remaining_warnings.remove(message)
47+
return
48+
self.count += 1
49+
50+
51+
def check_links(config_file: str, site_dir: str | None = None) -> int:
52+
"""Build a site and return nonzero for broken links; build errors propagate."""
53+
counter = _LinkWarnings()
54+
logger = logging.getLogger("mkdocs")
55+
logger.addHandler(counter)
56+
try:
57+
# Configuration and plugin loading can emit warnings before build().
58+
config = load_config(config_file=config_file, site_dir=site_dir)
59+
config.plugins.on_startup(command="build", dirty=False)
60+
try:
61+
build(config)
62+
finally:
63+
config.plugins.on_shutdown()
64+
finally:
65+
logger.removeHandler(counter)
66+
counter.close()
67+
if counter.count:
68+
logger.error(
69+
"Documentation check failed: %d warning(s) or error(s).",
70+
counter.count,
71+
)
72+
return 1
73+
return 0
74+
75+
76+
def main() -> int:
77+
"""Run the same build-only check locally and in pull-request CI."""
78+
parser = argparse.ArgumentParser(description=__doc__)
79+
parser.add_argument(
80+
"-f", "--config-file", default=str(Path(__file__).with_name("mkdocs.yml"))
81+
)
82+
parser.add_argument("-d", "--site-dir")
83+
args = parser.parse_args()
84+
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s")
85+
try:
86+
return check_links(args.config_file, args.site_dir)
87+
except MkDocsException as error:
88+
logging.getLogger("mkdocs").error("%s", error)
89+
return 1
90+
91+
92+
if __name__ == "__main__":
93+
raise SystemExit(main())

‎docs/docs/Advanced/classification-logic.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ Lists use the [Hungarian algorithm](hungarian-matching.md) for optimal element p
4141
1. **Empty lists**: `[] vs []` is TN; `[] vs [items]` produces one FA per item; `[items] vs []` produces one FN per item.
4242
2. **Matched elements**: similarity >= threshold is TP; below threshold is FD.
4343
3. **Unmatched elements**: leftover GT elements are FN; leftover EST elements are FA.
44+
4. **`None` elements**: absent, so they are not matched or counted. A list of only `None` is an empty list. See [`None` elements in a list](#none-elements-in-a-list).
45+
46+
#### `None` elements in a list {: #none-elements-in-a-list }
47+
48+
A `None` element marks an absence, not an object or a value, so it is left out before matching. This holds for a list field of models (`List[Optional[Model]]`) or of primitives (`List[Optional[str]]`), at any depth, and for a float `NaN` element, which counts as `None`. An empty string element is still a value. A list inside a list (`List[List[str]]`) or a dict value is compared as one whole value, so its `None`s are part of that value.
49+
50+
| GT | EST | Result |
51+
|---|---|---|
52+
| `[A, None]` | `[A, None]` | 1 TP |
53+
| `[A, B, C]` | `[A, None, C]` | 2 TP, 1 FN: `B` was missed |
54+
| `[A]` | `[None]` | 1 FN, as `[A] vs []` |
55+
| `[None]` | `[A]` | 1 FA, as `[] vs [A]` |
56+
| `[None]` | `[None]` | TN, as `[] vs []` |
57+
58+
This follows the null rules above: an absent value against a present one is an FN or FA, and two absences are not evidence of a match. Counting a `None` as an element would credit two `None`s as a TP, and would count a missed row as an FD (or, in a list of models, a TP), so the miss would keep recall at `1.0`. Elements keep their original positions in reports: in `[A, None, C]`, `C` is reported as `[2]`.
59+
60+
- **Positional lists are not supported either way.** Matching ignores order, so a `None` cannot mean "slot 3 is empty": `[None, A]` and `[A, None]` already compare as identical. Put the position in the data instead, for example a `page_number` field, and matching pairs elements by it.
61+
- **To score an absence, give it content.** If ground truth marks a row as unreadable and agreeing on that should earn credit, model it as a value, such as `Line(status="illegible")`. A `None` carries nothing to compare.
4462

4563
#### Example: Mixed Matching
4664

‎docs/docs/Advanced/hungarian-matching.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ ELSE:
207207

208208
- **Equal length** -- Every element gets paired. Only TP and FD are possible.
209209
- **Unequal length** -- Extra GT items become FN; extra Pred items become FA.
210+
- **`None` elements** -- Left out before matching, so they are never paired or counted, and lengths are counted without them. See [`None` elements in a list](classification-logic.md#none-elements-in-a-list).
210211

211212
## See Also
212213

‎docs/docs/Guides/.nav.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ nav:
33
- Comparators/
44
- Evaluation/
55
- Use-Cases/
6+
- Document_Packet_Splitting.md
67
- Best-Practices/

‎docs/mkdocs.yml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ site_url: https://awslabs.github.io/stickler/
33
repo_url: https://github.com/awslabs/stickler
44
repo_name: awslabs/stickler
55

6+
# Use the same diagnostics in local serve/build and the PR checker.
7+
validation:
8+
nav:
9+
not_found: warn
10+
omitted_files: warn
11+
links:
12+
not_found: warn
13+
anchors: warn
14+
unrecognized_links: warn
15+
absolute_links: warn
16+
617
theme:
718
name: material
819
palette:
@@ -71,4 +82,4 @@ plugins:
7182
extra_javascript:
7283
# Workaround for site_url breaking mermaid rendering; see the following for more info:
7384
# https://github.com/squidfunk/mkdocs-material/issues/3742#issuecomment-1076068038
74-
- https://unpkg.com/mermaid@11/dist/mermaid.min.js
85+
- https://unpkg.com/mermaid@11/dist/mermaid.min.js

0 commit comments

Comments
 (0)