Add louis-py: Basic Python bindings for the translator (PyO3) - #12
Open
LeonarddeR wants to merge 20 commits into
Open
Add louis-py: Basic Python bindings for the translator (PyO3)#12LeonarddeR wants to merge 20 commits into
LeonarddeR wants to merge 20 commits into
Conversation
Reshapes the issue liblouis#1 spec against the current API: louis-py/louis_py naming, EmphasisSpan (not Typeform dict), TranslationOptions builder, pyo3 0.29, and the fact that TranslationResult fields beyond output are unpopulated today. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
9 TDD tasks. Toolchain verified end-to-end on ARM64 Windows (uv-managed aarch64 CPython 3.12 + maturin 1.14 + pyo3 0.29 cdylib imports). Bundled minimal mini.ctb table for hermetic tests. Confirmed louis::Translator is Send+Sync (no Mutex needed). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add LouisError/TableParseError/TranslationError via pyo3::create_exception! and a to_pyerr(py, louis::TranslationError) converter. TableParseError carries .errors via setattr on the exception instance, verified to persist through PyErr::value(py).
Adds the Translator pyclass (frozen) wrapping louis::Translator, with a constructor and translate() that release the GIL around the Rust call. Also removes the now-unneeded #[allow(dead_code)] on to_pyerr since to_pyerr_nogil (added here) exercises it, and adds a compile-time Send+Sync assertion for louis::Translator. Deviates from the plan's verbatim snippets: the installed pyo3 0.29.0 renamed Python::with_gil -> Python::attach and Python::allow_threads -> Python::detach (no deprecated aliases present); semantics are identical per pyo3's own docs, verified by reading marker.rs.
…only tablepath test on POSIX
NVDA moved to a 64-bit build in 2026.1, so the 32-bit Windows wheel is no longer needed. Removing the x86 matrix leg also eliminates the only CI target that couldn't be validated without a matching-arch interpreter. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…rtifacts Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Member
|
Hi @LeonarddeR thank you very much for this. I'm basically on vacation until August, so just a quick feedback: Generally looks excellent. I'm wondering though if this should not be a separate repository. That could under the liblouis organization and would be entirely yours. Then the function you added to More detailed review in August. |
Member
Author
|
@egli Thanks for your initial reply. |
Member
Author
|
@egli I created https://github.com/LeonarddeR/louis-py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
louis-py, a new Cargo workspace member exposing the translator to Python via PyO3. Closes #1.Translatorclass (GIL-releasedtranslate/translate_with_options),Direction,TranslationModeflags,TranslationResult/EmphasisSpan, and aLouisError/TableParseError/TranslationErrorexception hierarchy._louis_py.pyi) +py.typedmarker..github/workflows/python-wheels.yml: on PR, lints/tests withuv+ruff, builds wheels (5-platform matrix) + sdist as build artifacts — no publishing.CHANGELOG.mdentry underAdded.Test plan
cargo testlouis-pytest suite viauv run pytestpython-wheelsworkflow runs green on PROpen questions
louis_pyname for the python package or name it otherwise?