|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Python-Redlines is a Python wrapper around compiled C# binaries that generate `.docx` redline/tracked-changes documents by comparing two Word files. The Python layer handles platform detection, binary extraction, temp file management, and subprocess execution. |
| 8 | + |
| 9 | +Two comparison engines are available: |
| 10 | +- **XmlPowerToolsEngine** — wraps Open-XML-PowerTools WmlComparer (original engine) |
| 11 | +- **DocxodusEngine** — wraps Docxodus, a modernized .NET 8.0 fork with better move detection |
| 12 | + |
| 13 | +## Commands |
| 14 | + |
| 15 | +```bash |
| 16 | +# Run tests |
| 17 | +hatch run test |
| 18 | + |
| 19 | +# Run a single test |
| 20 | +hatch run test tests/test_openxml_differ.py::test_run_redlines_with_real_files |
| 21 | + |
| 22 | +# Run tests with coverage |
| 23 | +hatch run cov |
| 24 | + |
| 25 | +# Type checking |
| 26 | +hatch run types:check |
| 27 | + |
| 28 | +# Build C# binaries for all platforms (requires .NET 8.0 SDK) |
| 29 | +hatch run build |
| 30 | + |
| 31 | +# Build Python package (triggers C# build via custom hook) |
| 32 | +hatch build |
| 33 | + |
| 34 | +# Initialize Docxodus submodule (required before building) |
| 35 | +git submodule update --init --recursive |
| 36 | +``` |
| 37 | + |
| 38 | +## Architecture |
| 39 | + |
| 40 | +The system uses a two-layer wrapper pattern with a shared base class: |
| 41 | + |
| 42 | +1. **Python layer** (`src/python_redlines/engines.py`): |
| 43 | + - `BaseEngine` — shared logic for binary extraction, subprocess invocation, and temp file management |
| 44 | + - `XmlPowerToolsEngine(BaseEngine)` — sets constants for the Open-XML-PowerTools binary (`dist/`, `bin/`, `redlines`) |
| 45 | + - `DocxodusEngine(BaseEngine)` — sets constants for the Docxodus binary (`dist_docxodus/`, `bin_docxodus/`, `redline`) |
| 46 | + |
| 47 | + Both engines expose `run_redline(author_tag, original, modified, **kwargs)`. `DocxodusEngine` overrides `_build_command()` to translate kwargs (e.g. `detect_moves`, `detail_threshold`) into CLI flags for the Docxodus binary. `XmlPowerToolsEngine` uses the legacy 4-positional-arg format and ignores kwargs. |
| 48 | + |
| 49 | +2. **C# binaries**: |
| 50 | + - `csproj/Program.cs` — Open-XML-PowerTools CLI tool |
| 51 | + - `docxodus/tools/redline/Program.cs` — Docxodus CLI tool (git submodule) |
| 52 | + |
| 53 | +Pre-compiled binaries for 6 platform targets (linux/win/osx x x64/arm64) are stored as archives in `src/python_redlines/dist/` and `src/python_redlines/dist_docxodus/`, included in the wheel. The build script `build_differ.py` compiles both engines using `dotnet publish`. |
| 54 | + |
| 55 | +## Key Files |
| 56 | + |
| 57 | +- `src/python_redlines/engines.py` — BaseEngine, XmlPowerToolsEngine, and DocxodusEngine classes |
| 58 | +- `src/python_redlines/__init__.py` — Exports all engine classes |
| 59 | +- `src/python_redlines/__about__.py` — Single source of truth for package version |
| 60 | +- `csproj/Program.cs` — Open-XML-PowerTools C# comparison utility |
| 61 | +- `docxodus/` — Docxodus git submodule (tools/redline/ contains the CLI) |
| 62 | +- `build_differ.py` — Cross-platform C# build orchestration for both engines |
| 63 | +- `hatch_run_build_hook.py` — Hatch build hook that triggers C# compilation |
| 64 | +- `tests/fixtures/` — Test `.docx` files (original, modified, expected_redline) |
| 65 | + |
| 66 | +## Testing Notes |
| 67 | + |
| 68 | +Tests must be run from the project root (fixtures use relative paths like `tests/fixtures/original.docx`). The XmlPowerToolsEngine integration test validates that comparing the fixture documents produces exactly 9 revisions. Docxodus uses a different stdout format (`"revision(s) found"` vs `"Revisions found: 9"`). |
| 69 | + |
| 70 | +## Stdout Format Differences |
| 71 | + |
| 72 | +- **XmlPowerToolsEngine**: `"Revisions found: 9"` |
| 73 | +- **DocxodusEngine**: `"Redline complete: 9 revision(s) found"` |
0 commit comments