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