1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 cloudpickle,
7 cython,
8 hypothesis,
9 jinja2,
10 numpy,
11 nvidia-ml-py,
12 psutil,
13 pydantic,
14 pynvml,
15 pytestCheckHook,
16 pythonOlder,
17 rich,
18 setuptools-scm,
19 setuptools,
20}:
21
22let
23 heap-layers-src = fetchFromGitHub {
24 owner = "emeryberger";
25 repo = "heap-layers";
26 name = "Heap-Layers";
27 rev = "a2048eae91b531dc5d72be7a194e0b333c06bd4c";
28 sha256 = "sha256-vl3z30CBX7hav/DM/UE0EQ9lLxZF48tMJrYMXuSulyA=";
29 };
30
31 printf-src = fetchFromGitHub {
32 owner = "mpaland";
33 repo = "printf";
34 name = "printf";
35 rev = "v4.0.0";
36 sha256 = "sha256-tgLJNJw/dJGQMwCmfkWNBvHB76xZVyyfVVplq7aSJnI=";
37 };
38in
39
40buildPythonPackage rec {
41 pname = "scalene";
42 version = "1.5.49";
43 pyproject = true;
44 disabled = pythonOlder "3.9";
45
46 src = fetchFromGitHub {
47 owner = "plasma-umass";
48 repo = "scalene";
49 rev = "v${version}";
50 hash = "sha256-Ivce90+W9NBMQjebj3zCB5eqDJydT8OTPYy4fjbybgI=";
51 };
52
53 patches = [
54 ./01-manifest-no-git.patch
55 ];
56
57 prePatch = ''
58 cp -r ${heap-layers-src} vendor/Heap-Layers
59 mkdir vendor/printf
60 cp ${printf-src}/printf.c vendor/printf/printf.cpp
61 cp -r ${printf-src}/* vendor/printf
62 sed -i"" 's/^#define printf printf_/\/\/&/' vendor/printf/printf.h
63 sed -i"" 's/^#define vsnprintf vsnprintf_/\/\/&/' vendor/printf/printf.h
64 '';
65
66 nativeBuildInputs = [
67 cython
68 setuptools
69 setuptools-scm
70 ];
71
72 propagatedBuildInputs = [
73 cloudpickle
74 jinja2
75 numpy
76 psutil
77 pydantic
78 pynvml
79 rich
80 ] ++ lib.optionals stdenv.hostPlatform.isLinux [ nvidia-ml-py ];
81
82 pythonRemoveDeps = [
83 "nvidia-ml-py3"
84 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ "nvidia-ml-py" ];
85
86 __darwinAllowLocalNetworking = true;
87
88 nativeCheckInputs = [ pytestCheckHook ];
89
90 checkInputs = [
91 hypothesis
92 numpy
93 ];
94
95 disabledTests = [
96 # Flaky -- socket collision
97 "test_show_browser"
98 ];
99
100 # remove scalene directory to prevent pytest import confusion
101 preCheck = ''
102 rm -rf scalene
103 '';
104
105 pythonImportsCheck = [ "scalene" ];
106
107 meta = with lib; {
108 description = "High-resolution, low-overhead CPU, GPU, and memory profiler for Python with AI-powered optimization suggestions";
109 homepage = "https://github.com/plasma-umass/scalene";
110 changelog = "https://github.com/plasma-umass/scalene/releases/tag/v${version}";
111 mainProgram = "scalene";
112 license = licenses.asl20;
113 maintainers = with maintainers; [ sarahec ];
114 };
115}