1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 pythonAtLeast,
7 fetchFromGitHub,
8 replaceVars,
9 gdb,
10 lldb,
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.14";
29 format = "setuptools";
30
31 disabled = pythonOlder "3.8";
32
33 src = fetchFromGitHub {
34 owner = "microsoft";
35 repo = "debugpy";
36 tag = "v${version}";
37 hash = "sha256-IOR6Dbbg/HK4/1re0BEWafwmpBMnQJCo5ojDMB2KgV4=";
38 };
39
40 patches =
41 [
42 # Use nixpkgs version instead of versioneer
43 (replaceVars ./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 (replaceVars ./hardcode-gdb.patch {
66 inherit gdb;
67 })
68 ]
69 ++ lib.optionals stdenv.hostPlatform.isDarwin [
70 # Hard code LLDB path (used to attach to process)
71 (replaceVars ./hardcode-lldb.patch {
72 inherit lldb;
73 })
74 ];
75
76 # Compile attach library for host platform
77 # Derived from linux_and_mac/compile_linux.sh & linux_and_mac/compile_mac.sh
78 preBuild = ''
79 (
80 set -x
81 cd src/debugpy/_vendored/pydevd/pydevd_attach_to_process
82 $CXX linux_and_mac/attach.cpp -Ilinux_and_mac -std=c++11 -fPIC -nostartfiles ${
83 {
84 "x86_64-linux" = "-shared -o attach_linux_amd64.so";
85 "i686-linux" = "-shared -o attach_linux_x86.so";
86 "aarch64-linux" = "-shared -o attach_linux_arm64.so";
87 "riscv64-linux" = "-shared -o attach_linux_riscv64.so";
88 "x86_64-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_x86_64.dylib";
89 "aarch64-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_arm64.dylib";
90 }
91 .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}")
92 }
93 )'';
94
95 # Disable tests for unmaintained versions of python
96 doCheck = pythonAtLeast "3.11";
97
98 nativeCheckInputs = [
99 ## Used to run the tests:
100 pytestCheckHook
101 pytest-xdist
102 pytest-timeout
103 pytest-retry
104
105 ## Used by test helpers:
106 importlib-metadata
107 psutil
108 untangle
109
110 ## Used in Python code that is run/debugged by the tests:
111 django
112 flask
113 gevent
114 numpy
115 requests
116 typing-extensions
117 ];
118
119 preCheck =
120 ''
121 export DEBUGPY_PROCESS_SPAWN_TIMEOUT=0
122 export DEBUGPY_PROCESS_EXIT_TIMEOUT=0
123 ''
124 + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
125 # https://github.com/python/cpython/issues/74570#issuecomment-1093748531
126 export no_proxy='*';
127 '';
128
129 postCheck = lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
130 unset no_proxy
131 '';
132
133 # Override default arguments in pytest.ini
134 pytestFlags = [ "--timeout=0" ];
135
136 disabledTests = [
137 # hanging test (flaky)
138 "test_systemexit"
139 ];
140
141 # Fixes hanging tests on Darwin
142 __darwinAllowLocalNetworking = true;
143
144 pythonImportsCheck = [ "debugpy" ];
145
146 meta = with lib; {
147 description = "Implementation of the Debug Adapter Protocol for Python";
148 homepage = "https://github.com/microsoft/debugpy";
149 changelog = "https://github.com/microsoft/debugpy/releases/tag/${src.tag}";
150 license = licenses.mit;
151 maintainers = with maintainers; [ kira-bruneau ];
152 platforms = [
153 "x86_64-linux"
154 "i686-linux"
155 "aarch64-linux"
156 "x86_64-darwin"
157 "aarch64-darwin"
158 "riscv64-linux"
159 ];
160 };
161}