1{ lib
2, stdenv
3, buildPythonPackage
4, pythonOlder
5, pythonAtLeast
6, fetchFromGitHub
7, substituteAll
8, fetchpatch
9, gdb
10, django
11, flask
12, gevent
13, psutil
14, pytest-timeout
15, pytest-xdist
16, pytestCheckHook
17, requests
18, llvmPackages
19}:
20
21buildPythonPackage rec {
22 pname = "debugpy";
23 version = "1.8.0";
24 format = "setuptools";
25
26 disabled = pythonOlder "3.8" || pythonAtLeast "3.13";
27
28 src = fetchFromGitHub {
29 owner = "microsoft";
30 repo = "debugpy";
31 rev = "refs/tags/v${version}";
32 hash = "sha256-FW1RDmj4sDBS0q08C82ErUd16ofxJxgVaxfykn/wVBA=";
33 };
34
35 patches = [
36 # Use nixpkgs version instead of versioneer
37 (substituteAll {
38 src = ./hardcode-version.patch;
39 inherit version;
40 })
41
42 # Fix importing debugpy in:
43 # - test_nodebug[module-launch(externalTerminal)]
44 # - test_nodebug[module-launch(integratedTerminal)]
45 #
46 # NOTE: The import failures seen in these tests without the patch
47 # will be seen if a user "installs" debugpy by adding it to PYTHONPATH.
48 # To avoid this issue, debugpy should be installed using python.withPackages:
49 # python.withPackages (ps: with ps; [ debugpy ])
50 ./fix-test-pythonpath.patch
51 ] ++ lib.optionals stdenv.isLinux [
52 # Hard code GDB path (used to attach to process)
53 (substituteAll {
54 src = ./hardcode-gdb.patch;
55 inherit gdb;
56 })
57 ] ++ lib.optionals stdenv.isDarwin [
58 # Hard code LLDB path (used to attach to process)
59 (substituteAll {
60 src = ./hardcode-lldb.patch;
61 inherit (llvmPackages) lldb;
62 })
63 ];
64
65 # Remove pre-compiled "attach" libraries and recompile for host platform
66 # Compile flags taken from linux_and_mac/compile_linux.sh & linux_and_mac/compile_mac.sh
67 preBuild = ''(
68 set -x
69 cd src/debugpy/_vendored/pydevd/pydevd_attach_to_process
70 rm *.so *.dylib *.dll *.exe *.pdb
71 ${stdenv.cc}/bin/c++ linux_and_mac/attach.cpp -Ilinux_and_mac -fPIC -nostartfiles ${{
72 "x86_64-linux" = "-shared -o attach_linux_amd64.so";
73 "i686-linux" = "-shared -o attach_linux_x86.so";
74 "aarch64-linux" = "-shared -o attach_linux_arm64.so";
75 "x86_64-darwin" = "-std=c++11 -lc -D_REENTRANT -dynamiclib -o attach_x86_64.dylib";
76 "i686-darwin" = "-std=c++11 -lc -D_REENTRANT -dynamiclib -o attach_x86.dylib";
77 "aarch64-darwin" = "-std=c++11 -lc -D_REENTRANT -dynamiclib -o attach_arm64.dylib";
78 }.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}")}
79 )'';
80
81 nativeCheckInputs = [
82 django
83 flask
84 gevent
85 psutil
86 pytest-timeout
87 pytest-xdist
88 pytestCheckHook
89 requests
90 ];
91
92 preCheck = ''
93 export DEBUGPY_PROCESS_SPAWN_TIMEOUT=0
94 export DEBUGPY_PROCESS_EXIT_TIMEOUT=0
95 '' + lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
96 # https://github.com/python/cpython/issues/74570#issuecomment-1093748531
97 export no_proxy='*';
98 '';
99
100 postCheck = lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
101 unset no_proxy
102 '';
103
104 # Override default arguments in pytest.ini
105 pytestFlagsArray = [
106 "--timeout=0"
107 ];
108
109 # Fixes hanging tests on Darwin
110 __darwinAllowLocalNetworking = true;
111
112 disabledTests = [
113 # https://github.com/microsoft/debugpy/issues/1241
114 "test_flask_breakpoint_multiproc"
115
116 # DeprecationWarning: pkg_resources is deprecated as an API
117 # Supposedly fixed in https://github.com/microsoft/debugpy/pull/1374,
118 # but still fails for a nix build
119 "test_gevent"
120 ];
121
122 pythonImportsCheck = [
123 "debugpy"
124 ];
125
126 meta = with lib; {
127 description = "An implementation of the Debug Adapter Protocol for Python";
128 homepage = "https://github.com/microsoft/debugpy";
129 changelog = "https://github.com/microsoft/debugpy/releases/tag/v${version}";
130 license = licenses.mit;
131 maintainers = with maintainers; [ kira-bruneau ];
132 platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" "i686-darwin" "aarch64-darwin" ];
133 };
134}