Skip to content

Commit 1c2347b

Browse files
tettoffensiveAlansCodeLog
authored andcommitted
Switched to Debugpy
- ptvsd is deprecated in favor of debugpy - Closes #19
1 parent d02c4cb commit 1c2347b

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

__init__.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
bl_info = {
2222
'name': 'Debugger for VS Code',
2323
'author': 'Alan North',
24-
'version': (1, 0, 1),
24+
'version': (2, 0, 0),
2525
'blender': (2, 80, 0), # supports 2.8+
2626
"description": "Starts debugging server for VS Code.",
2727
'location': 'In search (Edit > Operator Search) type "Debug"',
@@ -37,9 +37,9 @@
3737
import subprocess
3838
import re
3939

40-
# finds path to ptvsd if it exists
41-
def check_for_ptvsd():
42-
#commands to check
40+
# finds path to debugpy if it exists
41+
def check_for_debugpy():
42+
# commands to check
4343
checks = [
4444
["where", "python"],
4545
["whereis", "python"],
@@ -64,29 +64,30 @@ def check_for_ptvsd():
6464
match = re.search(".*(/)", location)
6565
if match is not None:
6666
match = match.group()
67-
if os.path.exists(match+"lib/site-packages/ptvsd"):
67+
if os.path.exists(match+"lib/site-packages/debugpy"):
6868
match = match+"lib/site-packages"
6969
return match
7070

71-
#check in path just in case PYTHONPATH happens to be set
71+
# check in path just in case PYTHONPATH happens to be set
72+
# this is not going to work because Blender's sys.path is different
7273
for path in sys.path:
7374
path = path.rstrip("/")
74-
if os.path.exists(path+"/ptvsd"):
75+
if os.path.exists(path+"/debugpy"):
7576
return path
76-
if os.path.exists(path+"/site-packages/ptvsd"):
77+
if os.path.exists(path+"/site-packages/debugpy"):
7778
return path+"/site-packages"
78-
if os.path.exists(path+"/lib/site-packages/ptvsd"):
79+
if os.path.exists(path+"/lib/site-packages/debugpy"):
7980
return path+"lib/site-packages"
80-
return "PTVSD not Found"
81+
return "debugpy not Found"
8182

8283
# Preferences
8384
class DebuggerPreferences(bpy.types.AddonPreferences):
8485
bl_idname = __name__
8586

8687
path: bpy.props.StringProperty(
87-
name="Location of PTVSD",
88+
name="Location of debugpy (site-packages folder)",
8889
subtype="DIR_PATH",
89-
default=check_for_ptvsd()
90+
default=check_for_debugpy()
9091
)
9192

9293
timeout: bpy.props.IntProperty(
@@ -103,7 +104,7 @@ class DebuggerPreferences(bpy.types.AddonPreferences):
103104
def draw(self, context):
104105
layout = self.layout
105106
row_path = layout
106-
row_path.label(text="The addon will try to auto-find the location to ptvsd, if no path is found, or you would like to use a different path, set it here.")
107+
row_path.label(text="The addon will try to auto-find the location of debugpy, if no path is found, or you would like to use a different path, set it here.")
107108
row_path.prop(self, "path")
108109

109110
row_timeout = layout.split()
@@ -122,7 +123,7 @@ def check_done(i, modal_limit, prefs):
122123
if i > modal_limit:
123124
print("Attach Confirmation Listener Timed Out")
124125
return {"CANCELLED"}
125-
if not ptvsd.is_attached():
126+
if not debugpy.is_client_connected():
126127
return {"PASS_THROUGH"}
127128
print('Debugger is Attached')
128129
return {"FINISHED"}
@@ -163,32 +164,32 @@ def cancel(self, context):
163164
class DebugServerStart(bpy.types.Operator):
164165
bl_idname = "debug.connect_debugger_vscode"
165166
bl_label = "Debug: Start Debug Server for VS Code"
166-
bl_description = "Starts ptvsd server for debugger to attach to"
167+
bl_description = "Starts debugpy server for debugger to attach to"
167168

168169
def execute(self, context):
169-
#get ptvsd and import if exists
170+
#get debugpy and import if exists
170171
prefs = bpy.context.preferences.addons[__name__].preferences
171-
ptvsd_path = prefs.path.rstrip("/")
172-
ptvsd_port = prefs.port
172+
debugpy_path = prefs.path.rstrip("/")
173+
debugpy_port = prefs.port
173174

174-
#actually check ptvsd is still available
175-
if ptvsd_path == "PTVSD not Found":
176-
self.report({"ERROR"}, "Couldn't detect ptvsd, please specify the path manually in the addon preferences or reload the addon if you installed ptvsd after enabling it.")
175+
#actually check debugpy is still available
176+
if debugpy_path == "debugpy not found":
177+
self.report({"ERROR"}, "Couldn't detect debugpy, please specify the path manually in the addon preferences or reload the addon if you installed debugpy after enabling it.")
177178
return {"CANCELLED"}
178179

179-
if not os.path.exists(os.path.abspath(ptvsd_path+"/ptvsd")):
180-
self.report({"ERROR"}, "Can't find ptvsd at: %r/ptvsd." % ptvsd_path)
180+
if not os.path.exists(os.path.abspath(debugpy_path+"/debugpy")):
181+
self.report({"ERROR"}, "Can't find debugpy at: %r/debugpy." % debugpy_path)
181182
return {"CANCELLED"}
182183

183-
if not any(ptvsd_path in p for p in sys.path):
184-
sys.path.append(ptvsd_path)
184+
if not any(debugpy_path in p for p in sys.path):
185+
sys.path.append(debugpy_path)
185186

186-
global ptvsd #so we can do check later
187-
import ptvsd
187+
global debugpy #so we can do check later
188+
import debugpy
188189

189190
# can only be attached once, no way to detach (at least not that I understand?)
190191
try:
191-
ptvsd.enable_attach(("0.0.0.0", ptvsd_port), redirect_output=True)
192+
debugpy.listen(("localhost", debugpy_port))
192193
except:
193194
print("Server already running.")
194195

0 commit comments

Comments
 (0)