1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 pythonAtLeast,
7 fetchFromGitHub,
8 substituteAll,
9 gdb,
10 lldb,
11 pytestCheckHook,
12 pytest-xdist,
13 pytest-timeout,
14 importlib-metadata,
15 psutil,
16 untangle,
17 django,
18 flask,
19 gevent,
20 numpy,
21 requests,
22 typing-extensions,
23}:
24
25buildPythonPackage rec {
26 pname = "debugpy";
27 version = "1.8.9";
28 format = "setuptools";
29
30 disabled = pythonOlder "3.8";
31
32 src = fetchFromGitHub {
33 owner = "microsoft";
34 repo = "debugpy";
35 rev = "refs/tags/v${version}";
36 hash = "sha256-JgYGdCGzzktigjEKMPbkcSJlFPYSEFEJvmIFfR0qSZM=";
37 };
38
39 patches =
40 [
41 # Use nixpkgs version instead of versioneer
42 (substituteAll {
43 src = ./hardcode-version.patch;
44 inherit version;
45 })
46
47 # Fix importing debugpy in:
48 # - test_nodebug[module-launch(externalTerminal)]
49 # - test_nodebug[module-launch(integratedTerminal)]
50 #
51 # NOTE: The import failures seen in these tests without the patch
52 # will be seen if a user "installs" debugpy by adding it to PYTHONPATH.
53 # To avoid this issue, debugpy should be installed using python.withPackages:
54 # python.withPackages (ps: with ps; [ debugpy ])
55 ./fix-test-pythonpath.patch
56
57 # Attach pid tests are disabled by default on windows & macos,
58 # but are also flaky on linux:
59 # - https://github.com/NixOS/nixpkgs/issues/262000
60 # - https://github.com/NixOS/nixpkgs/issues/251045
61 ./skip-attach-pid-tests.patch
62 ]
63 ++ lib.optionals stdenv.hostPlatform.isLinux [
64 # Hard code GDB path (used to attach to process)
65 (substituteAll {
66 src = ./hardcode-gdb.patch;
67 inherit gdb;
68 })
69 ]
70 ++ lib.optionals stdenv.hostPlatform.isDarwin [
71 # Hard code LLDB path (used to attach to process)
72 (substituteAll {
73 src = ./hardcode-lldb.patch;
74 inherit lldb;
75 })
76 ];
77
78 # Compile attach library for host platform
79 # Derived from linux_and_mac/compile_linux.sh & linux_and_mac/compile_mac.sh
80 preBuild = ''
81 (
82 set -x
83 cd src/debugpy/_vendored/pydevd/pydevd_attach_to_process
84 $CXX linux_and_mac/attach.cpp -Ilinux_and_mac -std=c++11 -fPIC -nostartfiles ${
85 {
86 "x86_64-linux" = "-shared -o attach_linux_amd64.so";
87 "i686-linux" = "-shared -o attach_linux_x86.so";
88 "aarch64-linux" = "-shared -o attach_linux_arm64.so";
89 "x86_64-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_x86_64.dylib";
90 "i686-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_x86.dylib";
91 "aarch64-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_arm64.dylib";
92 }
93 .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}")
94 }
95 )'';
96
97 # Disable tests for unmaintained versions of python
98 doCheck = pythonAtLeast "3.11";
99
100 nativeCheckInputs = [
101 ## Used to run the tests:
102 pytestCheckHook
103 pytest-xdist
104 pytest-timeout
105
106 ## Used by test helpers:
107 importlib-metadata
108 psutil
109 untangle
110
111 ## Used in Python code that is run/debugged by the tests:
112 django
113 flask
114 gevent
115 numpy
116 requests
117 typing-extensions
118 ];
119
120 preCheck =
121 ''
122 export DEBUGPY_PROCESS_SPAWN_TIMEOUT=0
123 export DEBUGPY_PROCESS_EXIT_TIMEOUT=0
124 ''
125 + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
126 # https://github.com/python/cpython/issues/74570#issuecomment-1093748531
127 export no_proxy='*';
128 '';
129
130 postCheck = lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
131 unset no_proxy
132 '';
133
134 # Override default arguments in pytest.ini
135 pytestFlagsArray = [ "--timeout=0" ];
136
137 # Fixes hanging tests on Darwin
138 __darwinAllowLocalNetworking = true;
139
140 pythonImportsCheck = [ "debugpy" ];
141
142 meta = with lib; {
143 description = "Implementation of the Debug Adapter Protocol for Python";
144 homepage = "https://github.com/microsoft/debugpy";
145 changelog = "https://github.com/microsoft/debugpy/releases/tag/v${version}";
146 license = licenses.mit;
147 maintainers = with maintainers; [ kira-bruneau ];
148 platforms = [
149 "x86_64-linux"
150 "i686-linux"
151 "aarch64-linux"
152 "x86_64-darwin"
153 "i686-darwin"
154 "aarch64-darwin"
155 ];
156 };
157}