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