Skip to content

Commit

Permalink
Merge pull request #1348 from TikhonJelvis/pytesseract-executable-dep…
Browse files Browse the repository at this point in the history
…endency

Add dependency on native Tesseract OCR executable for pytesseract
  • Loading branch information
cpcloud authored Oct 21, 2023
2 parents 00f7a37 + 9ecb280 commit 67dade9
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
28 changes: 28 additions & 0 deletions overrides/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,34 @@ lib.composeManyExtensions [
buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.taglib ];
});

pytesseract =
let
pytesseract-cmd-patch = pkgs.writeText "pytesseract-cmd.patch" ''
--- a/pytesseract/pytesseract.py
+++ b/pytesseract/pytesseract.py
@@ -27,7 +27,7 @@
from PIL import Image
-tesseract_cmd = 'tesseract'
+tesseract_cmd = '${pkgs.tesseract4}/bin/tesseract'
numpy_installed = find_loader('numpy') is not None
if numpy_installed:
'';
in
super.pytesseract.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.tesseract4 ];
patches = (old.patches or [ ]) ++ lib.optionals (!(old.src.isWheel or false)) [ pytesseract-cmd-patch ];

# apply patch in postInstall if the source is a wheel
postInstall = lib.optionalString (old.src.isWheel or false) ''
pushd "$out/${self.python.sitePackages}"
patch -p1 < "${pytesseract-cmd-patch}"
popd
'';
});

pytezos = super.pytezos.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.libsodium ];
});
Expand Down
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ in
rpds-py-no-wheel = callTest ./rpds-py-no-wheel { };
contourpy-wheel = callTest ./contourpy-wheel { };
contourpy-no-wheel = callTest ./contourpy-no-wheel { };
pytesseract = callTest ./pytesseract { };
} // lib.optionalAttrs (!stdenv.isDarwin) {
# pyqt5 = (callTest ./pyqt5 { });

Expand Down
13 changes: 13 additions & 0 deletions tests/pytesseract/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ poetry2nix, runCommand, python3 }:
let
env = poetry2nix.mkPoetryEnv {
python = python3;
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
preferWheels = true;
};
py = env.python;
in
runCommand "pytesseract-test" { } ''
${env}/bin/python -c 'import pytesseract; print(pytesseract.get_tesseract_version())' > $out
''
99 changes: 99 additions & 0 deletions tests/pytesseract/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/pytesseract/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.poetry]
name = "pytesseract-test"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.10"
pytesseract = "*"

0 comments on commit 67dade9

Please sign in to comment.