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 = "4.3.1";
31 pyproject = true;
32
33 src = fetchFromGitHub {
34 owner = "py-pdf";
35 repo = "pypdf";
36 rev = "refs/tags/${version}";
37 # fetch sample files used in tests
38 fetchSubmodules = true;
39 hash = "sha256-wSF20I5WaxRoN0n0jxB5O3mAAIOxP/TclYBTRAUwYHo=";
40 };
41
42 outputs = [
43 "out"
44 "doc"
45 ];
46
47 nativeBuildInputs = [
48 flit-core
49
50 # docs
51 sphinxHook
52 sphinx-rtd-theme
53 myst-parser
54 ];
55
56 postPatch = ''
57 substituteInPlace pyproject.toml \
58 --replace-fail "--disable-socket" ""
59 '';
60
61 propagatedBuildInputs = lib.optionals (pythonOlder "3.11") [ typing-extensions ];
62
63 optional-dependencies = rec {
64 full = crypto ++ image;
65 crypto = [ cryptography ];
66 image = [ pillow ];
67 };
68
69 pythonImportsCheck = [ "pypdf" ];
70
71 nativeCheckInputs = [
72 (fpdf2.overridePythonAttrs { doCheck = false; }) # avoid reference loop
73 pytestCheckHook
74 pytest-timeout
75 ] ++ optional-dependencies.full;
76
77 pytestFlagsArray = [
78 # don't access the network
79 "-m"
80 "'not enable_socket'"
81 ];
82
83 meta = with lib; {
84 description = "Pure-python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files";
85 homepage = "https://github.com/py-pdf/pypdf";
86 changelog = "https://github.com/py-pdf/pypdf/blob/${src.rev}/CHANGELOG.md";
87 license = licenses.bsd3;
88 maintainers = with maintainers; [ javaes ];
89 };
90}