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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
{
lib,
stdenv,
buildPythonPackage,
fetchFromGitHub,
cloudpickle,
cython,
hypothesis,
jinja2,
numpy,
nvidia-ml-py,
psutil,
pydantic,
pytestCheckHook,
rich,
setuptools-scm,
setuptools,
}:
let
heap-layers-src = fetchFromGitHub {
owner = "emeryberger";
repo = "heap-layers";
name = "Heap-Layers";
rev = "a2048eae91b531dc5d72be7a194e0b333c06bd4c";
sha256 = "sha256-vl3z30CBX7hav/DM/UE0EQ9lLxZF48tMJrYMXuSulyA=";
};
printf-src = fetchFromGitHub {
owner = "mpaland";
repo = "printf";
name = "printf";
tag = "v4.0.0";
sha256 = "sha256-tgLJNJw/dJGQMwCmfkWNBvHB76xZVyyfVVplq7aSJnI=";
};
in
buildPythonPackage rec {
pname = "scalene";
version = "1.5.55";
pyproject = true;
src = fetchFromGitHub {
owner = "plasma-umass";
repo = "scalene";
tag = "v${version}";
hash = "sha256-aO7l/paYqbneDArAbXxptIlMGfvc1dAaFLucEj/7xbk=";
};
patches = [
./01-manifest-no-git.patch
];
prePatch = ''
cp -r ${heap-layers-src} vendor/Heap-Layers
mkdir vendor/printf
cp ${printf-src}/printf.c vendor/printf/printf.cpp
cp -r ${printf-src}/* vendor/printf
sed -i 's/^#define printf printf_/\/\/&/' vendor/printf/printf.h
sed -i 's/^#define vsnprintf vsnprintf_/\/\/&/' vendor/printf/printf.h
'';
nativeBuildInputs = [
cython
setuptools
setuptools-scm
];
propagatedBuildInputs = [
cloudpickle
jinja2
numpy
psutil
pydantic
rich
]
++ lib.optionals stdenv.hostPlatform.isLinux [ nvidia-ml-py ];
pythonRemoveDeps = [
"nvidia-ml-py3"
]
++ lib.optionals stdenv.hostPlatform.isDarwin [ "nvidia-ml-py" ];
__darwinAllowLocalNetworking = true;
nativeCheckInputs = [ pytestCheckHook ];
checkInputs = [
hypothesis
numpy
];
disabledTests = [
# Flaky -- socket collision
"test_show_browser"
# File not found
"test_nested_package_relative_import"
];
# remove scalene directory to prevent pytest import confusion
preCheck = ''
rm -rf scalene
'';
pythonImportsCheck = [ "scalene" ];
meta = {
description = "High-resolution, low-overhead CPU, GPU, and memory profiler for Python with AI-powered optimization suggestions";
homepage = "https://github.com/plasma-umass/scalene";
changelog = "https://github.com/plasma-umass/scalene/releases/tag/v${version}";
mainProgram = "scalene";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ sarahec ];
badPlatforms = [
# The scalene doesn't seem to account for arm64 linux
"aarch64-linux"
# On darwin, builds 1) assume aarch64 and 2) mistakenly compile one part as
# x86 and the other as arm64 then tries to link them into a single binary
# which fails.
"x86_64-darwin"
"aarch64-darwin"
];
};
}
|