1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 fetchFromGitHub,
7 substituteAll,
8 gdb,
9 lldb,
10 pytestCheckHook,
11 pytest-xdist,
12 pytest-timeout,
13 importlib-metadata,
14 psutil,
15 django,
16 requests,
17 gevent,
18 numpy,
19 flask,
20}:
21
22buildPythonPackage rec {
23 pname = "debugpy";
24 version = "1.8.1";
25 format = "setuptools";
26
27 disabled = pythonOlder "3.8";
28
29 src = fetchFromGitHub {
30 owner = "microsoft";
31 repo = "debugpy";
32 rev = "refs/tags/v${version}";
33 hash = "sha256-2TkieSQYxnlUroSD9wNKNaHUTLRksFWL/6XmSNGTCA4=";
34 };
35
36 patches =
37 [
38 # Use nixpkgs version instead of versioneer
39 (substituteAll {
40 src = ./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.isLinux [
61 # Hard code GDB path (used to attach to process)
62 (substituteAll {
63 src = ./hardcode-gdb.patch;
64 inherit gdb;
65 })
66 ]
67 ++ lib.optionals stdenv.isDarwin [
68 # Hard code LLDB path (used to attach to process)
69 (substituteAll {
70 src = ./hardcode-lldb.patch;
71 inherit lldb;
72 })
73 ];
74
75 # Remove pre-compiled "attach" libraries and recompile for host platform
76 # Compile flags taken from linux_and_mac/compile_linux.sh & linux_and_mac/compile_mac.sh
77 preBuild = ''
78 (
79 set -x
80 cd src/debugpy/_vendored/pydevd/pydevd_attach_to_process
81 rm *.so *.dylib *.dll *.exe *.pdb
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 "i686-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_x86.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 nativeCheckInputs = [
96 ## Used to run the tests:
97 pytestCheckHook
98 pytest-xdist
99 pytest-timeout
100
101 ## Used by test helpers:
102 importlib-metadata
103 psutil
104
105 ## Used in Python code that is run/debugged by the tests:
106 django
107 flask
108 gevent
109 numpy
110 requests
111 ];
112
113 preCheck =
114 ''
115 export DEBUGPY_PROCESS_SPAWN_TIMEOUT=0
116 export DEBUGPY_PROCESS_EXIT_TIMEOUT=0
117 ''
118 + lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
119 # https://github.com/python/cpython/issues/74570#issuecomment-1093748531
120 export no_proxy='*';
121 '';
122
123 postCheck = lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
124 unset no_proxy
125 '';
126
127 # Override default arguments in pytest.ini
128 pytestFlagsArray = [ "--timeout=0" ];
129
130 # Fixes hanging tests on Darwin
131 __darwinAllowLocalNetworking = true;
132
133 pythonImportsCheck = [ "debugpy" ];
134
135 meta = with lib; {
136 description = "An implementation of the Debug Adapter Protocol for Python";
137 homepage = "https://github.com/microsoft/debugpy";
138 changelog = "https://github.com/microsoft/debugpy/releases/tag/v${version}";
139 license = licenses.mit;
140 maintainers = with maintainers; [ kira-bruneau ];
141 platforms = [
142 "x86_64-linux"
143 "i686-linux"
144 "aarch64-linux"
145 "x86_64-darwin"
146 "i686-darwin"
147 "aarch64-darwin"
148 ];
149 };
150}