diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 92554e654712..d672539299db 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -20538,6 +20538,64 @@ in { }; }; + pyocr = buildPythonPackage rec { + name = "pyocr-${version}"; + version = "0.4.4"; + + # Don't fetch from PYPI because it doesn't contain tests. + src = pkgs.fetchFromGitHub { + owner = "jflesch"; + repo = "pyocr"; + rev = version; + sha256 = "09s7dxin8ams0f3xab60f45l3nn236a8win9yfyq9aqy9mm946ak"; + }; + + postPatch = '' + sed -i \ + -e 's,^\(TESSERACT_CMD *= *\).*,\1"${pkgs.tesseract}/bin/tesseract",' \ + -e 's,^\(CUNEIFORM_CMD *= *\).*,\1"${pkgs.cuneiform}/bin/cuneiform",' \ + -e '/^CUNIFORM_POSSIBLE_PATHS *= *\[/,/^\]$/ { + c CUNIFORM_POSSIBLE_PATHS = ["${pkgs.cuneiform}/share/cuneiform"] + }' src/pyocr/{tesseract,cuneiform}.py + + sed -i -r \ + -e 's,"libtesseract\.so\.3","${pkgs.tesseract}/lib/libtesseract.so",' \ + -e 's,^(TESSDATA_PREFIX *=).*,\1 "${pkgs.tesseract}/share/tessdata",' \ + src/pyocr/libtesseract/tesseract_raw.py + + # Disable specific tests that are probably failing because of this issue: + # https://github.com/jflesch/pyocr/issues/52 + for test in $disabledTests; do + file="''${test%%:*}" + fun="''${test#*:}" + echo "$fun = unittest.expectedFailure($fun)" >> "tests/tests_$file.py" + done + ''; + + disabledTests = [ + "cuneiform:TestTxt.test_basic" + "cuneiform:TestTxt.test_european" + "cuneiform:TestTxt.test_french" + "cuneiform:TestWordBox.test_basic" + "cuneiform:TestWordBox.test_european" + "cuneiform:TestWordBox.test_french" + "libtesseract:TestBasicDoc.test_basic" + "libtesseract:TestDigitLineBox.test_digits" + "libtesseract:TestLineBox.test_japanese" + "libtesseract:TestTxt.test_japanese" + "libtesseract:TestWordBox.test_japanese" + "tesseract:TestDigitLineBox.test_digits" + "tesseract:TestTxt.test_japanese" + ]; + + propagatedBuildInputs = [ self.pillow self.six ]; + + meta = { + homepage = "https://github.com/jflesch/pyocr"; + description = "A Python wrapper for Tesseract and Cuneiform"; + license = licenses.gpl3Plus; + }; + }; pyparsing = buildPythonPackage rec { name = "pyparsing-${version}";