summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/onnx/default.nix
blob: 4ba0c3baf3c9ff171afa99716ecff9a9fccbeca8 (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
78
79
80
81
82
{
  buildPythonPackage,
  onnx, # pkgs.onnx

  # dependencies
  ml-dtypes,
  numpy,
  protobuf,
  typing-extensions,

  # tests
  parameterized,
  pillow,
  pytestCheckHook,
  writableTmpDirAsHomeHook,
}:
buildPythonPackage {
  inherit (onnx)
    pname
    src # Needed for testing.
    version
    ;

  format = "wheel";

  dontUseWheelUnpack = true;

  postUnpack = ''
    cp -rv "${onnx.dist}" "$sourceRoot/dist"
    chmod +w "$sourceRoot/dist"
  '';

  buildInputs = [
    # onnx must be included to avoid shrinking during fixupPhase removing the RUNPATH entry on
    # onnx_cpp2py_export.cpython-*.so.
    onnx
  ];

  dependencies = [
    ml-dtypes
    numpy
    protobuf
    typing-extensions
  ];

  nativeCheckInputs = [
    parameterized
    pillow
    pytestCheckHook
    writableTmpDirAsHomeHook
  ];

  # The executables are just utility scripts that aren't too important
  postInstall = ''
    rm -rv $out/bin
  '';

  # detecting source dir as a python package confuses pytest
  preCheck = ''
    rm onnx/__init__.py
  '';

  enabledTestPaths = [
    "onnx/test"
    "examples"
  ];

  __darwinAllowLocalNetworking = true;

  pythonImportsCheck = [ "onnx" ];

  meta = {
    # Explicitly inherit from ONNX's meta to avoid pulling in attributes added by stdenv.mkDerivation.
    inherit (onnx.meta)
      changelog
      description
      homepage
      license
      maintainers
      ;
  };
}