1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 buildPythonPackage,
6 setuptools,
7 matplotlib,
8 numpy,
9 pytestCheckHook,
10 pillow,
11 nix-update-script,
12 typst,
13}:
14
15buildPythonPackage rec {
16 pname = "mpl-typst";
17 version = "0.2.1";
18 pyproject = true;
19
20 src = fetchFromGitHub {
21 owner = "daskol";
22 repo = "mpl-typst";
23 tag = "v${version}";
24 hash = "sha256-lkO4BTo3duNAsppTjteeBuzgSJL/UnKVW2QXgrfVrqM=";
25 };
26
27 postPatch = ''
28 # make hermetic
29 substituteInPlace mpl_typst/config.py \
30 --replace-fail \
31 "get_typst_compiler(name: str, default=Path('typst'))" \
32 "get_typst_compiler(name: str, default=Path('${lib.getExe typst}'))"
33 '';
34
35 build-system = [
36 setuptools
37 ];
38
39 dependencies = [
40 matplotlib
41 ];
42
43 nativeCheckInputs = [
44 pytestCheckHook
45 pillow
46 numpy
47 ];
48
49 pytestFlagsArray = [ "-v" ];
50
51 pythonImportsCheck = [
52 "mpl_typst"
53 "mpl_typst.as_default"
54 ];
55
56 disabledTests = [
57 # runs typst and gets "error: failed to download package"
58 "test_draw_path"
59 "test_draw_image_lenna"
60 "test_draw_image_spy"
61 ];
62
63 disabledTestPaths = lib.optional stdenv.hostPlatform.isDarwin [
64 # fatal error when matplotlib creates a canvas
65 "mpl_typst/backend_test.py"
66 ];
67
68 passthru.updateScript = nix-update-script { };
69
70 meta = {
71 description = "Typst backend for matplotlib";
72 homepage = "https://github.com/daskol/mpl-typst";
73 changelog = "https://github.com/daskol/mpl-typst/releases/tag/${src.tag}";
74 license = lib.licenses.mit;
75 maintainers = with lib.maintainers; [ genga898 ];
76 };
77}