1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 fetchpatch2,
6 pythonOlder,
7
8 # build-system
9 flit-core,
10
11 # docs
12 sphinxHook,
13 sphinx-rtd-theme,
14 myst-parser,
15
16 # propagates
17 typing-extensions,
18
19 # optionals
20 cryptography,
21 pillow,
22
23 # tests
24 fpdf2,
25 pytestCheckHook,
26 pytest-timeout,
27}:
28
29buildPythonPackage rec {
30 pname = "pypdf";
31 version = "4.1.0";
32 format = "pyproject";
33
34 src = fetchFromGitHub {
35 owner = "py-pdf";
36 repo = "pypdf";
37 rev = "refs/tags/${version}";
38 # fetch sample files used in tests
39 fetchSubmodules = true;
40 hash = "sha256-Z3flDC102FwEaNtef0YAfmAFSxpimQNyxt9tRfpKueg=";
41 };
42
43 patches = [
44 (fetchpatch2 {
45 # add missing test marker on networked test
46 url = "https://github.com/py-pdf/pypdf/commit/f43268734a529d4098e6258bf346148fd24c54f0.patch";
47 includes = [ "tests/test_generic.py" ];
48 hash = "sha256-Ow32UB4crs3OgT+AmA9TNmcO5Y9SoSahybzD3AmWmVk=";
49 })
50 ];
51
52 outputs = [
53 "out"
54 "doc"
55 ];
56
57 nativeBuildInputs = [
58 flit-core
59
60 # docs
61 sphinxHook
62 sphinx-rtd-theme
63 myst-parser
64 ];
65
66 postPatch = ''
67 substituteInPlace pyproject.toml \
68 --replace "--disable-socket" ""
69 '';
70
71 propagatedBuildInputs = lib.optionals (pythonOlder "3.10") [ typing-extensions ];
72
73 passthru.optional-dependencies = rec {
74 full = crypto ++ image;
75 crypto = [ cryptography ];
76 image = [ pillow ];
77 };
78
79 pythonImportsCheck = [ "pypdf" ];
80
81 nativeCheckInputs = [
82 (fpdf2.overridePythonAttrs { doCheck = false; }) # avoid reference loop
83 pytestCheckHook
84 pytest-timeout
85 ] ++ passthru.optional-dependencies.full;
86
87 pytestFlagsArray = [
88 # don't access the network
89 "-m"
90 "'not enable_socket'"
91 ];
92
93 disabledTests = [
94 # requires fpdf2 which we don't package yet
95 "test_compression"
96 # infinite recursion when including fpdf2
97 "test_merging_many_temporary_files"
98 ];
99
100 meta = with lib; {
101 description = "A pure-python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files";
102 homepage = "https://github.com/py-pdf/pypdf";
103 changelog = "https://github.com/py-pdf/pypdf/blob/${src.rev}/CHANGELOG.md";
104 license = licenses.bsd3;
105 maintainers = with maintainers; [ ];
106 };
107}