nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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 pytestCheckHook,
15 rich,
16 setuptools-scm,
17 setuptools,
18}:
19
20let
21 heap-layers-src = fetchFromGitHub {
22 owner = "emeryberger";
23 repo = "heap-layers";
24 name = "Heap-Layers";
25 rev = "a2048eae91b531dc5d72be7a194e0b333c06bd4c";
26 sha256 = "sha256-vl3z30CBX7hav/DM/UE0EQ9lLxZF48tMJrYMXuSulyA=";
27 };
28
29 printf-src = fetchFromGitHub {
30 owner = "mpaland";
31 repo = "printf";
32 name = "printf";
33 tag = "v4.0.0";
34 sha256 = "sha256-tgLJNJw/dJGQMwCmfkWNBvHB76xZVyyfVVplq7aSJnI=";
35 };
36in
37
38buildPythonPackage rec {
39 pname = "scalene";
40 version = "1.5.55";
41 pyproject = true;
42
43 src = fetchFromGitHub {
44 owner = "plasma-umass";
45 repo = "scalene";
46 tag = "v${version}";
47 hash = "sha256-aO7l/paYqbneDArAbXxptIlMGfvc1dAaFLucEj/7xbk=";
48 };
49
50 patches = [
51 ./01-manifest-no-git.patch
52 ];
53
54 prePatch = ''
55 cp -r ${heap-layers-src} vendor/Heap-Layers
56 mkdir vendor/printf
57 cp ${printf-src}/printf.c vendor/printf/printf.cpp
58 cp -r ${printf-src}/* vendor/printf
59 sed -i 's/^#define printf printf_/\/\/&/' vendor/printf/printf.h
60 sed -i 's/^#define vsnprintf vsnprintf_/\/\/&/' vendor/printf/printf.h
61 '';
62
63 nativeBuildInputs = [
64 cython
65 setuptools
66 setuptools-scm
67 ];
68
69 propagatedBuildInputs = [
70 cloudpickle
71 jinja2
72 numpy
73 psutil
74 pydantic
75 rich
76 ]
77 ++ lib.optionals stdenv.hostPlatform.isLinux [ nvidia-ml-py ];
78
79 pythonRemoveDeps = [
80 "nvidia-ml-py3"
81 ]
82 ++ lib.optionals stdenv.hostPlatform.isDarwin [ "nvidia-ml-py" ];
83
84 __darwinAllowLocalNetworking = true;
85
86 nativeCheckInputs = [ pytestCheckHook ];
87
88 checkInputs = [
89 hypothesis
90 numpy
91 ];
92
93 disabledTests = [
94 # Flaky -- socket collision
95 "test_show_browser"
96 # File not found
97 "test_nested_package_relative_import"
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 = {
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 = lib.licenses.asl20;
113 maintainers = with lib.maintainers; [ sarahec ];
114 badPlatforms = [
115 # The scalene doesn't seem to account for arm64 linux
116 "aarch64-linux"
117
118 # On darwin, builds 1) assume aarch64 and 2) mistakenly compile one part as
119 # x86 and the other as arm64 then tries to link them into a single binary
120 # which fails.
121 "x86_64-darwin"
122 "aarch64-darwin"
123 ];
124 };
125}