Ghostwriter
Ghostwriter copied to clipboard
Development Setup/Documentation
Hi guys,
I really like Ghotswriter and the fact that you are sharing such a helpful tool with the community. Looking into what ended up being a trivial bug (#100), got me wondering how one could debug GW. From the .vscode folder I concluded that you apparently already use VSCode. I dug up a useful article on setting up remote debugging with a dockerized Django app in VSCode.
Unfortunately this requires changes that will be overridden the next time I pull the main branch:
- adding ptvsd as a new (development time) dependency in
requirements/local.txt
- modifying
manage.py
to start the debugger - modifying
local.yml
to expose the debugger port
I also found that there are at least two django-wrappers for ptvsd that may or may not be worth looking into.
I believe adding the documentation and code allowing your users to debug GW (in a dev configuration) will reduce the barrier of entry for users like myself, who are somewhat familiar with python, but not VSCode or remote debugging/docker/thelot.
As with issue #100 this might result in shorter time from issue to fix.
Anyway leaving this here for others to find and in the hope it might benefit them:
VSCode launch config (.vscode/lauch.json):
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Django",
"type": "python",
"request": "attach",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"port": 3000,
"host": "127.0.0.1",
}
]
}
Update to reqiuirements/local.txt:
ptvsd==4.3.2 # https://github.com/microsoft/ptvsd
Updated to manaye.py :
...
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
# start new section
from django.conf import settings
if settings.DEBUG:
if os.environ.get('RUN_MAIN') or os.environ.get('WERKZEUG_RUN_MAIN'):
import ptvsd
ptvsd.enable_attach(address=('0.0.0.0', 3000))
print('Attached!')
# end new section
try:
from django.core.management import execute_from_command_line
...
Update to local.yml (notice the 3000:3000 port mapping):
services:
django: &django
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: ghostwriter_local_django
depends_on:
- postgres
volumes:
- .:/app
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
- "3000:3000"
This all sounds very cool, @er4z0r. Thanks for taking the time to write it up! Being able to set a breakpoint and debug a specific thing within the container should be very useful.