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 "x86_64-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_x86_64.dylib";
88 "aarch64-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_arm64.dylib";
89 }
90 .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}")
91 }
92 )'';
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 ''
120 export DEBUGPY_PROCESS_SPAWN_TIMEOUT=0
121 export DEBUGPY_PROCESS_EXIT_TIMEOUT=0
122 ''
123 + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
124 # https://github.com/python/cpython/issues/74570#issuecomment-1093748531
125 export no_proxy='*';
126 '';
127
128 postCheck = lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
129 unset no_proxy
130 '';
131
132 # Override default arguments in pytest.ini
133 pytestFlags = [ "--timeout=0" ];
134
135 disabledTests = [
136 # hanging test (flaky)
137 "test_systemexit"
138 ];
139
140 # Fixes hanging tests on Darwin
141 __darwinAllowLocalNetworking = true;
142
143 pythonImportsCheck = [ "debugpy" ];
144
145 meta = with lib; {
146 description = "Implementation of the Debug Adapter Protocol for Python";
147 homepage = "https://github.com/microsoft/debugpy";
148 changelog = "https://github.com/microsoft/debugpy/releases/tag/${src.tag}";
149 license = licenses.mit;
150 maintainers = with maintainers; [ kira-bruneau ];
151 platforms = [
152 "x86_64-linux"
153 "i686-linux"
154 "aarch64-linux"
155 "x86_64-darwin"
156 "aarch64-darwin"
157 ];
158 };
159}