1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pythonOlder,
6
7 # build-system
8 flit-core,
9
10 # docs
11 sphinxHook,
12 sphinx-rtd-theme,
13 myst-parser,
14
15 # propagates
16 typing-extensions,
17
18 # optionals
19 cryptography,
20 pillow,
21
22 # tests
23 fpdf2,
24 pytestCheckHook,
25 pytest-timeout,
26}:
27
28buildPythonPackage rec {
29 pname = "pypdf";
30 version = "6.1.0";
31 pyproject = true;
32
33 disabled = pythonOlder "3.8";
34
35 src = fetchFromGitHub {
36 owner = "py-pdf";
37 repo = "pypdf";
38 tag = version;
39 # fetch sample files used in tests
40 fetchSubmodules = true;
41 hash = "sha256-qfLN6g2+3j35E4m9vGcWXL1BLiFdDZEFmxYgnknlW3M=";
42 };
43
44 outputs = [
45 "out"
46 "doc"
47 ];
48
49 postPatch = ''
50 substituteInPlace pyproject.toml \
51 --replace-fail "--disable-socket" ""
52 '';
53
54 build-system = [ flit-core ];
55
56 nativeBuildInputs = [
57 sphinxHook
58 sphinx-rtd-theme
59 myst-parser
60 ];
61
62 dependencies = lib.optionals (pythonOlder "3.11") [ typing-extensions ];
63
64 optional-dependencies = rec {
65 full = crypto ++ image;
66 crypto = [ cryptography ];
67 image = [ pillow ];
68 };
69
70 pythonImportsCheck = [ "pypdf" ];
71
72 nativeCheckInputs = [
73 (fpdf2.overridePythonAttrs { doCheck = false; }) # avoid reference loop
74 pytestCheckHook
75 pytest-timeout
76 ]
77 ++ optional-dependencies.full;
78
79 disabledTestMarks = [
80 # don't access the network
81 "enable_socket"
82 ];
83
84 meta = with lib; {
85 description = "Pure-python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files";
86 homepage = "https://github.com/py-pdf/pypdf";
87 changelog = "https://github.com/py-pdf/pypdf/blob/${src.tag}/CHANGELOG.md";
88 license = licenses.bsd3;
89 maintainers = with maintainers; [ javaes ];
90 };
91}