summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/mpl-typst/default.nix
blob: 47f092e89fa01a916cc2809ae4e610679ac7e22d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{
  lib,
  stdenv,
  fetchFromGitHub,
  buildPythonPackage,
  setuptools,
  matplotlib,
  numpy,
  pytestCheckHook,
  pillow,
  nix-update-script,
  typst,
}:

buildPythonPackage rec {
  pname = "mpl-typst";
  version = "0.2.1";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "daskol";
    repo = "mpl-typst";
    tag = "v${version}";
    hash = "sha256-lkO4BTo3duNAsppTjteeBuzgSJL/UnKVW2QXgrfVrqM=";
  };

  postPatch = ''
    # make hermetic
    substituteInPlace mpl_typst/config.py \
      --replace-fail \
        "get_typst_compiler(name: str, default=Path('typst'))" \
        "get_typst_compiler(name: str, default=Path('${lib.getExe typst}'))"
  '';

  build-system = [
    setuptools
  ];

  dependencies = [
    matplotlib
  ];

  nativeCheckInputs = [
    pytestCheckHook
    pillow
    numpy
  ];

  pytestFlagsArray = [ "-v" ];

  pythonImportsCheck = [
    "mpl_typst"
    "mpl_typst.as_default"
  ];

  disabledTests = [
    # runs typst and gets "error: failed to download package"
    "test_draw_path"
    "test_draw_image_lenna"
    "test_draw_image_spy"
  ];

  disabledTestPaths = lib.optional stdenv.hostPlatform.isDarwin [
    # fatal error when matplotlib creates a canvas
    "mpl_typst/backend_test.py"
  ];

  passthru.updateScript = nix-update-script { };

  meta = {
    description = "Typst backend for matplotlib";
    homepage = "https://github.com/daskol/mpl-typst";
    changelog = "https://github.com/daskol/mpl-typst/releases/tag/${src.tag}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ genga898 ];
  };
}