1{ stdenv, buildPythonPackage, fetchFromGitHub
2, substituteAll, gdb
3, colorama, django, flask, gevent, psutil, pytest
4, pytest-timeout, pytest_xdist, requests
5, isPy27
6}:
7
8buildPythonPackage rec {
9 pname = "debugpy";
10 version = "1.0.0b12";
11
12 src = fetchFromGitHub {
13 owner = "Microsoft";
14 repo = pname;
15 rev = "v${version}";
16 sha256 = "0sz33aq5qldl7kh4qjf5w3d08l9s77ipcj4i9wfklj8f6vf9w1wh";
17 };
18
19 patches = [
20 # Hard code GDB path (used to attach to process)
21 (substituteAll {
22 src = ./hardcode-gdb.patch;
23 inherit gdb;
24 })
25
26 # Fix importing debugpy in:
27 # - test_nodebug[module-launch(externalTerminal)]
28 # - test_nodebug[module-launch(integratedTerminal)]
29 #
30 # NOTE: The import failures seen in these tests without the patch
31 # will be seen if a user "installs" debugpy by adding it to PYTHONPATH.
32 # To avoid this issue, debugpy should be installed using python.withPackages:
33 # python.withPackages (ps: with ps; [ debugpy ])
34 ./fix-test-pythonpath.patch
35 ];
36
37 # Remove pre-compiled "attach" libraries and recompile for host platform
38 # Compile flags taken from linux_and_mac/compile_linux.sh & linux_and_mac/compile_mac.sh
39 preBuild = ''(
40 set -x
41 cd src/debugpy/_vendored/pydevd/pydevd_attach_to_process
42 rm *.so *.dylib *.dll *.exe *.pdb
43 ${stdenv.cc}/bin/c++ linux_and_mac/attach.cpp -Ilinux_and_mac -fPIC -nostartfiles ${{
44 "x86_64-linux" = "-shared -m64 -o attach_linux_amd64.so";
45 "i686-linux" = "-shared -m32 -o attach_linux_x86.so";
46 "x86_64-darwin" = "-std=c++11 -lc -D_REENTRANT -dynamiclib -arch x86_64 -o attach_x86_64.dylib";
47 "i686-darwin" = "-std=c++11 -lc -D_REENTRANT -dynamiclib -arch i386 -o attach_x86.dylib";
48 }.${stdenv.hostPlatform.system}}
49 )'';
50
51 checkInputs = [
52 colorama django flask gevent psutil pytest
53 pytest-timeout pytest_xdist requests
54 ];
55
56 # Override default arguments in pytest.ini
57 checkPhase = "pytest --timeout 0 -n $NIX_BUILD_CORES"
58 # gevent fails to import zope.interface with Python 2.7
59 + stdenv.lib.optionalString isPy27 " -k 'not test_gevent'";
60
61 meta = with stdenv.lib; {
62 description = "An implementation of the Debug Adapter Protocol for Python";
63 homepage = "https://github.com/microsoft/debugpy";
64 license = licenses.mit;
65 maintainers = with maintainers; [ metadark ];
66 platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "i686-darwin" ];
67 };
68}