1{ lib
2, stdenv
3, buildPythonPackage
4, fetchFromGitHub
5, substituteAll
6, gdb
7, django
8, flask
9, gevent
10, psutil
11, pytest-timeout
12, pytest-xdist
13, pytestCheckHook
14, requests
15, isPy3k
16}:
17
18buildPythonPackage rec {
19 pname = "debugpy";
20 version = "1.5.1";
21
22 src = fetchFromGitHub {
23 owner = "Microsoft";
24 repo = pname;
25 rev = "v${version}";
26 sha256 = "sha256-dPP4stLt5nl9B9afPmH6/hpGKXBsaTpvYZQSHxU6KaY=";
27 };
28
29 patches = [
30 # Hard code GDB path (used to attach to process)
31 (substituteAll {
32 src = ./hardcode-gdb.patch;
33 inherit gdb;
34 })
35
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 ];
52
53 # Remove pre-compiled "attach" libraries and recompile for host platform
54 # Compile flags taken from linux_and_mac/compile_linux.sh & linux_and_mac/compile_mac.sh
55 preBuild = ''(
56 set -x
57 cd src/debugpy/_vendored/pydevd/pydevd_attach_to_process
58 rm *.so *.dylib *.dll *.exe *.pdb
59 ${stdenv.cc}/bin/c++ linux_and_mac/attach.cpp -Ilinux_and_mac -fPIC -nostartfiles ${{
60 "x86_64-linux" = "-shared -m64 -o attach_linux_amd64.so";
61 "i686-linux" = "-shared -m32 -o attach_linux_x86.so";
62 "x86_64-darwin" = "-std=c++11 -lc -D_REENTRANT -dynamiclib -arch x86_64 -o attach_x86_64.dylib";
63 "i686-darwin" = "-std=c++11 -lc -D_REENTRANT -dynamiclib -arch i386 -o attach_x86.dylib";
64 "aarch64-darwin" = "-std=c++11 -lc -D_REENTRANT -dynamiclib -arch arm64 -o attach_arm64.dylib";
65 }.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}")}
66 )'';
67
68 doCheck = isPy3k;
69 checkInputs = [
70 django
71 flask
72 gevent
73 psutil
74 pytest-timeout
75 pytest-xdist
76 pytestCheckHook
77 requests
78 ];
79
80 # Override default arguments in pytest.ini
81 pytestFlagsArray = [ "--timeout=0" "-n=$NIX_BUILD_CORES" ];
82
83 pythonImportsCheck = [ "debugpy" ];
84
85 meta = with lib; {
86 description = "An implementation of the Debug Adapter Protocol for Python";
87 homepage = "https://github.com/microsoft/debugpy";
88 license = licenses.mit;
89 maintainers = with maintainers; [ kira-bruneau ];
90 platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "i686-darwin" "aarch64-darwin" ];
91 };
92}