1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 isPyPy,
7 fetchFromGitHub,
8 setuptools,
9 setuptools-scm,
10 fs,
11 lxml,
12 brotli,
13 brotlicffi,
14 zopfli,
15 unicodedata2,
16 lz4,
17 scipy,
18 munkres,
19 pycairo,
20 matplotlib,
21 sympy,
22 xattr,
23 skia-pathops,
24 uharfbuzz,
25 pytest7CheckHook,
26}:
27
28buildPythonPackage rec {
29 pname = "fonttools";
30 version = "4.56.0";
31 pyproject = true;
32
33 disabled = pythonOlder "3.8";
34
35 src = fetchFromGitHub {
36 owner = "fonttools";
37 repo = "fonttools";
38 tag = version;
39 hash = "sha256-ZkC1+I2d9wY9J7IoCGHGWG2gOVN7wW274UpN1lQxmJY=";
40 };
41
42 patches = [
43 # https://github.com/fonttools/fonttools/pull/3855
44 # FIXME: remove when merged
45 ./python-3.13.4.patch
46 ];
47
48 build-system = [
49 setuptools
50 setuptools-scm
51 ];
52
53 optional-dependencies =
54 let
55 extras = {
56 ufo = [ fs ];
57 lxml = [ lxml ];
58 woff = [
59 (if isPyPy then brotlicffi else brotli)
60 zopfli
61 ];
62 unicode = lib.optional (pythonOlder "3.13") unicodedata2;
63 graphite = [ lz4 ];
64 interpolatable = [
65 pycairo
66 (if isPyPy then munkres else scipy)
67 ];
68 plot = [ matplotlib ];
69 symfont = [ sympy ];
70 type1 = lib.optional stdenv.hostPlatform.isDarwin xattr;
71 pathops = [ skia-pathops ];
72 repacker = [ uharfbuzz ];
73 };
74 in
75 extras // { all = lib.concatLists (lib.attrValues extras); };
76
77 nativeCheckInputs = [
78 # test suite fails with pytest>=8.0.1
79 # https://github.com/fonttools/fonttools/issues/3458
80 pytest7CheckHook
81 ]
82 ++ lib.concatLists (
83 lib.attrVals (
84 [
85 "woff"
86 # "interpolatable" is not included because it only contains 2 tests at the time of writing but adds 270 extra dependencies
87 "ufo"
88 ]
89 ++ lib.optionals (!skia-pathops.meta.broken) [
90 "pathops" # broken
91 ]
92 ++ [ "repacker" ]
93 ) optional-dependencies
94 );
95
96 pythonImportsCheck = [ "fontTools" ];
97
98 preCheck = ''
99 # tests want to execute the "fonttools" executable from $PATH
100 export PATH="$out/bin:$PATH"
101 '';
102
103 # Timestamp tests have timing issues probably related
104 # to our file timestamp normalization
105 disabledTests = [
106 "test_recalc_timestamp_ttf"
107 "test_recalc_timestamp_otf"
108 "test_ttcompile_timestamp_calcs"
109 ];
110
111 disabledTestPaths = [
112 # avoid test which depend on fs and matplotlib
113 # fs and matplotlib were removed to prevent strong cyclic dependencies
114 "Tests/misc/plistlib_test.py"
115 "Tests/pens"
116 "Tests/ufoLib"
117
118 # test suite fails with pytest>=8.0.1
119 # https://github.com/fonttools/fonttools/issues/3458
120 "Tests/ttLib/woff2_test.py"
121 "Tests/ttx/ttx_test.py"
122 ];
123
124 meta = with lib; {
125 homepage = "https://github.com/fonttools/fonttools";
126 description = "Library to manipulate font files from Python";
127 changelog = "https://github.com/fonttools/fonttools/blob/${src.tag}/NEWS.rst";
128 license = licenses.mit;
129 maintainers = [ maintainers.sternenseemann ];
130 };
131}