Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 pythonOlder, 6 pythonAtLeast, 7 fetchFromGitHub, 8 substituteAll, 9 gdb, 10 lldb, 11 pytestCheckHook, 12 pytest-xdist, 13 pytest-timeout, 14 importlib-metadata, 15 psutil, 16 django, 17 requests, 18 gevent, 19 numpy, 20 flask, 21}: 22 23buildPythonPackage rec { 24 pname = "debugpy"; 25 version = "1.8.2"; 26 format = "setuptools"; 27 28 disabled = pythonOlder "3.8"; 29 30 src = fetchFromGitHub { 31 owner = "microsoft"; 32 repo = "debugpy"; 33 rev = "refs/tags/v${version}"; 34 hash = "sha256-J63izrJX7/el36kMHv+IyqDQ1C13CKb40HLOVgOzHEw="; 35 }; 36 37 patches = 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 # Attach pid tests are disabled by default on windows & macos, 56 # but are also flaky on linux: 57 # - https://github.com/NixOS/nixpkgs/issues/262000 58 # - https://github.com/NixOS/nixpkgs/issues/251045 59 ./skip-attach-pid-tests.patch 60 ] 61 ++ lib.optionals stdenv.isLinux [ 62 # Hard code GDB path (used to attach to process) 63 (substituteAll { 64 src = ./hardcode-gdb.patch; 65 inherit gdb; 66 }) 67 ] 68 ++ lib.optionals stdenv.isDarwin [ 69 # Hard code LLDB path (used to attach to process) 70 (substituteAll { 71 src = ./hardcode-lldb.patch; 72 inherit lldb; 73 }) 74 ]; 75 76 # Remove pre-compiled "attach" libraries and recompile for host platform 77 # Compile flags taken from linux_and_mac/compile_linux.sh & linux_and_mac/compile_mac.sh 78 preBuild = '' 79 ( 80 set -x 81 cd src/debugpy/_vendored/pydevd/pydevd_attach_to_process 82 rm *.so *.dylib *.dll *.exe *.pdb 83 $CXX linux_and_mac/attach.cpp -Ilinux_and_mac -std=c++11 -fPIC -nostartfiles ${ 84 { 85 "x86_64-linux" = "-shared -o attach_linux_amd64.so"; 86 "i686-linux" = "-shared -o attach_linux_x86.so"; 87 "aarch64-linux" = "-shared -o attach_linux_arm64.so"; 88 "x86_64-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_x86_64.dylib"; 89 "i686-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_x86.dylib"; 90 "aarch64-darwin" = "-D_REENTRANT -dynamiclib -lc -o attach_arm64.dylib"; 91 } 92 .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}") 93 } 94 )''; 95 96 # Disable tests for unmaintained versions of python 97 doCheck = pythonAtLeast "3.11"; 98 99 nativeCheckInputs = [ 100 ## Used to run the tests: 101 pytestCheckHook 102 pytest-xdist 103 pytest-timeout 104 105 ## Used by test helpers: 106 importlib-metadata 107 psutil 108 109 ## Used in Python code that is run/debugged by the tests: 110 django 111 flask 112 gevent 113 numpy 114 requests 115 ]; 116 117 preCheck = 118 '' 119 export DEBUGPY_PROCESS_SPAWN_TIMEOUT=0 120 export DEBUGPY_PROCESS_EXIT_TIMEOUT=0 121 '' 122 + lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) '' 123 # https://github.com/python/cpython/issues/74570#issuecomment-1093748531 124 export no_proxy='*'; 125 ''; 126 127 postCheck = lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) '' 128 unset no_proxy 129 ''; 130 131 # Override default arguments in pytest.ini 132 pytestFlagsArray = [ "--timeout=0" ]; 133 134 # Fixes hanging tests on Darwin 135 __darwinAllowLocalNetworking = true; 136 137 pythonImportsCheck = [ "debugpy" ]; 138 139 meta = with lib; { 140 description = "Implementation of the Debug Adapter Protocol for Python"; 141 homepage = "https://github.com/microsoft/debugpy"; 142 changelog = "https://github.com/microsoft/debugpy/releases/tag/v${version}"; 143 license = licenses.mit; 144 maintainers = with maintainers; [ kira-bruneau ]; 145 platforms = [ 146 "x86_64-linux" 147 "i686-linux" 148 "aarch64-linux" 149 "x86_64-darwin" 150 "i686-darwin" 151 "aarch64-darwin" 152 ]; 153 }; 154}