Skip to content
Open
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
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,83 @@ Any `yunohost` command will run from the code of the git clone.

The `use-git` action can be used for any package among `yunohost`, `yunohost-admin`, `moulinette` and `ssowat` with similar consequences.

### 4. Run with a graphical debugger

You can pilote your code with a graphical debugger like the one inside vscodium or with vimspector.

You have to run your `yunohost` command prefixed by `./ynh-dev debug `, for example:
```
./ynh-dev debug yunohost user list
```
The command will be suspended until a graphical debugger attach this process through the port 5678.

#### With vim
1. Setup vimspector in your .vimrc, for example with Vundle:
```
Bundle 'puremourning/vimspector'

let g:vimspector_enable_mappings = 'HUMAN'
"packadd! vimspector
let g:vimspector_install_gadgets = [ 'debugpy']
```
2. Run vim, and install vimspector and debugpy gadget
```
:PluginInstall
:VimspectorInstall
```
3. Configure a `.vimspector.json` at the root of your project:
```
{
"configurations": {
"run": {
"adapter": "multi-session",
"filetypes": [ "python" ], // optional
"configuration": {
"request": "attach",
"pathMappings": [
{"localRoot": "~/PATH_TO_YOUR_CODE/ynh-dev/yunohost/src/", "remoteRoot": "/usr/lib/python3/dist-packages/yunohost/"}
],
"justMyCode": false
}
}
}
}
```
4. Reopen vim, set some breakpoints with F9 and start with F5

#### With vscodium
Note: the workspace needs to be a trusted workspace, if you don't trust a big repo like yunohost, you can still copy src python directory into a trusted workspace...

1. Install python extension in vscodium
2. Setup a launch.json at the root of your workspace
```
{
// Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
// Pointez pour afficher la description des attributs existants.
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Remote Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "IP_OF_YOUR_INCUS",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/src/",
"remoteRoot": "/usr/lib/python3/dist-packages/yunohost/"
}
],
"justMyCode": false
}
]
}
```
3. Set some breakpoint and click on `Execute and debug` or F5

## Further Resources

- [yunohost.org/dev](https://yunohost.org/dev)
11 changes: 11 additions & 0 deletions ynh-dev
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function show_usage() {
test [PKG] Deploy, update and run tests for some packages
Tests for single modules and functions can ran with
e.g. ./ynh-dev test yunohost/appurl:urlavailable
debug YNH_COMMAND Allow to attach a graphical debugger like vscodium or vimspector on 5678 port
e.g. ./ynh-dev debug yunohost user list
dev Watch python files and restart yunohost-api and yunohost-portal-api when changes occur
catalog
build Rebuild the custom catalog
Expand Down Expand Up @@ -56,6 +58,7 @@ function main()
dev|--dev) dev "${ARGUMENTS[@]}" ;;
lint|--lint) run_linters "${ARGUMENTS[@]}" ;;
test|--test) run_tests "${ARGUMENTS[@]}" ;;
debug|--debug) run_debug "${ARGUMENTS[@]}" ;;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
debug|--debug) run_debug "${ARGUMENTS[@]}" ;;
debug|--debug) run_debug "${ARGUMENTS[@]}" ;;


catalog|--catalog) catalog "${ARGUMENTS[@]}" ;;

Expand Down Expand Up @@ -574,6 +577,14 @@ function run_tests()
esac
done
}
function run_debug() {
if ! dpkg -l |grep python3-debugpy > /dev/null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ! dpkg -l |grep python3-debugpy > /dev/null
if ! dpkg -l | grep -q python3-debugpy

then
apt install -y python3-debugpy
fi
yunohost firewall allow Both 5678 -4 > /dev/null 2> /dev/null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
yunohost firewall allow Both 5678 -4 > /dev/null 2> /dev/null
yunohost firewall allow Both 5678 -4 &> /dev/null

BTW, what are the reasons for also hiding errors?

python3 -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5678 --wait-for-client "/usr/bin/$@"
}

function catalog()
{
Expand Down