1{
2 lib,
3 stdenv,
4 pkgs,
5 buildPythonPackage,
6 fetchFromGitHub,
7 fontconfig,
8 glib,
9 harfbuzz,
10 pango,
11
12 # build-system
13 flit-core,
14
15 # dependencies
16 cffi,
17 cssselect2,
18 fonttools,
19 pillow,
20 pydyf,
21 pyphen,
22 tinycss2,
23 tinyhtml5,
24
25 # tests
26 pytest-cov-stub,
27 pytestCheckHook,
28 replaceVars,
29 versionCheckHook,
30 writableTmpDirAsHomeHook,
31}:
32
33buildPythonPackage rec {
34 pname = "weasyprint";
35 version = "65.1";
36 pyproject = true;
37
38 src = fetchFromGitHub {
39 owner = "Kozea";
40 repo = "WeasyPrint";
41 tag = "v${version}";
42 hash = "sha256-iSeuRX1dnnrGZbcb1yTxOJPD5kgIWY6oz/0v02QJqSs=";
43 };
44
45 patches = [
46 (replaceVars ./library-paths.patch {
47 fontconfig = "${fontconfig.lib}/lib/libfontconfig${stdenv.hostPlatform.extensions.sharedLibrary}";
48 gobject = "${glib.out}/lib/libgobject-2.0${stdenv.hostPlatform.extensions.sharedLibrary}";
49 harfbuzz = "${harfbuzz.out}/lib/libharfbuzz${stdenv.hostPlatform.extensions.sharedLibrary}";
50 harfbuzz_subset = "${harfbuzz.out}/lib/libharfbuzz-subset${stdenv.hostPlatform.extensions.sharedLibrary}";
51 pango = "${pango.out}/lib/libpango-1.0${stdenv.hostPlatform.extensions.sharedLibrary}";
52 pangoft2 = "${pango.out}/lib/libpangoft2-1.0${stdenv.hostPlatform.extensions.sharedLibrary}";
53 })
54 ];
55
56 build-system = [ flit-core ];
57
58 dependencies = [
59 cffi
60 cssselect2
61 fonttools
62 pillow
63 pydyf
64 pyphen
65 tinycss2
66 tinyhtml5
67 ]
68 ++ fonttools.optional-dependencies.woff;
69
70 nativeCheckInputs = [
71 pkgs.ghostscript
72 pytest-cov-stub
73 pytestCheckHook
74 versionCheckHook
75 writableTmpDirAsHomeHook
76 ];
77 versionCheckProgramArg = "--version";
78
79 disabledTests = [
80 # needs the Ahem font (fails on macOS)
81 "test_font_stretch"
82 # sensitive to sandbox environments
83 "test_linear_gradients_12"
84 "test_linear_gradients_5"
85 "test_tab_size"
86 "test_tabulation_character"
87 # rounding issues in sandbox
88 "test_empty_inline_auto_margins"
89 "test_images_transparent_text"
90 "test_layout_table_auto_44"
91 "test_layout_table_auto_45"
92 "test_margin_boxes_element"
93 "test_running_elements"
94 "test_vertical_align_4"
95 "test_visibility_1"
96 "test_visibility_3"
97 "test_visibility_4"
98 "test_woff_simple"
99 ];
100
101 FONTCONFIG_FILE = "${fontconfig.out}/etc/fonts/fonts.conf";
102
103 # Set env variable explicitly for Darwin, but allow overriding when invoking directly
104 makeWrapperArgs = [ "--set-default FONTCONFIG_FILE ${FONTCONFIG_FILE}" ];
105
106 pythonImportsCheck = [ "weasyprint" ];
107
108 meta = {
109 changelog = "https://github.com/Kozea/WeasyPrint/releases/tag/v${version}";
110 description = "Converts web documents to PDF";
111 mainProgram = "weasyprint";
112 homepage = "https://weasyprint.org/";
113 license = lib.licenses.bsd3;
114 teams = [ lib.teams.apm ];
115 badPlatforms = [
116 # Fatal Python error: Segmentation fault
117 # "...weasyprint/pdf/fonts.py", line 221 in _harfbuzz_subset
118 lib.systems.inspect.patterns.isDarwin
119 ];
120 };
121}