Skip to content

Commit 185d7dc

Browse files
Merge pull request #418 from replit/dstewart/upgrade-debugpy
[debugpy] Reflow dap-python to remove override
2 parents f6939e5 + b3264d9 commit 185d7dc

File tree

4 files changed

+62
-75
lines changed

4 files changed

+62
-75
lines changed

pkgs/dapPython/default.nix

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,24 @@
11
{ pkgs, python, pypkgs, debugpy ? pypkgs.debugpy }:
22

3-
pypkgs.buildPythonPackage rec {
4-
pname = "replit-python-dap-wrapper";
3+
let
4+
pythonVersion = pkgs.lib.versions.majorMinor python.version;
5+
in
6+
pkgs.stdenv.mkDerivation {
7+
name = "dap-python";
58
version = debugpy.version;
6-
7-
src = ./.;
8-
99
propagatedBuildInputs = [
10-
debugpy
10+
(python.withPackages (_: [
11+
debugpy
12+
]))
1113
];
12-
13-
postInstall = ''
14+
dontUnpack = true;
15+
installPhase = ''
1416
mkdir -p $out/bin
15-
16-
cat<<EOF > $out/bin/dap-python
17-
#!${python}/bin/python3
18-
"""A small wrapper around debugpy's cli.
19-
20-
This wrapper is roughly equivalent to:
21-
22-
python3 -m debugpy --listen localhost:0 --wait-for-client "$@"
23-
24-
with the added twist that it reports the port used back through fd 3.
25-
"""
26-
27-
import os
28-
import os.path
29-
import sys
30-
import runpy
31-
32-
import debugpy
33-
import debugpy.server
34-
35-
36-
def _main() -> None:
37-
if len(sys.argv) < 2:
38-
print(f'Usage: {sys.argv[0]} <script> [args...]', file=sys.stderr)
39-
sys.exit(1)
40-
# This process' stdout/stderr are already used to deliver
41-
# the debuggee's stdout/stderr. We need to deliver this
42-
# information out of band, through fd 3.
43-
with os.fdopen(3, 'w') as port_fd:
44-
port_fd.write(str(debugpy.listen(('localhost', 0))[1]))
45-
debugpy.wait_for_client()
46-
# The first argument to this script is this script itself, so we need to
47-
# remove it. Otherwise `runpy.run_path` below will change `sys.argv[0]` to
48-
# the script being run, which would result in the script name being
49-
# duplicate.
50-
sys.argv.pop(0)
51-
target_as_str = sys.argv[0]
52-
dir = os.path.dirname(os.path.abspath(target_as_str))
53-
sys.path.insert(0, os.getcwd())
54-
runpy.run_path(target_as_str, run_name="__main__")
55-
56-
57-
if __name__ == '__main__':
58-
_main()
59-
EOF
17+
cp ${./wrapper.py} $out/bin/dap-python
6018
chmod +x $out/bin/dap-python
19+
20+
substituteInPlace $out/bin/dap-python \
21+
--replace "@python-bin@" "${python}/bin/python3" \
22+
--replace "@debugpy-path@" "${debugpy.out}/lib/python${pythonVersion}/site-packages"
6123
'';
6224
}

pkgs/dapPython/setup.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

pkgs/dapPython/wrapper.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!@python-bin@
2+
"""A small wrapper around debugpy's cli.
3+
4+
This wrapper is roughly equivalent to:
5+
6+
python3 -m debugpy --listen localhost:0 --wait-for-client "$@"
7+
8+
with the added twist that it reports the port used back through fd 3.
9+
"""
10+
11+
import os
12+
import os.path
13+
import sys
14+
import runpy
15+
16+
# Permit interpolated path to be sensibly replaced.
17+
for idx, path in enumerate("@debugpy-path@".split(":")):
18+
sys.path.insert(idx, path)
19+
20+
import debugpy
21+
import debugpy.server
22+
23+
24+
def _main() -> None:
25+
if len(sys.argv) < 2:
26+
print(f'Usage: {sys.argv[0]} <script> [args...]', file=sys.stderr)
27+
sys.exit(1)
28+
# This process' stdout/stderr are already used to deliver
29+
# the debuggee's stdout/stderr. We need to deliver this
30+
# information out of band, through fd 3.
31+
with os.fdopen(3, 'w') as port_fd:
32+
port_fd.write(str(debugpy.listen(('localhost', 0))[1]))
33+
debugpy.wait_for_client()
34+
# The first argument to this script is this script itself, so we need to
35+
# remove it. Otherwise `runpy.run_path` below will change `sys.argv[0]` to
36+
# the script being run, which would result in the script name being
37+
# duplicate.
38+
sys.argv.pop(0)
39+
target_as_str = sys.argv[0]
40+
dir = os.path.dirname(os.path.abspath(target_as_str))
41+
sys.path.insert(0, os.getcwd())
42+
runpy.run_path(target_as_str, run_name="__main__")
43+
44+
45+
if __name__ == '__main__':
46+
_main()

pkgs/modules/python/default.nix

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,8 @@ let
3232
destination = "/config.toml";
3333
};
3434

35-
debugpy = pypkgs.debugpy.overridePythonAttrs
36-
(old: rec {
37-
disabled = false;
38-
version = "1.8.0";
39-
src = pkgs.fetchFromGitHub {
40-
owner = "microsoft";
41-
repo = "debugpy";
42-
rev = "refs/tags/v${version}";
43-
hash = "sha256-FW1RDmj4sDBS0q08C82ErUd16ofxJxgVaxfykn/wVBA=";
44-
};
45-
doCheck = false;
46-
});
47-
4835
dapPython = pkgs.callPackage ../../dapPython {
49-
inherit pkgs python pypkgs debugpy;
36+
inherit pkgs python pypkgs;
5037
};
5138

5239
debuggerConfig = {

0 commit comments

Comments
 (0)