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