Home » Support » Index of All Documentation » How-Tos » How-Tos for Web Development »

Wing IDE is an integrated development environment that can be used to write, test, and debug Python code that is written for the Google App Engine. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code. Since Google App Engine will reload your code when you save it to disk, you can achieve a very fast edit/debug cycle without restarting the debug process.

For more information on Wing IDE see the product overview. If you do not already have Wing IDE installed, download a free trial now. To get started using Wing, refer to the tutorial in the Help menu in Wing and/or the Wing IDE Quickstart Guide.

Creating a Project

Before trying to configure a Wing IDE project, first install and set up Google App Engine and verify that it is working by starting it outside of Wing IDE and testing it with a web browser. It is also a good idea to install App Engine upgrades at this time, before doing anything else.

Then create a project in Wing using New Project in the Project menu and selecting Google App Engine as the project type. Then use Add Directory in the Project menu to add your source directories to the project. You should also add at least dev_appserver.py, which is located in the top level of the Google SDK directory.

Next open up dev_appserver.py in Wing's editor and select Set Current as Main Debug File in the Debug menu. This tells Wing to use this file as the main entry point, which is then highlighted in red in the Project tool. If a main debug file is already defined the Debug menu item will be Clear Main Debug File instead.

Next you need to go into Project Properties and set Debug/Execute > Debug Child Processes to Always Debug Child Processes. This is needed because App Engine creates more than one process.

Finally, save your project with Save Project in the Project menu. Store the project at or near the top level of your source tree.

Configuring the Debugger

Before trying to debug make sure you stop Google App Engine if it is running already outside of Wing IDE.

You can debug code running under Google App Engine by selecting Start / Continue from the Debug menu (or using the green run icon in the toolbar). This will bring up a dialog that contains a Run Arguments field that must be altered to specify the application to run. For example, to run the guestbook demo that comes with the SDK, the run arguments would be "${GOOGLE_APPENGINE_DIR}/demos/guestbook" where ${GOOGLE_APPENGINE_DIR} is replaced by the full pathname of the directory the SDK is installed in. The quotation marks are needed if the pathname contains a space. In other apps, this is the directory path to where the app.yaml file is located. If this path name is incorrect, you will get an error when you start debugging.

You can also leave the environment reference ${GOOGLE_APPENGINE_DIR} in the path and define an environment variable under the Environment tab of the Debug dialog. Or use ${WING:PROJECT_DIR} instead to base the path on the directory where the project file is located.

Add a --port=8082 style argument if you wish to change the port number that Google App Engine is using when run from Wing's debugger. Otherwise the default of 8080 will be used.

Using a partial path for the application may also be possible if the Initial Directory is also set in under the Debug tab.

Next, click the OK button to start debugging. Once the debugger is started, the Debug I/O tool (accessed from the Tools menu) should display output from App Engine, and this should include a message indicating the hostname and port at which App Engine is taking requests. Requests may be made with a web browser using that URL. If Google App Engine asks to check for updates at startup, it will do so in the Debug I/O tool and you can press "y" or "n" and then Enter as you would on the command line. Or send the --skip_sdk_update_check argument on the command line to dev_appserver.py to disable this.

Using the Debugger

After you have configured the debugger, set a break point in any Python code that is executed by a request and load the page in the browser. For example, to break when the main page of the guestbook demo is generated, set a breakpoint in the method Mainpage.get in guestbook.py. When you reach the breakpoint, the browser will sit and wait while Wing displays a red run marker on code at the breakpoint and other lines as you step through code using the buttons in Wing IDE's toolbar.

Check out the Stack Data and Watch tools in the Tools menu to inspect debug data, or just use the Debug Probe, which is an interactive Python shell that works in the context of the current debug stack frame. When the debug process is paused, both the Debug Probe and editor show auto-completion and call tips based on live runtime state, making it quick and easy to write and try out new code. You can also see data values by hovering the mouse over symbols in the editor or Debug Probe and you can press F4 to go to the point of definition.

Continuing with the green run button in the toolbar will complete the page load in the browser, unless a breakpoint or exception is reached first.

To set up multiple entry points, use Named Entry Points in the Debug menu. These can contain different commands lines and environment for dev_appserver.py.

You may edit the Python code for an application while the App Engine is running, and then reload in your browser to see the result of any changes made. In most cases, there is no need to restart the debug process after edits are made. However, if you try the browser reload too quickly, while App Engine is still restarting, then it may not respond or breakpoints may be missed.

To learn more about the debugger, try the Tutorial in Wing's Help menu.

Improving Auto-Completion and Goto-Definition

Wing can't parse the sys.path hackery in more recent versions of Google App Engine so it may fail to find some modules for auto-completion, goto-definition and other features. To work around this, set a breakpoint in _run_file in dev_appserver.py and start debugging. Then, after script_name has been set, in the Debug Probe tool (in Wing Pro only) type the following:

os.pathsep.join(_PATHS.script_paths(script_name))

Copy this to the clipboard and open up the file properties for dev_appserver.py by right-clicking on the file. Then, in Project Properties under the Environment tab select Custom for the Python Path, click on the View as Text button and paste in the extra path.

You will need to redo this if you move the app engine installation, or you can use ${WING:PROJECT_DIR} to convert those paths to base on the location of the project file.

If you use more than one app within your project with multiple Named Entry Points, you'll want to set this Python Path into the Named Entry Points's Launch Configuration environment instead of placing it in Project Properties.

Trouble-shooting

App Engine runs code in a secure environment that prevents access to some system information, including process ID. This causes some of the sub-processes created by App Engine to be shown with process id -1. In this case they are not listed as children of the parent process and you will need to kill both processes, one at a time, from the toolbar or Debug menu.

Windows users may need to set the TZ environment variable to UTC via the environment field in Project Properties to work around problems with setting os.environ['TZ'] while a process is running (this is a Windows runtime bug). One possible symptom of this is repeated 302 redirects that prevent logging in or other use of the site.

The Debugger > Exceptions > Report Exceptions preference should be set to When Printed (the default) when working with Google App Engine or Wing will report some additional exceptions that are handled internally when running Google App Engine outside of the debugger.

If you have unchecked the "Show this dialog before each run" checkbox in the debug dialog shown when launching dev_appserver.py and need to alter the command line arguments or other values there, you can access the dialog by right clicking on dev_appserver.py in the editor or Project and selecting Properties.

Related Documents

Wing IDE provides many other options and tools. For more information:

« 2.6. Using Wing IDE with TurbogearsTable of Contents2.8. Using Wing IDE with mod_wsgi »

Using Wing IDE with Google App Engine