Using Wing IDE with Google App Engine


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.

Version Compatibility

The instructions here work with Google App Engine version 1.7 or with old_dev_appserver.py under version 1.8+. Changes in the default dev_appserver.py in version 1.8 have broken debugging with Wing. We are looking into fixing this using startup scripts to preload the debugger before sandboxing is initiated. For now, we recommend using old_dev_appsever.py when debugging.

Configuring the Environment

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.

Next create a project in Wing using New Project in the Project menu and use Add Directory in the Project menu to add your source directories to the project. This must include dev_appserver.py, which is located in the top level of the Google SDK directory.

Then 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 when you start debugging, and it also helps Wing infer your Python Path and other settings. The main debug file is 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.

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

Using Django

If you are using the Django via the app-engine-patch project, you need to use manage.py as your main debug file instead of dev_appserver.py and should follow the Manual Configuration instructions in the Django How-To (except that the --noreload option is not supported).

Debugging Your Application

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 AppConfigNotFoundError exception 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.

To try out 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 interctive 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.

Continuing with the green run button in the toolbar will complete the page load in the browser, unless some other breakpoints or an exception are reached first.

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 start the debug process after edits are made.

Configuration Details

Windows users will want 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.

If you need to send command line arguments to app engine (for example, to change the port it listens on), these should be added to Run Arguments under the Debug tab of File Properties for dev_appserver.py. You can access this dialog by right clicking on the editor and selecting Properties.

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.

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 fix_sys_path in dev_appserver.py and start debugging. Then, in the Debug Probe tool (in Wing Pro only) type the following:

os.pathsep.join(EXTRA_PATHS)

Copy this to the clipboard and open up the file properties for dev_appserver.py by right-clicking on the file. Then, 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.

Improving Responsiveness when Setting Breakpoints or Pausing

Out of the box, earlier versions of Google App Engine would sit in a select call for up to thirty seconds when it has nothing to do. This results in delays in setting breakpoints or pausing the debug process. To speed this up, go into tools/dev_appserver.py and change DEFAULT_SELECT_DELAY to a shorter value, such as 1.0. This is longer needed in newer versions of Google App Engine.

Related Documents

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

« 2.0. Using Wing IDE with DjangoTable of Contents2.2. Using Wing IDE with Pyramid »