git.iko.soy/typeable/nixpkgs
on master help sign in
pythonPackages.pyocr: 0.4.7 -> 0.5.3
commit5314a74ee6d8eefcd4f9a5cc6e676643baf36180 authorSymphorien Gibol <symphorien+git@xlumurb.eu> dateMon 10 Sep 2018, 17:27 (8 years ago) parentf403939
2 files changed+48−55
pkgs/development/python-modules/pyocr/default.nix+21−25 pkgs/development/python-modules/pyocr/paths.patch+27−30
pkgs/development/python-modules/pyocr/default.nix+21−25
@@ -1,47 +1,39 @@
1−{ lib, fetchFromGitHub, buildPythonPackage, pillow, six
2−, tesseract, cuneiform, isPy3k
1+{ lib, fetchFromGitLab, buildPythonPackage, pillow, six
2+, tesseract, cuneiform, isPy3k, substituteAll, pytest, tox
33}:
44
55buildPythonPackage rec {
66 pname = "pyocr";
7− version = "0.4.7";
7+ version = "0.5.3";
88 name = pname + "-" + version;
99 disabled = !isPy3k;
1010
1111 # Don't fetch from PYPI because it doesn't contain tests.
12− src = fetchFromGitHub {
13− owner = "jflesch";
12+ src = fetchFromGitLab {
13+ domain = "gitlab.gnome.org";
14+ group = "World";
15+ owner = "OpenPaperwork";
1416 repo = "pyocr";
1517 rev = version;
16− sha256 = "1iw73r8yrgjf8g00yzpz62ymqbf89cqhyhl9g430srmsrq7mn2yd";
18+ sha256 = "1nihf0qmbpg3yj3yp11jp6hp5z5dqf39nz6j9lqbvgi1nqbs7x15";
1719 };
1820
19− NIX_CUNEIFORM_CMD = "${cuneiform}/bin/cuneiform";
20− NIX_CUNEIFORM_DATA = "${cuneiform}/share/cuneiform";
21− NIX_LIBTESSERACT_PATH = "${tesseract}/lib/libtesseract.so";
22− NIX_TESSDATA_PREFIX = "${tesseract}/share/tessdata";
23− NIX_TESSERACT_CMD = "${tesseract}/bin/tesseract";
24−
25− patches = [ ./paths.patch ];
21+ patches = [ (substituteAll {
22+ src = ./paths.patch;
23+ inherit cuneiform tesseract;
24+ })
25+ ];
2626
2727 postPatch = ''
28− substituteInPlace src/pyocr/cuneiform.py \
29− --subst-var NIX_CUNEIFORM_CMD \
30− --subst-var NIX_CUNEIFORM_CMD
31−
32− substituteInPlace src/pyocr/tesseract.py \
33− --subst-var NIX_TESSERACT_CMD
34−
35− substituteInPlace src/pyocr/libtesseract/tesseract_raw.py \
36− --subst-var NIX_TESSDATA_PREFIX \
37− --subst-var NIX_LIBTESSERACT_PATH
28+ echo 'version = "${version}"' > src/pyocr/_version.py
3829
3930 # Disable specific tests that are probably failing because of this issue:
4031 # https://github.com/jflesch/pyocr/issues/52
4132 for test in $disabledTests; do
4233 file="''${test%%:*}"
4334 fun="''${test#*:}"
44− echo "$fun = unittest.skip($fun)" >> "tests/tests_$file.py"
35+ echo "import pytest" >> "tests/tests_$file.py"
36+ echo "$fun = pytest.mark.skip($fun)" >> "tests/tests_$file.py"
4537 done
4638 '';
4739
@@ -57,14 +49,18 @@ buildPythonPackage rec {
5749 "libtesseract:TestLineBox.test_japanese"
5850 "libtesseract:TestTxt.test_japanese"
5951 "libtesseract:TestWordBox.test_japanese"
52+ "libtesseract:TestTxt.test_multi"
53+ "tesseract:TestTxt.test_multi"
6054 "tesseract:TestDigitLineBox.test_digits"
6155 "tesseract:TestTxt.test_japanese"
6256 ];
6357
6458 propagatedBuildInputs = [ pillow six ];
59+ checkInputs = [ pytest tox ];
60+ checkPhase = "pytest";
6561
6662 meta = {
67− homepage = "https://github.com/jflesch/pyocr";
63+ inherit (src) homepage;
6864 description = "A Python wrapper for Tesseract and Cuneiform";
6965 license = lib.licenses.gpl3Plus;
7066 };
pkgs/development/python-modules/pyocr/paths.patch+27−30
@@ -1,28 +1,28 @@
1−diff --git a/src/pyocr/cuneiform.py b/src/pyocr/cuneiform.py
2−index a461d92..1f2b914 100644
3−--- a/src/pyocr/cuneiform.py
4−+++ b/src/pyocr/cuneiform.py
1+Index: current/src/pyocr/cuneiform.py
2+===================================================================
3+--- current.orig/src/pyocr/cuneiform.py
4++++ current/src/pyocr/cuneiform.py
55@@ -27,13 +27,9 @@ from . import error
66 from . import util
77
88
99-# CHANGE THIS IF CUNEIFORM IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
1010-CUNEIFORM_CMD = 'cuneiform'
11−+CUNEIFORM_CMD = '@NIX_CUNEIFORM_CMD@'
11++CUNEIFORM_CMD = '@cuneiform@/bin/cuneiform'
1212
1313-CUNEIFORM_DATA_POSSIBLE_PATHS = [
1414- "/usr/local/share/cuneiform",
1515- "/usr/share/cuneiform",
1616-]
17−+CUNEIFORM_DATA_POSSIBLE_PATHS = ['@NIX_CUNEIFORM_DATA@']
17++CUNEIFORM_DATA_POSSIBLE_PATHS = ['@cuneiform@/share/cuneiform']
1818
1919 LANGUAGES_LINE_PREFIX = "Supported languages: "
2020 LANGUAGES_SPLIT_RE = re.compile("[^a-z]")
21−diff --git a/src/pyocr/libtesseract/tesseract_raw.py b/src/pyocr/libtesseract/tesseract_raw.py
22−index b4e7bda..47505f7 100644
23−--- a/src/pyocr/libtesseract/tesseract_raw.py
24−+++ b/src/pyocr/libtesseract/tesseract_raw.py
25−@@ -1,55 +1,13 @@
21+Index: current/src/pyocr/libtesseract/tesseract_raw.py
22+===================================================================
23+--- current.orig/src/pyocr/libtesseract/tesseract_raw.py
24++++ current/src/pyocr/libtesseract/tesseract_raw.py
25+@@ -1,52 +1,13 @@
2626 import ctypes
2727 import logging
2828 import os
@@ -56,7 +56,13 @@ index b4e7bda..47505f7 100644
5656- # Jflesch> Don't they have the equivalent of LD_LIBRARY_PATH on
5757- # Windows ?
5858- "../vs2010/DLL_Release/libtesseract302.dll",
59+- # prefer the most recent first
60+- "libtesseract305.dll",
61+- "libtesseract304.dll",
62+- "libtesseract303.dll",
5963- "libtesseract302.dll",
64+- "libtesseract400.dll", # Tesseract 4 is still in alpha stage
65+- "libtesseract.dll",
6066- "C:\\Program Files (x86)\\Tesseract-OCR\\libtesseract-4.dll",
6167- "C:\\Program Files (x86)\\Tesseract-OCR\\libtesseract-3.dll",
6268- ]
@@ -66,27 +72,18 @@ index b4e7bda..47505f7 100644
6672- "libtesseract.so.3",
6773- ]
6874-
69−-
70−-g_libtesseract = None
71−-
72−-for libname in libnames:
73−- try:
74−- g_libtesseract = ctypes.cdll.LoadLibrary(libname)
75−- break
76−- except OSError:
77−- pass
78−+g_libtesseract = ctypes.cdll.LoadLibrary('@NIX_LIBTESSERACT_PATH@')
75++libnames = [ "@tesseract@/lib/libtesseract.so" ]
7976
77+ g_libtesseract = None
8078
81− class PageSegMode(object):
82−@@ -326,12 +284,11 @@ def init(lang=None):
79+@@ -346,12 +307,11 @@ def init(lang=None):
8380 try:
8481 if lang:
8582 lang = lang.encode("utf-8")
8683- prefix = None
8784- if TESSDATA_PREFIX:
8885- prefix = TESSDATA_PREFIX.encode("utf-8")
89−+ prefix = os.getenv('TESSDATA_PREFIX', '@NIX_TESSDATA_PREFIX@')
86++ prefix = os.getenv('TESSDATA_PREFIX', '@tesseract@/share/tessdata')
9087+ os.environ['TESSDATA_PREFIX'] = prefix
9188 g_libtesseract.TessBaseAPIInit3(
9289 ctypes.c_void_p(handle),
@@ -95,17 +92,17 @@ index b4e7bda..47505f7 100644
9592 ctypes.c_char_p(lang)
9693 )
9794 g_libtesseract.TessBaseAPISetVariable(
98−diff --git a/src/pyocr/tesseract.py b/src/pyocr/tesseract.py
99−index c935881..7139ffe 100755
100−--- a/src/pyocr/tesseract.py
101−+++ b/src/pyocr/tesseract.py
102−@@ -31,8 +31,7 @@ from .builders import DigitBuilder # backward compatibility
95+Index: current/src/pyocr/tesseract.py
96+===================================================================
97+--- current.orig/src/pyocr/tesseract.py
98++++ current/src/pyocr/tesseract.py
99+@@ -31,8 +31,7 @@ from .builders import DigitBuilder # ba
103100 from .error import TesseractError # backward compatibility
104101 from .util import digits_only
105102
106103-# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
107104-TESSERACT_CMD = 'tesseract.exe' if os.name == 'nt' else 'tesseract'
108−+TESSERACT_CMD = '@NIX_TESSERACT_CMD@'
105++TESSERACT_CMD = '@tesseract@/bin/tesseract'
109106
110107 TESSDATA_EXTENSION = ".traineddata"
111108