1{
2 lib,
3 buildPythonPackage,
4 deprecation,
5 fetchFromGitHub,
6 ghostscript,
7 hatch-vcs,
8 hatchling,
9 hypothesis,
10 img2pdf,
11 jbig2enc,
12 packaging,
13 pdfminer-six,
14 pillow-heif,
15 pikepdf,
16 pillow,
17 pluggy,
18 pngquant,
19 pytest-xdist,
20 pytestCheckHook,
21 pythonOlder,
22 rich,
23 reportlab,
24 substituteAll,
25 tesseract,
26 unpaper,
27 installShellFiles,
28}:
29
30buildPythonPackage rec {
31 pname = "ocrmypdf";
32 version = "16.7.0";
33
34 disabled = pythonOlder "3.10";
35
36 pyproject = true;
37
38 src = fetchFromGitHub {
39 owner = "ocrmypdf";
40 repo = "OCRmyPDF";
41 rev = "v${version}";
42 # The content of .git_archival.txt is substituted upon tarball creation,
43 # which creates indeterminism if master no longer points to the tag.
44 # See https://github.com/ocrmypdf/OCRmyPDF/issues/841
45 postFetch = ''
46 rm "$out/.git_archival.txt"
47 '';
48 hash = "sha256-81maXJjdGlzWy3TaQ8cabjJl6ZE5tbfc8m/+Px7ONhs=";
49 };
50
51 patches = [
52 ./use-pillow-heif.patch
53 (substituteAll {
54 src = ./paths.patch;
55 gs = lib.getExe ghostscript;
56 jbig2 = lib.getExe jbig2enc;
57 pngquant = lib.getExe pngquant;
58 tesseract = lib.getExe tesseract;
59 unpaper = lib.getExe unpaper;
60 })
61 ];
62
63 build-system = [
64 hatch-vcs
65 hatchling
66 ];
67
68 nativeBuildInputs = [ installShellFiles ];
69
70 dependencies = [
71 deprecation
72 img2pdf
73 packaging
74 pdfminer-six
75 pillow-heif
76 pikepdf
77 pillow
78 pluggy
79 rich
80 ];
81
82 nativeCheckInputs = [
83 hypothesis
84 pytest-xdist
85 pytestCheckHook
86 reportlab
87 ];
88
89 pythonImportsCheck = [ "ocrmypdf" ];
90
91 postInstall = ''
92 installShellCompletion --cmd ocrmypdf \
93 --bash misc/completion/ocrmypdf.bash \
94 --fish misc/completion/ocrmypdf.fish
95 '';
96
97 meta = with lib; {
98 homepage = "https://github.com/ocrmypdf/OCRmyPDF";
99 description = "Adds an OCR text layer to scanned PDF files, allowing them to be searched";
100 license = with licenses; [
101 mpl20
102 mit
103 ];
104 maintainers = with maintainers; [
105 dotlambda
106 ];
107 changelog = "https://github.com/ocrmypdf/OCRmyPDF/blob/${src.rev}/docs/release_notes.rst";
108 mainProgram = "ocrmypdf";
109 };
110}