Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
windows:
name: Windows / Python ${{ matrix.python }}
runs-on: windows-2025
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
python: ["3.11", "3.12", "3.13", "3.14"]
defaults:
run:
shell: pwsh
env:
PYTHONUTF8: "1"
# Typer otherwise forces ANSI styling when GITHUB_ACTIONS is set.
_TYPER_FORCE_DISABLE_TERMINAL: "1"
NO_COLOR: "1"
steps:
- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.12.19"
python-version: ${{ matrix.python }}
enable-cache: true
cache-dependency-glob: uv.lock

- name: Install Python
run: uv python install "${{ matrix.python }}"

- name: Install locked dependencies
run: uv sync --locked --group dev

- name: Isolate MatnOCR settings
run: |
$configHome = Join-Path $env:RUNNER_TEMP 'matnocr-config'
Add-Content -LiteralPath $env:GITHUB_ENV -Value "MATNOCR_CONFIG_HOME=$configHome" -Encoding utf8

- name: Record runtime and OCR languages
run: uv run --no-sync python tools/ci_smoke.py --diagnostics-only

- name: Ruff check
run: uv run --no-sync ruff check .

- name: Ruff format
run: uv run --no-sync ruff format --check .

- name: Type check
run: uv run --no-sync ty check

- name: Unit and integration tests
run: uv run --no-sync pytest --cov=matnocr

- name: Build wheel and source distribution
run: uv build --out-dir "${{ runner.temp }}/matnocr-dist"

- name: Export locked runtime dependencies
run: uv export --locked --no-dev --no-emit-project --format requirements-txt --output-file "${{ runner.temp }}/matnocr-runtime.txt"

- name: Create fresh wheel environment
run: uv venv --python "${{ matrix.python }}" "${{ runner.temp }}/matnocr-wheel-env"

- name: Install locked runtime dependencies into wheel environment
run: uv pip sync --python "${{ runner.temp }}/matnocr-wheel-env/Scripts/python.exe" "${{ runner.temp }}/matnocr-runtime.txt"

- name: Install built wheel
run: |
$wheels = @(Get-ChildItem -LiteralPath '${{ runner.temp }}/matnocr-dist' -Filter '*.whl')
if ($wheels.Count -ne 1) { throw 'Expected exactly one built wheel.' }
uv pip install --no-deps --python '${{ runner.temp }}/matnocr-wheel-env/Scripts/python.exe' $wheels[0].FullName

- name: Smoke-test installed wheel and console command
run: |
& '${{ runner.temp }}/matnocr-wheel-env/Scripts/python.exe' -I tools/ci_smoke.py

ci:
name: CI
if: always()
needs: [windows]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Require all Windows jobs to succeed
env:
WINDOWS_RESULT: ${{ needs.windows.result }}
run: test "$WINDOWS_RESULT" = success
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ coverage.py
Ruff, ty, pytest und pytest-cov sind bereits als Dev Dependencies eingetragen.
Die Konfiguration steht in `pyproject.toml`: Ruff prüft aktiven Code und Tests
(ohne die historischen Experimente `prototype.py` und `add_new_white_page.py`),
ty prüft `src/` und `tests/` für Python 3.11 unter Windows. Unit- und mit
ty prüft `src/`, `tests/` und `tools/` für Python 3.11 unter Windows. Unit- und mit
`integration` markierte Integrationstests sind getrennt. Aktuellen Status und
weitere Aufgaben in `TODO.md` beachten.

Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ development work, not a claim that a public release has been published.
staged writes that preserve existing exports if replacement fails.
- Unit tests, synthetic English/German/Arabic integration documents, and local
Ruff, ty, pytest, and coverage configuration.
- GitHub Actions CI for Python 3.11–3.14 on Windows Server 2025, including
locked dependencies, code checks, capability-aware integration tests, package
builds, and CLI smoke tests in a fresh wheel environment. A combined `CI`
check reports the overall matrix result for branch protection.
- Usage and development documentation, screenshots, contributor guidance,
security and conduct policies, and GitHub issue and pull request templates.

Expand All @@ -30,4 +34,4 @@ development work, not a claim that a public release has been published.
- Suppressed the PDFium foreign-bitmap close warning in the scan fast path
after verifying that OCR uses an independent pixel copy.

Public PyPI releases, GitHub CI, and packaged Windows releases are still planned.
Public PyPI releases and packaged Windows releases are still planned.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ features or changes to the renderer, OCR engine, dependencies, or packaging,
open a feature request before implementation so the scope can be discussed.

MatnOCR is in development. The package version is not evidence of a published
release; see [CHANGELOG.md](CHANGELOG.md). CI and publishing remain planned work.
release; see [CHANGELOG.md](CHANGELOG.md). The CI workflow is configured in
`.github/workflows/ci.yml`; publishing remains planned work.

## Report an Issue

Expand Down
29 changes: 19 additions & 10 deletions PROJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ Ruff, ty, pytest, and pytest-cov (coverage.py) are already included in the
`pyproject.toml` development dependency group and recorded in `uv.lock`.
Ruff, ty, pytest, and branch coverage are configured in `pyproject.toml`.
Ruff checks active code and tests; the historical experiments `prototype.py`
and `add_new_white_page.py` are excluded. ty checks `src/` and `tests/` for
Python 3.11 on Windows. The installed PyWinRT types require no global rule
and `add_new_white_page.py` are excluded. ty checks `src/`, `tests/`, and
`tools/` for Python 3.11 on Windows. The installed PyWinRT types require no global rule
suppression; existing `Any` boundaries for native objects are explained in
`README.md`. Local commands are documented there as well.

Expand Down Expand Up @@ -717,8 +717,8 @@ project/

The package lives under `src/matnocr/`; unit tests are in `tests/unit/`, and
integration tests are in `tests/integration/`. The tree also shows planned
files: GitHub workflows are still pending. Community documents, issue forms,
and the pull request template are present. `TODO.md` describes the authoritative
files: the CI workflow is present; release and CodeQL workflows are still
pending. Community documents, issue forms, and the pull request template are present. `TODO.md` describes the authoritative
implementation status.

## 15. Packaging and Installation
Expand All @@ -733,8 +733,9 @@ matnocr = "matnocr.cli:app"
```

The console entry point launches `matnocr`; `python -m matnocr` is also
available. Full build and wheel verification remains part of the packaging
roadmap.
available. Local wheel/sdist builds, archive checks, fresh wheel installation,
and CLI smoke checks have passed on Python 3.13. Validation on the GitHub runner
and across the full Python matrix remains part of the CI and packaging roadmap.

## 16. Installation for Users

Expand Down Expand Up @@ -826,11 +827,19 @@ with:

## 19. CI – Continuous Integration

CI should run through GitHub Actions.
GitHub Actions CI is configured in `.github/workflows/ci.yml`. It runs on
pushes to `main`, pull requests targeting `main`, and manual dispatch. The
application jobs use `windows-2025` with Python 3.11, 3.12, 3.13, and 3.14.
The first hosted run must still confirm compatibility and actual OCR capability
availability; Windows Server language packs must not be assumed to match a
Windows desktop.

Because OCR is Windows-specific, at least one Windows runner is required.
The workflow pins uv 0.12.19 and action commit SHAs, uses read-only repository
permissions, and does not publish packages. A final `CI` job combines the Windows
matrix results and can become the required branch-protection check after the
first successful hosted run. This gate uses Ubuntu only to combine results.

Planned workflow for pull requests and pushes:
Configured workflow:

```text
Checkout
Expand All @@ -848,7 +857,7 @@ Checkout

### Python Matrix

Versions planned for evaluation:
Configured CI versions, pending their first successful hosted evaluation:

```text
3.11
Expand Down
63 changes: 36 additions & 27 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ offline-ocr

### 27. Branch Protection später aktivieren

- [ ] Pull Requests vor Merge
- [ ] CI muss erfolgreich sein
- [ ] versehentliches Force Push verhindern
- [x] Pull Requests vor Merge
- [ ] CI muss erfolgreich sein (Check `CI` nach erstem erfolgreichen GitHub-Lauf verpflichtend machen)
- [x] versehentliches Force Push verhindern
- [ ] Tags / Releases schützen

## Phase 6 – GitHub CI
Expand All @@ -439,29 +439,38 @@ pull_request

Schritte:

- [ ] Checkout
- [ ] uv installieren
- [ ] Python installieren
- [ ] `uv sync --locked`
- [ ] `ruff check`
- [ ] `ruff format --check`
- [ ] `ty check`
- [ ] `pytest`
- [ ] Package bauen
- [ ] gebauten Wheel installieren
- [ ] CLI Smoke Test
- [x] Checkout
- [x] uv installieren
- [x] Python installieren
- [x] `uv sync --locked`
- [x] `ruff check`
- [x] `ruff format --check`
- [x] `ty check`
- [x] `pytest`
- [x] Package bauen
- [x] gebauten Wheel installieren
- [x] CLI Smoke Test

Der Workflow ist implementiert und lokal unter Python 3.13 geprüft.
Der erste ausgeführte Hosted-Testlauf zeigte CLI-Tests mit einer Abhängigkeit
von der nicht versionierten `prototype.py` sowie von Typer erzwungene ANSI-Codes.
Die Tests erzeugen nun eigene Eingabepfade; der Workflow deaktiviert erzwungene
Terminalformatierung. Lokal bestehen damit alle 144 Tests auch mit den
CI-Umgebungsvariablen. Der erfolgreiche Hosted-Wiederholungslauf steht noch aus.

- [ ] ersten GitHub-Lauf auf dem PR prüfen (Matrix und echte Runner-Capabilities)

### 29. Windows Runner

- [ ] Windows GitHub Runner verwenden
- [ ] genaue Runner-Version festlegen
- [ ] verfügbare Windows-OCR-Sprachen untersuchen
- [ ] falls sinnvoll kleine Integrationstests aktivieren
- [ ] OCR-Sprachabhängige Tests sauber skippen
- [x] Windows GitHub Runner konfigurieren (`windows-2025`; erster Hosted-Lauf noch offen)
- [x] Runner-Image-Familie festlegen (`windows-2025`; konkrete Image-Version im Actions-Log)
- [ ] verfügbare Windows-OCR-Sprachen im ersten GitHub-Lauf untersuchen (Diagnose-Schritt konfiguriert)
- [x] kleine Integrationstests im Workflow aktivieren
- [x] OCR-Sprachabhängige Tests bei fehlender Runtime oder Sprache sauber skippen

### 30. Python CI Matrix

Prüfen:
Matrix 3.11–3.14 ist konfiguriert; erfolgreiche Hosted-Läufe noch prüfen:

- [ ] Python 3.11
- [ ] Python 3.12
Expand All @@ -474,8 +483,8 @@ Nur nach erfolgreichem Test offiziell unterstützen.

- [ ] Dependabot
- [ ] CodeQL
- [ ] minimale GitHub-Action-Berechtigungen
- [ ] Actions möglichst auf stabile Versionen / SHAs pinnen
- [x] minimale GitHub-Action-Berechtigungen (`contents: read` im CI-Workflow)
- [x] CI-Actions auf geprüfte Commit-SHAs und uv auf Version pinnen

## Phase 7 – Python Packaging / PyPI

Expand All @@ -497,11 +506,11 @@ Nur nach erfolgreichem Test offiziell unterstützen.

### 33. Build lokal testen

- [ ] `uv build`
- [ ] sdist prüfen
- [ ] wheel prüfen
- [ ] frische virtuelle Umgebung erstellen
- [ ] wheel dort installieren
- [x] `uv build`
- [x] sdist prüfen
- [x] wheel prüfen
- [x] frische virtuelle Umgebung erstellen
- [x] wheel dort installieren
- [ ] CLI vollständig testen

### 34. TestPyPI
Expand Down
40 changes: 36 additions & 4 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Ruff, ty, pytest, and branch coverage are configured in `pyproject.toml`.
Ruff targets Python 3.11 and checks common syntax errors, undefined names,
imports, modernization, and common bug patterns. Its formatter uses 88 columns
and double quotes. The historical `prototype.py` and `add_new_white_page.py`
experiments are excluded from Ruff; ty checks `src/` and `tests/`, targeting
experiments are excluded from Ruff; ty checks `src/`, `tests/`, and `tools/`, targeting
Python 3.11 on Windows. These scripts are not distributed application code.

The installed PyWinRT typing works with ty without global rule suppression or
Expand All @@ -69,7 +69,39 @@ and the locally installed Arial font; affected tests skip if these capabilities
are unavailable. No new package dependencies or bundled font files are needed.
No language packs are installed by tests, and no private book pages are used.
See [the integration test notes](../tests/integration/README.md) for details.
The full suite currently requires Windows
because application modules imported by unit tests use WinRT. GitHub CI remains
a later roadmap task.
The full suite currently requires Windows because application modules imported
by unit tests use WinRT.

## GitHub Actions CI

The workflow in [ci.yml](../.github/workflows/ci.yml) runs on pushes to `main`,
pull requests targeting `main`, and manual dispatch. Each matrix job uses
`windows-2025` with Python 3.11, 3.12, 3.13, or 3.14. setup-uv selects the matrix
interpreter independently of the local `.python-version` file. uv is pinned to
0.12.19, and third-party actions are pinned to commit SHAs. The workflow has
read-only repository permissions and does not publish artifacts or use deployment
secrets.

Every Windows job synchronizes `uv.lock`, logs the runtime and available OCR
languages, runs Ruff, formatting, ty, and all tests with coverage, and builds a
wheel and source distribution. It then creates a separate environment, installs
the locked runtime dependencies and built wheel, and runs `tools/ci_smoke.py`
with isolated Python imports. The smoke test verifies that the imported package
lives in that environment, checks CLI help/version output, and invokes the
installed `matnocr.exe` console entry point. It deliberately uses OCR-command
help rather than requiring an OCR engine for help on a server runner.

OCR capabilities on Windows Server runners may differ from a desktop Windows
installation. Integration tests skip an unavailable OCR runtime or missing
language pack and report the reasons. The diagnostics step records the actual
languages without installing system capabilities or opening an administrative
PowerShell. CLI unit tests use synthetic language discovery.

The final `CI` job runs even if a matrix job fails or is skipped, and succeeds
only when the Windows matrix succeeds. After the first successful GitHub run,
require this check in the `main` ruleset. Do not require all possible OCR
languages or assume that a configured Python matrix is already validated:
inspect the first run and its skipped tests before marking compatibility tasks
complete. The final gate uses Ubuntu only to combine results; all application
checks run on Windows.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ indent-style = "space"
line-ending = "auto"

[tool.ty.src]
include = ["src", "tests"]
include = ["src", "tests", "tools"]

[tool.ty.environment]
python-version = "3.11"
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ def pdfium() -> Any:
def windows_ocr() -> Any:
if sys.platform != "win32":
pytest.skip("Windows OCR requires Windows")
return pytest.importorskip("winrt.windows.media.ocr")
module = pytest.importorskip("winrt.windows.media.ocr")
try:
tuple(module.OcrEngine.available_recognizer_languages)
except (OSError, RuntimeError) as error:
pytest.skip(f"Windows OCR runtime is unavailable: {error}")
return module


@pytest.fixture
Expand Down
Loading