nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 pkgsCross,
5 buildPythonPackage,
6 fetchFromGitHub,
7 gitUpdater,
8 setuptools-scm,
9 pdfium-binaries,
10 numpy,
11 pillow,
12 pytestCheckHook,
13 removeReferencesTo,
14 python,
15}:
16
17let
18 # They demand their own fork of ctypesgen
19 ctypesgen = buildPythonPackage rec {
20 pname = "ctypesgen";
21 version = "1.1.1+g${src.rev}"; # the most recent tag + git version
22 pyproject = true;
23
24 src = fetchFromGitHub {
25 owner = "pypdfium2-team";
26 repo = "ctypesgen";
27 rev = "3961621c3e057015362db82471e07f3a57822b15";
28 hash = "sha256-0OBY7/Zn12rG20jNYG65lANTRVRIFvE0SgUdYGFpRtU=";
29 };
30
31 build-system = [
32 setuptools-scm
33 ];
34 };
35
36in
37buildPythonPackage rec {
38 pname = "pypdfium2";
39 version = "5.3.0";
40 pyproject = true;
41
42 src = fetchFromGitHub {
43 owner = "pypdfium2-team";
44 repo = "pypdfium2";
45 tag = version;
46 hash = "sha256-HXJv7GCb+r1rE9Jh0wHm/LCfr8eHJA7qtCk0YhbE+24=";
47 };
48
49 build-system = [
50 ctypesgen
51 setuptools-scm
52 ];
53
54 nativeBuildInputs = [
55 removeReferencesTo
56 ];
57
58 propagatedBuildInputs = [
59 pdfium-binaries
60 ];
61
62 preBuild = ''
63 getVersion() {
64 cat ${pdfium-binaries}/VERSION | grep $1 | sed 's/.*=//'
65 }
66 export GIVEN_FULLVER="$(getVersion MAJOR).$(getVersion MINOR).$(getVersion BUILD).$(getVersion PATCH)"
67 '';
68
69 env = {
70 PDFIUM_PLATFORM = "system-search:${pdfium-binaries.version}";
71 PDFIUM_HEADERS = "${pdfium-binaries}/include";
72 PDFIUM_BINARY = "${pdfium-binaries}/lib/libpdfium${stdenv.targetPlatform.extensions.sharedLibrary}";
73 CPP = "${stdenv.cc.targetPrefix}cpp";
74 };
75
76 # Remove references to stdenv in comments.
77 postInstall = ''
78 remove-references-to -t ${stdenv.cc.cc} $out/${python.sitePackages}/pypdfium2_raw/bindings.py
79 '';
80
81 nativeCheckInputs = [
82 numpy
83 pillow
84 pytestCheckHook
85 ];
86
87 pythonImportsCheck = [
88 "pypdfium2"
89 ];
90
91 passthru = {
92 updateScript = gitUpdater {
93 allowedVersions = "^[.0-9]+$";
94 };
95 tests.cross = pkgsCross.aarch64-multiplatform.python3Packages.pypdfium2;
96 };
97
98 meta = {
99 changelog = "https://github.com/pypdfium2-team/pypdfium2/releases/tag/${version}";
100 description = "Python bindings to PDFium";
101 homepage = "https://pypdfium2.readthedocs.io/";
102 license = with lib.licenses; [
103 asl20 # or
104 mit
105 ];
106 maintainers = with lib.maintainers; [ booxter ];
107 };
108}