diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | .vscode/launch.json | 12 | ||||
| -rw-r--r-- | DEBUG_template.toml | 3 | ||||
| -rw-r--r-- | lib/debug/debugger.py | 33 |
4 files changed, 20 insertions, 29 deletions
@@ -14,7 +14,6 @@ locales/ .pydevproject .project /.idea -/.vscode /VERSION /src/ .DS_STORE diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..10d9aca1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,12 @@ +{ + "configurations": [ + { + "name": "Python: Ink/Stitch", + "type": "python", + "request": "attach", + "listen": { + "port": 5678 + } + } + ] +} diff --git a/DEBUG_template.toml b/DEBUG_template.toml index f33b17b7..46bf65e8 100644 --- a/DEBUG_template.toml +++ b/DEBUG_template.toml @@ -28,9 +28,6 @@ ### disable debugger when calling from inkscape, default: false # disable_from_inkscape = true -### wait for debugger to attach (vscode), default: true -# wait_attach = false - ### creation of bash script, default: false # create_bash_script = true diff --git a/lib/debug/debugger.py b/lib/debug/debugger.py index c58ddb3e..157e4636 100644 --- a/lib/debug/debugger.py +++ b/lib/debug/debugger.py @@ -33,7 +33,6 @@ # ### Miscelaneous notes: # - to disable debugger when running from inkscape set disable_from_inkscape = true in DEBUG.toml # - to change various output file names see DEBUG.toml -# - to disable waiting for debugger to attach (vscode editor) set wait_attach = false in DEBUG.toml # - to prefer inkscape version of inkex module over pip version set prefer_pip_inkex = false in DEBUG.toml # ### @@ -100,26 +99,14 @@ # see: https://code.visualstudio.com/docs/python/debugging#_command-line-debugging # https://code.visualstudio.com/docs/python/debugging#_debugging-by-attaching-over-a-network-connection # -# 1. Install the Python extension for VS Code +# 1. Install the Python module to debug in VS Code # pip install debugpy -# 2. create .vscode/launch.json containing: -# "configurations": [ ... -# { -# "name": "Python: Attach", -# "type": "python", -# "request": "attach", -# "connect": { -# "host": "localhost", -# "port": 5678 -# } -# } -# ] -# 3. Touch a file named "DEBUG.toml" at the top of your git repo, as above -# set debug_type = vscode +# 2. Install the Python and Python Debugger extensions in VS Code +# 3. Copy and edit a file named "DEBUG.toml" from "DEBUG_template.toml" next to inkstitch.py in your git clone: +# debug_type = vscode # 4. Start the debug server in VS Code by clicking on the debug icon in the left pane # select "Python: Attach" from the dropdown menu and click on the green arrow. -# The debug server will start and connect to already running python processes, -# but immediately exit if no python processes are running. +# 5. Run Ink/Stitch and it should connect to VS Code's debugger automatically. # # Notes: # to see flask server url routes: @@ -147,7 +134,6 @@ def init_debugger(debug_type:str, ini: dict): if debug_type == 'none': return - wait_attach = safe_get(ini, "DEBUG", "wait_attach", default=True) # currently only for vscode debugger = debug_type try: @@ -172,11 +158,8 @@ def init_debugger(debug_type:str, ini: dict): try: if debugger == 'vscode': - debugpy.listen(('localhost', 5678)) - if wait_attach: - print("Waiting for debugger attach", file=sys.stderr) - debugpy.wait_for_client() # wait for debugger to attach - debugpy.breakpoint() # stop here to start normal debugging + debugpy.connect(("localhost", 5678)) + debugpy.breakpoint() elif debugger == 'pycharm': pydevd_pycharm.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True) @@ -188,7 +171,7 @@ def init_debugger(debug_type:str, ini: dict): raise ValueError(f"unknown debugger: '{debugger}'") except socket.error as error: - logger.info("Debugging: connection to pydevd failed: %s", error) + logger.info(f"Debugging: connection to {debugger} failed: %s", error) logger.info(f"Be sure to run 'Start debugging server' in {debugger} to enable debugging.") else: logger.info(f"Enabled '{debugger}' debugger.") |
