build: bundle the OCR binary into macOS wheels#10
Merged
Conversation
Add a hatch build hook that compiles a universal (arm64 + x86_64) lcr-ocr, bundles it under the package, and tags the wheel macosx_11_0_universal2. The hook skips when Swift is unavailable (e.g. the sdist), and the built binary is git-ignored since it is produced at build time.
Resolve the binary as LCR_OCR_BIN, then the copy bundled in the wheel, then PATH, then the in-repo dev build, restoring the executable bit if installation dropped it.
Assert the bundled copy is used when no override is set.
Move the release build to macOS so the Swift hook runs, and assert the wheel is universal2 and contains the OCR binary.
The macOS wheel ships the OCR binary, so OCR works without building it or setting LCR_OCR_BIN.
Editable installs invoke the build hook with version 'editable'; some hosts (e.g. CI without Xcode) have a non-functional swift shim that the which-guard does not catch. Editable installs never need the bundled binary, so return early for them.
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.
Makes
pip install localcontextroutership working OCR — no manual Swift build, noLCR_OCR_BIN.What
hatch_build.py): compiles a universal (arm64+x86_64)lcr-ocr, bundles it under the package, and tags the wheelpy3-none-macosx_11_0_universal2. Skips cleanly when Swift is unavailable (so the sdist still builds), producing a pure wheel in that case.ocr.py):LCR_OCR_BIN→ bundled copy →PATH→ in-repo dev build, restoring the executable bit if installation dropped it.universal2and containslocalcontextrouter/_bin/lcr-ocr.Verified locally
python -m build→localcontextrouter-0.1.0-py3-none-macosx_11_0_universal2.whlcontaining the binary;twine checkpasses.LCR_OCR_BINandlcr-ocrnot on PATH, OCRs an image successfully — zero-setup OCR.lipoconfirms the bundled binary is a fatx86_64 arm64build.Tests
ruff, ruff format, mypy (strict), pytest (56), including a bundled-binary resolution test.
Notes