From 06341b628519de05ce35bcfafe8a3df444526a27 Mon Sep 17 00:00:00 2001 From: Rick Levine Date: Wed, 15 Feb 2023 20:11:13 -0800 Subject: Pycharm debugging info --- lib/debug.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'lib/debug.py') diff --git a/lib/debug.py b/lib/debug.py index 83dd1766..a340df18 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -47,7 +47,7 @@ class Debug(object): self.log("Debug logging enabled.") def init_debugger(self): - # How to debug Ink/Stitch: + # How to debug Ink/Stitch with LiClipse: # # 1. Install LiClipse (liclipse.com) -- no need to install Eclipse first # 2. Start debug server as described here: http://www.pydev.org/manual_adv_remote_debugger.html @@ -55,8 +55,55 @@ class Debug(object): # 3. Create a file named "DEBUG" next to inkstitch.py in your git clone. # 4. Run any extension and PyDev will start debugging. + ### + + # To debug with PyCharm: + + # 0. You must use the PyCharm Professional Edition and _not_ the Community + # Edition. Jetbrains has chosen to make remote debugging a Pro feature. + # To debug Inkscape python extensions, the extension code and Inkscape run + # independently of PyCharm, and only communicate with the debugger via a + # TCP socket. Thus, debugging is "remote," even if it's on the same machine, + # connected via the loopback interface. + # + # 1. pip install pydev_pycharm + # + # pydev_pycharm is versioned frequently. Jetbrains suggests installing + # a version at least compatible with the current build. For example, if your + # PyCharm build, as found in menu PyCharm -> About Pycharm is 223.8617.48, + # you could do: + # pip install pydevd-pycharm~=223.8617.48 + # + # 2. In the Run menu, choose "Edit Configurations..." and create a new + # configuration. Set "IDE host name:" to "localhost" and "Port:" to 5678. + # You can leave the default settings for all other choices. + # + # 3. Touch a file named "DEBUG" at the top of your git repo, as above. + # + # 4. In the execution env for Inkscape, set the environment variable + # PYCHARM_REMOTE_DEBUG to any value, and launch Inkscape. If you're starting + # Inkscape from the PyCharm Terminal pane, you can do: + # export PYCHARM_REMOTE_DEBUG=true;inkscape + # + # 5. Either click on the green "bug" icon or press Ctrl-D to start debugging. + # The PyCharm debugger pane will display the message "Waiting for process + # connection..." + # + # 6. Do some action in Inkscape which runs Ink/Stitch extension code, and the + # debugger will be triggered. If you've left "Suspend after connect" checked + # in the Run configuration, PyCharm will pause in the "self.log("Enabled + # PyDev debugger.)" statement, below. Uncheck the box to have it continue + # automatically to your first set breakpoint. + + # Thanks to lexelby for the hints needed to puzzle this out. + + try: - import pydevd + if 'PYCHARM_REMOTE_DEBUG' in os.environ: + import pydevd_pycharm + else: + import pydevd + except ImportError: self.log("importing pydevd failed (debugger disabled)") @@ -66,7 +113,12 @@ class Debug(object): sys.stderr = devnull try: - pydevd.settrace() + if 'PYCHARM_REMOTE_DEBUG' in os.environ: + pydevd_pycharm.settrace('localhost', port=5678, stdoutToServer=True, + stderrToServer=True) + else: + pydevd.settrace() + except socket.error as error: self.log("Debugging: connection to pydevd failed: %s", error) self.log("Be sure to run 'Start debugging server' in PyDev to enable debugging.") -- cgit v1.2.3 From 42bbeb9891eb05c0675d716fac16a95b1fb4d2d3 Mon Sep 17 00:00:00 2001 From: Rick Levine Date: Thu, 16 Feb 2023 05:00:12 -0800 Subject: Add symbolic link note --- lib/debug.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'lib/debug.py') diff --git a/lib/debug.py b/lib/debug.py index a340df18..890280f8 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -59,12 +59,12 @@ class Debug(object): # To debug with PyCharm: - # 0. You must use the PyCharm Professional Edition and _not_ the Community - # Edition. Jetbrains has chosen to make remote debugging a Pro feature. - # To debug Inkscape python extensions, the extension code and Inkscape run - # independently of PyCharm, and only communicate with the debugger via a - # TCP socket. Thus, debugging is "remote," even if it's on the same machine, - # connected via the loopback interface. + # You must use the PyCharm Professional Edition and _not_ the Community + # Edition. Jetbrains has chosen to make remote debugging a Pro feature. + # To debug Inkscape python extensions, the extension code and Inkscape run + # independently of PyCharm, and only communicate with the debugger via a + # TCP socket. Thus, debugging is "remote," even if it's on the same machine, + # connected via the loopback interface. # # 1. pip install pydev_pycharm # @@ -74,22 +74,33 @@ class Debug(object): # you could do: # pip install pydevd-pycharm~=223.8617.48 # - # 2. In the Run menu, choose "Edit Configurations..." and create a new + # 2. From the Pycharm "Run" menu, choose "Edit Configurations..." and create a new # configuration. Set "IDE host name:" to "localhost" and "Port:" to 5678. # You can leave the default settings for all other choices. # # 3. Touch a file named "DEBUG" at the top of your git repo, as above. # - # 4. In the execution env for Inkscape, set the environment variable + # 4. Create a symbolic link in the Inkscape extensions directory to the + # top-level directory of your github repo. On a mac, for example: + # cd ~/Library/Application\ Support/org.inkscape.Inkscape/config/inkscape/extensions/ + # ln -s + # On other architectures it may be: + # cd ~/.config/inkscape/extensions + # ln -s + # Remove any other Ink/Stitch files or references to Ink/Stitch from the + # extensions directory, or you'll see duplicate entries in the Ink/Stitch + # extensions menu in Inkscape. + # + # 5. In the execution env for Inkscape, set the environment variable # PYCHARM_REMOTE_DEBUG to any value, and launch Inkscape. If you're starting # Inkscape from the PyCharm Terminal pane, you can do: # export PYCHARM_REMOTE_DEBUG=true;inkscape # - # 5. Either click on the green "bug" icon or press Ctrl-D to start debugging. + # 6. Either click on the green "bug" icon or press Ctrl-D to start debugging. # The PyCharm debugger pane will display the message "Waiting for process # connection..." # - # 6. Do some action in Inkscape which runs Ink/Stitch extension code, and the + # 7. Do some action in Inkscape which invokes Ink/Stitch extension code, and the # debugger will be triggered. If you've left "Suspend after connect" checked # in the Run configuration, PyCharm will pause in the "self.log("Enabled # PyDev debugger.)" statement, below. Uncheck the box to have it continue -- cgit v1.2.3 From 5c4b1ce23fc491f5f8f4d42138f4c71f40c8a3f5 Mon Sep 17 00:00:00 2001 From: Rick Levine Date: Thu, 16 Feb 2023 05:02:07 -0800 Subject: Fix typos --- lib/debug.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/debug.py') diff --git a/lib/debug.py b/lib/debug.py index 890280f8..aae9ae81 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -81,12 +81,12 @@ class Debug(object): # 3. Touch a file named "DEBUG" at the top of your git repo, as above. # # 4. Create a symbolic link in the Inkscape extensions directory to the - # top-level directory of your github repo. On a mac, for example: + # top-level directory of your git repo. On a mac, for example: # cd ~/Library/Application\ Support/org.inkscape.Inkscape/config/inkscape/extensions/ - # ln -s + # ln -s # On other architectures it may be: # cd ~/.config/inkscape/extensions - # ln -s + # ln -s # Remove any other Ink/Stitch files or references to Ink/Stitch from the # extensions directory, or you'll see duplicate entries in the Ink/Stitch # extensions menu in Inkscape. -- cgit v1.2.3 From a9b7f8c75a9859d843ed1370ab9a6ad5c77f08f7 Mon Sep 17 00:00:00 2001 From: Rick Levine Date: Thu, 16 Feb 2023 05:05:38 -0800 Subject: More tweaks --- lib/debug.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/debug.py') diff --git a/lib/debug.py b/lib/debug.py index aae9ae81..edf55bcc 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -96,9 +96,9 @@ class Debug(object): # Inkscape from the PyCharm Terminal pane, you can do: # export PYCHARM_REMOTE_DEBUG=true;inkscape # - # 6. Either click on the green "bug" icon or press Ctrl-D to start debugging. - # The PyCharm debugger pane will display the message "Waiting for process - # connection..." + # 6. In Pycharm, either click on the green "bug" icon if visible in the upper + # right or press Ctrl-D to start debugging.The PyCharm debugger pane will + # display the message "Waiting for process connection..." # # 7. Do some action in Inkscape which invokes Ink/Stitch extension code, and the # debugger will be triggered. If you've left "Suspend after connect" checked -- cgit v1.2.3 From 9ba194124c0b33676b0f3af51f203c1787d33b06 Mon Sep 17 00:00:00 2001 From: Rick Levine Date: Thu, 16 Feb 2023 08:30:04 -0800 Subject: Punting --- lib/debug.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/debug.py') diff --git a/lib/debug.py b/lib/debug.py index edf55bcc..0d6af104 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -106,9 +106,6 @@ class Debug(object): # PyDev debugger.)" statement, below. Uncheck the box to have it continue # automatically to your first set breakpoint. - # Thanks to lexelby for the hints needed to puzzle this out. - - try: if 'PYCHARM_REMOTE_DEBUG' in os.environ: import pydevd_pycharm -- cgit v1.2.3