Skip to content

Commit

Permalink
update debug instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Nov 6, 2023
1 parent 1cd336e commit 4b7483f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ Though it is not required, we recommend installing these plugins from the QGIS P

#### Visual Studio Code

First, you'll need to uncomment these 2 lines in the `__init__.py` file:
First, you'll need to change the _debug value to True in `plugin_utils/installer.py` file and verify the VS Code Python extension path:

```python
# from speckle.utils import enable_remote_debugging
# enable_remote_debugging()
_debug = True
_vs_code_directory = os.path.expanduser("~\.vscode\extensions\ms-python.python-2023.20.0\pythonFiles\lib\python")
```

This will automatically setup `ptvsd` if it's not already installed, and start listening to port `5678`.
This will automatically setup `debugpy` if it's not already installed, and start listening to port `5678`.

In VS Code, you can use the built in python debugger. You'll need to create a debug configuration by creating a `launch.json` file.

Expand Down Expand Up @@ -199,10 +199,5 @@ That's all there is to it! Now any breakpoints you create should be hit.

![successful debugging in vs code](https://user-images.githubusercontent.com/7717434/129324011-42ebd156-ba6b-4eca-8b67-22300eb462fc.png)

> If you want to have the debugger wait for you to connect using VSCode, you can uncomment this line in the `speckle/utils.py` file:
>
> ```python
> #ptvsd.wait_for_attach()
> ```

Enjoy!
33 changes: 29 additions & 4 deletions plugin_utils/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

_user_data_env_var = "SPECKLE_USERDATA_PATH"
_debug = False
_vs_code_directory = os.path.expanduser(
"~\.vscode\extensions\ms-python.python-2023.20.0\pythonFiles\lib\python"
)


def _path() -> Optional[Path]:
Expand Down Expand Up @@ -160,6 +163,31 @@ def install_requirements(host_application: str) -> None:
# dependencies
requirements = get_requirements_path().read_text().replace("\n", "")
path = str(connector_installation_path(host_application))

print(f"Installing debugpy to {path}")
from subprocess import run

if _debug is True:
try:
import debugpy
except:
completed_process = run(
[
PYTHON_PATH,
"-m",
"pip",
"install",
"-t",
str(path),
"debugpy==1.8.0",
],
capture_output=True,
text=True,
)
if completed_process.returncode != 0:
m = f"Failed to install debugpy through pip. Disable debug mode or install debugpy manually. Full log: {completed_process}"
raise Exception(completed_process)

if _dependencies_installed(requirements, path):
return

Expand Down Expand Up @@ -240,10 +268,7 @@ def startDegugger() -> None:
import debugpy
import shutil

directory = os.path.expanduser(
"~\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python"
)
sys.path.append(directory)
sys.path.append(_vs_code_directory)
debugpy.configure(python=shutil.which("python"))

try:
Expand Down

0 comments on commit 4b7483f

Please sign in to comment.