This gist aims to show how to configure debug for VScode and python development on the Google App Engine Standard Environment. This tutorial is based on this article, with some additional information that didn't seem much clear for me.
Step 1: Open the application directory in VSCode.
Step 2: Download the latest version of ptvsd
module here. Copy it to your working directory, extract it, than enter the extracted folder (the one that contains setup.py
) and copy the ptvsd
folder to your root project (where app.yaml
resides).
Step 3: Create a tasks.json
file with the VSCode command. Press CTRL+SHIFT+B
to "Run build task". As no task is configured it will create one from a template which you will have to choose. Once created, place the following content into taksks.json
:
Don't forget to change the path to
dev_appserver.py
{
"version": "0.1.0",
"command": "python",
"isShellCommand": true,
"showOutput": "always",
"args": [
"<PATH-TO>/dev_appserver.py",
"--python_startup_script=${workspaceRoot}/pydev_startup.py",
"--automatic_restart=no",
"--max_module_instances=default:1",
"${workspaceRoot}/app.yaml"
]
}
Step 3: Create a file named pydev_startup.py
with the following contents in the root directory of your application:
import sys
import os
#Assuming that pdvsd is located in the working folder
sys.path.append(os.getcwd())
from .ptvsd import enable_attach
#Fee free to change the secret and port number
enable_attach(secret = 'gae', address = ('0.0.0.0', 3000))
#The debug server has started and you can now use VS Code to attach to the application for debugging
print("Google App Engine has started, ready to attach the debugger")
Step 4: Create a debug configuration with the following entry (in launch.json
)
{
"name": "Google AppEngine Debug Attach",
"type": "python",
"request": "attach",
"host": "localhost",
"secret": "gae",
"port": 3000,
"remoteRoot": "${workspaceRoot}",
"localRoot": "${workspaceRoot}",
"preLaunchTask": "python"
}
Step 5: Start the task created earlier using the command CTRL+SHIFT+B
(or use Command ‘Run Build Task’ from the Command Palette).
Step 6: This will now open up the Tasks output window and will display information such as the following:
INFO 2016-07-27 05:29:01,672 sdk_update_checker.py:229] Checking for updates to the SDK.
Step 7: Wait until you see the message Google App Engine has started, ready to attach the debugger displaed, as follows:
INFO 2016-07-27 05:29:01,672 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO 2016-07-27 05:29:02,664 api_server.py:205] Starting API server at: http://localhost:52245
INFO 2016-07-27 05:29:02,668 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2016-07-27 05:29:02,671 admin_server.py:116] Starting admin server at: http://localhost:8000
Google App Engine has started, ready to attach the debugger
Step 8: Finally, go into the debug configuration and select the Google AppEngine Debug Attach
option, and run it.
Does this still work? I can't get it to run the pydev_startup:
{
"version": "0.1.0",
"command": "python",
"isShellCommand": true,
"showOutput": "always",
"args": [
"//dev_appserver.py",
"--python_startup_script=${workspaceRoot}/pydev_startup.py",
"--automatic_restart=yes",
"--max_module_instances=default:1",
"--port=5001",
"--host=localhost",
"${workspaceRoot}/app.yaml"
]
}
Does this look right?