@luan.tm
I have done some experimentation and you can use the VS Code Debug mode and breakpoints with the following configuration.
However, you will need to disable the caching to hit the breakpoint for some parts of the code.
1. Override the Container Command
First, override the command and the ports fields in the docker-compose file for the service you would like to test.
You can use the docker-compose.override.yml
file to achieve this, it is located at "$(tutor config printroot)/env/dev/docker-compose.override.yml"
.
The command should be replaced with the following:
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 ./manage.py lms runserver 0.0.0.0:8000"]
The 5678 port is the debugging port and 8000 port is the default lms port. You should also replace lms with cms if you are testing the cms.
I am using debugpy
as it is the default suggestion from VS Code.
The ports should be replaced with the following:
ports:
- "8000:8000"
- "5678:5678"
It will look something like this in the end:
lms:
volumes:
- "{REMOVED}/tutor/volumes/edx-platform:/openedx/edx-platform"
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 ./manage.py lms runserver 0.0.0.0:8000 --nothreading"]
ports:
- "8000:8000"
- "5678:5678"
2. Configure VS Code
You should create a launch.json
file under the .vscode
folder in your workspace root. I have the following structure, you should adjust the following configuration accordingly if you have a different structure.
- root -
${workspaceFolder}
- /tutor -
$(tutor config printroot)
- /tutor-plugins
You can use the following configuration, however, you should change the port and the localRoot if you have changed the default for any of those.
{
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/tutor/volumes/edx-platform",
"remoteRoot": "/openedx/edx-platform"
}
]
}
]
}
3. Start Developing
You can use the familiar tutor dev start -d lms
and tutor dev stop lms
.
The LMS will not launch until the debugger is attached.
Everything above applied to CMS as well, just change lms with cms.
References