Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,3 @@ cython_debug/

# PyPI configuration file
.pypirc

# VS Code settings
.vscode/launch.json
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
// To use this configuration, add `debugpy.listen(("localhost", 5678))` to the script you wish to debug
"name": "Attach to Streamlit at localhost:5678",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"justMyCode": false
}
]
}
23 changes: 19 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ start docs\_build\index.html

# Debugging on the streamlit side

Debugging the measurement script can be done using standard Python debugging techniques. However, debugging the Streamlit script—or any code invoked by the Streamlit script—is more complex because it runs in a separate process launched by the PythonPanelServer. To debug the Streamlit script, you can use debugpy to attach the Visual Studio Code debugger as follows:
Debugging the measurement script can be done using standard Python debugging
techniques. However, debugging the Streamlit script—or any code invoked by the
Streamlit script—is more complex because it runs in a separate process launched
by the PythonPanelServer. To debug the Streamlit script, you can use debugpy to
attach the Visual Studio Code debugger as follows:

## Instrument Streamlit script to debug

Expand All @@ -73,9 +77,15 @@ except RuntimeError as e:
raise
```

The `debugpy.listen()` function opens a port that allows the debugger to attach to the running process. You can specify any available port, as long as it matches the port configured in the launch.json file shown below. Since calling listen() more than once will raise an exception, it is wrapped in a try block to prevent the script from crashing if it is rerun.
The `debugpy.listen()` function opens a port that allows the debugger to attach
to the running process. You can specify any available port, as long as it
matches the port configured in the launch.json file shown below. Since calling
listen() more than once will raise an exception, it is wrapped in a try block to
prevent the script from crashing if it is rerun.

The `debugpy.wait_for_client()` function pauses script execution until the debugger is attached. This is helpful if you need to debug initialization code, but you can omit this line if it is not required.
The `debugpy.wait_for_client()` function pauses script execution until the
debugger is attached. This is helpful if you need to debug initialization code,
but you can omit this line if it is not required.

The `import debugpy` statement includes a type suppression comment to satisfy mypy.

Expand All @@ -96,7 +106,12 @@ You will also need this configuration in your launch.json:
}
```

After running your measurement script and allowing the PythonPanelServer to launch Streamlit with your Streamlit script, you can attach the debugger by clicking the **Attach to Streamlit at localhost:5678** button in the VS Code **Run and Debug** tab. Once attached, you can set breakpoints and use all standard debugging features in your Streamlit script, as well as in any nipanel code invoked by the Streamlit script.
After running your measurement script and allowing the PythonPanelServer to
launch Streamlit with your Streamlit script, you can attach the debugger by
clicking the **Attach to Streamlit at localhost:5678** button in the VS Code
**Run and Debug** tab. Once attached, you can set breakpoints and use all
standard debugging features in your Streamlit script, as well as in any nipanel
code invoked by the Streamlit script.

# Developer Certificate of Origin (DCO)

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ni-measurement-plugin-sdk = {version=">=2.3"}
typing-extensions = ">=4.13.2"
streamlit = ">=1.24"
nitypes = {version=">=0.1.0dev1", allow-prereleases=true}
debugpy = "^1.8.1"
debugpy = ">=1.8.1"

[tool.poetry.group.dev.dependencies]
types-grpcio = ">=1.0"
Expand Down