about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorGuillaume Girol <symphorien@users.noreply.github.com>2024-02-16 21:52:57 +0100
committerGitHub <noreply@github.com>2024-02-16 21:52:57 +0100
commit6437f580bb5d034fea84e853878120fd9c324067 (patch)
treeeff9f16af8e3d7314e30175390c28baf2838553a /pkgs
parentaa05557fc288223b9d10f6f2aceb8d3be1fd0ff7 (diff)
parente8e0f9d2689a7047f1648744cf6e21c91065a9de (diff)
Merge pull request #288455 from tomodachi94/fix/cuneiform/darwin-support
python311Packages.pyocr: fix non-Linux builds
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/development/python-modules/pyocr/default.nix19
-rw-r--r--pkgs/development/python-modules/pyocr/paths-cuneiform.patch101
-rw-r--r--pkgs/development/python-modules/pyocr/paths-tesseract.patch (renamed from pkgs/development/python-modules/pyocr/paths.patch)100
3 files changed, 115 insertions, 105 deletions
diff --git a/pkgs/development/python-modules/pyocr/default.nix b/pkgs/development/python-modules/pyocr/default.nix
index 407166e98c901..0d87538a1ce4f 100644
--- a/pkgs/development/python-modules/pyocr/default.nix
+++ b/pkgs/development/python-modules/pyocr/default.nix
@@ -1,4 +1,5 @@
 { lib
+, stdenv
 , fetchFromGitLab
 , buildPythonPackage
 , pillow
@@ -9,6 +10,8 @@
 , pytestCheckHook
 , setuptools
 , setuptools-scm
+, withTesseractSupport ? true
+, withCuneiformSupport ? stdenv.hostPlatform.isLinux
 }:
 
 buildPythonPackage rec {
@@ -27,12 +30,14 @@ buildPythonPackage rec {
     hash = "sha256-gE0+qbHCwpDdxXFY+4rjVU2FbUSfSVrvrVMcWUk+9FU=";
   };
 
-  patches = [
-    (substituteAll {
-      src = ./paths.patch;
-      inherit cuneiform tesseract;
-    })
-  ];
+  patches = [] ++ (lib.optional withTesseractSupport (substituteAll {
+      src = ./paths-tesseract.patch;
+      inherit tesseract;
+      tesseractLibraryLocation = "${tesseract}/lib/libtesseract${stdenv.hostPlatform.extensions.sharedLibrary}";
+    })) ++ (lib.optional stdenv.hostPlatform.isLinux (substituteAll {
+      src = ./paths-cuneiform.patch;
+      inherit cuneiform;
+    }));
 
   propagatedBuildInputs = [ pillow ];
 
@@ -45,6 +50,6 @@ buildPythonPackage rec {
     changelog = "https://gitlab.gnome.org/World/OpenPaperwork/pyocr/-/blob/${version}/ChangeLog";
     description = "A Python wrapper for Tesseract and Cuneiform";
     license = licenses.gpl3Plus;
-    maintainers = with maintainers; [ symphorien ];
+    maintainers = with maintainers; [ symphorien tomodachi94 ];
   };
 }
diff --git a/pkgs/development/python-modules/pyocr/paths-cuneiform.patch b/pkgs/development/python-modules/pyocr/paths-cuneiform.patch
new file mode 100644
index 0000000000000..a25f08eddd06f
--- /dev/null
+++ b/pkgs/development/python-modules/pyocr/paths-cuneiform.patch
@@ -0,0 +1,101 @@
+commit cfc05af26b571e9ca09e9c709c0fb8934e9e46dd
+Author: Guillaume Girol <symphorien+git@xlumurb.eu>
+Date:   Sat Aug 20 17:48:01 2022 +0200
+
+    Fix finding cuneiform
+
+diff --git a/src/pyocr/cuneiform.py b/src/pyocr/cuneiform.py
+index 2e5b717..35647e2 100644
+--- a/src/pyocr/cuneiform.py
++++ b/src/pyocr/cuneiform.py
+@@ -25,13 +25,9 @@ from . import builders
+ from .error import CuneiformError
+ 
+ 
+-# CHANGE THIS IF CUNEIFORM IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
+-CUNEIFORM_CMD = 'cuneiform'
++CUNEIFORM_CMD = '@cuneiform@/bin/cuneiform'
+ 
+-CUNEIFORM_DATA_POSSIBLE_PATHS = [
+-    "/usr/local/share/cuneiform",
+-    "/usr/share/cuneiform",
+-]
++CUNEIFORM_DATA_POSSIBLE_PATHS = ['@cuneiform@/share/cuneiform']
+ 
+ LANGUAGES_LINE_PREFIX = "Supported languages: "
+ LANGUAGES_SPLIT_RE = re.compile("[^a-z]")
+diff --git a/tests/test_cuneiform.py b/tests/test_cuneiform.py
+index b76e93c..266f6b2 100644
+--- a/tests/test_cuneiform.py
++++ b/tests/test_cuneiform.py
+@@ -21,7 +21,7 @@ class TestCuneiform(BaseTest):
+         # XXX is it useful?
+         which.return_value = True
+         self.assertTrue(cuneiform.is_available())
+-        which.assert_called_once_with("cuneiform")
++        which.assert_called_once_with("@cuneiform@/bin/cuneiform")
+ 
+     @patch("subprocess.Popen")
+     def test_version(self, popen):
+@@ -54,7 +54,7 @@ class TestCuneiform(BaseTest):
+         self.assertIn("eng", langs)
+         self.assertIn("fra", langs)
+         popen.assert_called_once_with(
+-            ["cuneiform", "-l"],
++            ["@cuneiform@/bin/cuneiform", "-l"],
+             stdout=subprocess.PIPE, stderr=subprocess.STDOUT
+         )
+ 
+@@ -110,7 +110,7 @@ class TestCuneiformTxt(BaseTest):
+         output = cuneiform.image_to_string(self.image)
+         self.assertEqual(output, self._get_file_content("text").strip())
+         popen.assert_called_once_with(
+-            ["cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
++            ["@cuneiform@/bin/cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
+             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+             stderr=subprocess.STDOUT
+         )
+@@ -126,7 +126,7 @@ class TestCuneiformTxt(BaseTest):
+                                            builder=self.builder)
+         self.assertEqual(output, self._get_file_content("text").strip())
+         popen.assert_called_once_with(
+-            ["cuneiform", "-l", "fra", "-f", "text", "-o", self.tmp_filename,
++            ["@cuneiform@/bin/cuneiform", "-l", "fra", "-f", "text", "-o", self.tmp_filename,
+              "-"],
+             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+             stderr=subprocess.STDOUT
+@@ -143,7 +143,7 @@ class TestCuneiformTxt(BaseTest):
+                                            builder=self.builder)
+         self.assertEqual(output, self._get_file_content("text").strip())
+         popen.assert_called_once_with(
+-            ["cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
++            ["@cuneiform@/bin/cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
+             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+             stderr=subprocess.STDOUT
+         )
+@@ -174,7 +174,7 @@ class TestCuneiformTxt(BaseTest):
+         output = cuneiform.image_to_string(image, builder=self.builder)
+         self.assertEqual(output, self._get_file_content("text").strip())
+         popen.assert_called_once_with(
+-            ["cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
++            ["@cuneiform@/bin/cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
+             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+             stderr=subprocess.STDOUT
+         )
+@@ -230,7 +230,7 @@ class TestCuneiformWordBox(BaseTest):
+         output = cuneiform.image_to_string(self.image,
+                                            builder=self.builder)
+         popen.assert_called_once_with(
+-            ["cuneiform", "-f", "hocr", "-o", self.tmp_filename, "-"],
++            ["@cuneiform@/bin/cuneiform", "-f", "hocr", "-o", self.tmp_filename, "-"],
+             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+             stderr=subprocess.STDOUT
+         )
+@@ -284,7 +284,7 @@ class TestCuneiformLineBox(BaseTest):
+         output = cuneiform.image_to_string(self.image,
+                                            builder=self.builder)
+         popen.assert_called_once_with(
+-            ["cuneiform", "-f", "hocr", "-o", self.tmp_filename, "-"],
++            ["@cuneiform@/bin/cuneiform", "-f", "hocr", "-o", self.tmp_filename, "-"],
+             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+             stderr=subprocess.STDOUT
diff --git a/pkgs/development/python-modules/pyocr/paths.patch b/pkgs/development/python-modules/pyocr/paths-tesseract.patch
index c3c802c20649f..1a5aa8b367ebc 100644
--- a/pkgs/development/python-modules/pyocr/paths.patch
+++ b/pkgs/development/python-modules/pyocr/paths-tesseract.patch
@@ -2,28 +2,8 @@ commit cfc05af26b571e9ca09e9c709c0fb8934e9e46dd
 Author: Guillaume Girol <symphorien+git@xlumurb.eu>
 Date:   Sat Aug 20 17:48:01 2022 +0200
 
-    Fix finding tesseract and cuneiform
+    Fix finding tesseract
 
-diff --git a/src/pyocr/cuneiform.py b/src/pyocr/cuneiform.py
-index 2e5b717..35647e2 100644
---- a/src/pyocr/cuneiform.py
-+++ b/src/pyocr/cuneiform.py
-@@ -25,13 +25,9 @@ from . import builders
- from .error import CuneiformError
- 
- 
--# CHANGE THIS IF CUNEIFORM IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
--CUNEIFORM_CMD = 'cuneiform'
-+CUNEIFORM_CMD = '@cuneiform@/bin/cuneiform'
- 
--CUNEIFORM_DATA_POSSIBLE_PATHS = [
--    "/usr/local/share/cuneiform",
--    "/usr/share/cuneiform",
--]
-+CUNEIFORM_DATA_POSSIBLE_PATHS = ['@cuneiform@/share/cuneiform']
- 
- LANGUAGES_LINE_PREFIX = "Supported languages: "
- LANGUAGES_SPLIT_RE = re.compile("[^a-z]")
 diff --git a/src/pyocr/libtesseract/tesseract_raw.py b/src/pyocr/libtesseract/tesseract_raw.py
 index 1edec8c..434a336 100644
 --- a/src/pyocr/libtesseract/tesseract_raw.py
@@ -90,7 +70,7 @@ index 1edec8c..434a336 100644
 -        "libtesseract.4.dylib",
 -    ]
 -
-+libnames = [ "@tesseract@/lib/libtesseract.so" ]
++libnames = [ "@tesseractLibraryLocation@" ]
  
  g_libtesseract = None
  
@@ -125,82 +105,6 @@ index 0fe0d20..c1fdd27 100644
  
  TESSDATA_EXTENSION = ".traineddata"
  
-diff --git a/tests/test_cuneiform.py b/tests/test_cuneiform.py
-index b76e93c..266f6b2 100644
---- a/tests/test_cuneiform.py
-+++ b/tests/test_cuneiform.py
-@@ -21,7 +21,7 @@ class TestCuneiform(BaseTest):
-         # XXX is it useful?
-         which.return_value = True
-         self.assertTrue(cuneiform.is_available())
--        which.assert_called_once_with("cuneiform")
-+        which.assert_called_once_with("@cuneiform@/bin/cuneiform")
- 
-     @patch("subprocess.Popen")
-     def test_version(self, popen):
-@@ -54,7 +54,7 @@ class TestCuneiform(BaseTest):
-         self.assertIn("eng", langs)
-         self.assertIn("fra", langs)
-         popen.assert_called_once_with(
--            ["cuneiform", "-l"],
-+            ["@cuneiform@/bin/cuneiform", "-l"],
-             stdout=subprocess.PIPE, stderr=subprocess.STDOUT
-         )
- 
-@@ -110,7 +110,7 @@ class TestCuneiformTxt(BaseTest):
-         output = cuneiform.image_to_string(self.image)
-         self.assertEqual(output, self._get_file_content("text").strip())
-         popen.assert_called_once_with(
--            ["cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
-+            ["@cuneiform@/bin/cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
-             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-             stderr=subprocess.STDOUT
-         )
-@@ -126,7 +126,7 @@ class TestCuneiformTxt(BaseTest):
-                                            builder=self.builder)
-         self.assertEqual(output, self._get_file_content("text").strip())
-         popen.assert_called_once_with(
--            ["cuneiform", "-l", "fra", "-f", "text", "-o", self.tmp_filename,
-+            ["@cuneiform@/bin/cuneiform", "-l", "fra", "-f", "text", "-o", self.tmp_filename,
-              "-"],
-             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-             stderr=subprocess.STDOUT
-@@ -143,7 +143,7 @@ class TestCuneiformTxt(BaseTest):
-                                            builder=self.builder)
-         self.assertEqual(output, self._get_file_content("text").strip())
-         popen.assert_called_once_with(
--            ["cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
-+            ["@cuneiform@/bin/cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
-             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-             stderr=subprocess.STDOUT
-         )
-@@ -174,7 +174,7 @@ class TestCuneiformTxt(BaseTest):
-         output = cuneiform.image_to_string(image, builder=self.builder)
-         self.assertEqual(output, self._get_file_content("text").strip())
-         popen.assert_called_once_with(
--            ["cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
-+            ["@cuneiform@/bin/cuneiform", "-f", "text", "-o", self.tmp_filename, "-"],
-             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-             stderr=subprocess.STDOUT
-         )
-@@ -230,7 +230,7 @@ class TestCuneiformWordBox(BaseTest):
-         output = cuneiform.image_to_string(self.image,
-                                            builder=self.builder)
-         popen.assert_called_once_with(
--            ["cuneiform", "-f", "hocr", "-o", self.tmp_filename, "-"],
-+            ["@cuneiform@/bin/cuneiform", "-f", "hocr", "-o", self.tmp_filename, "-"],
-             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-             stderr=subprocess.STDOUT
-         )
-@@ -284,7 +284,7 @@ class TestCuneiformLineBox(BaseTest):
-         output = cuneiform.image_to_string(self.image,
-                                            builder=self.builder)
-         popen.assert_called_once_with(
--            ["cuneiform", "-f", "hocr", "-o", self.tmp_filename, "-"],
-+            ["@cuneiform@/bin/cuneiform", "-f", "hocr", "-o", self.tmp_filename, "-"],
-             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-             stderr=subprocess.STDOUT
-         )
 diff --git a/tests/test_libtesseract.py b/tests/test_libtesseract.py
 index cc31a50..890c02c 100644
 --- a/tests/test_libtesseract.py