about summary refs log tree commit diff
path: root/pkgs/development/python-modules/pynvml/default.nix
blob: 762771c66a2bb1b25ab1783d2bd2e71498f677b2 (plain) (blame)
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
{
  lib,
  buildPythonPackage,
  cudaPackages,
  fetchFromGitHub,
  substituteAll,
  pythonOlder,
  addOpenGLRunpath,
  setuptools,
  pytestCheckHook,
  versioneer,
  pynvml,
}:

buildPythonPackage rec {
  pname = "pynvml";
  version = "11.5.0";
  pyproject = true;
  disabled = pythonOlder "3.6";

  src = fetchFromGitHub {
    owner = "gpuopenanalytics";
    repo = "pynvml";
    rev = "refs/tags/${version}";
    hash = "sha256-K3ZENjgi+TVDxr55dRK1y8SwzfgVIzcnD4oEI+KHRa4=";
  };

  patches = [
    (substituteAll {
      src = ./0001-locate-libnvidia-ml.so.1-on-NixOS.patch;
      inherit (addOpenGLRunpath) driverLink;
    })
  ];

  # unvendor versioneer
  postPatch = ''
    rm versioneer.py
  '';

  nativeBuildInputs = [
    setuptools
    versioneer
  ];

  pythonImportsCheck = [
    "pynvml"
    "pynvml.smi"
  ];

  nativeCheckInputs = [ pytestCheckHook ];

  # OSError: /run/opengl-driver/lib/libnvidia-ml.so.1: cannot open shared object file: No such file or directory
  doCheck = false;

  passthru.tests.tester-nvmlInit = cudaPackages.writeGpuTestPython { libraries = [ pynvml ]; } ''
    import pynvml
    from pynvml.smi import nvidia_smi  # noqa: F401

    print(f"{pynvml.nvmlInit()=}")
  '';

  meta = with lib; {
    description = "Python bindings for the NVIDIA Management Library";
    homepage = "https://github.com/gpuopenanalytics/pynvml";
    license = licenses.bsd3;
    maintainers = [ maintainers.bcdarwin ];
  };
}