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