Wing IDE is an integrated development environment that can be used to write, test, and debug Python code that is written for Webware, an open source web development framework. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code.
To get started using Wing, refer to the tutorial in the Help menu in Wing and/or the Wing IDE Quickstart Guide.
Wing IDE allows you to graphically debug a Webware application as you interact with it from your web browser. Breakpoints set in your code from the IDE will be reached, allowing inspection of your running code's local and global variables with Wing's various debugging tools. In addition, in Wing IDE Pro, the Debug Probe tab allows you to interactively execute methods on objects and get values of variables that are available in the context of the running web app.
There is more than one way to do this, but in this document we focus on an "in process" method where the Webware server is run from within Wing as opposed to attaching to a remote process. The technique described below was tested with Webware 0.9 and Python 2.4 on CentOS Linux. It should work with other versions and on other OSes as well. Your choice of browser should have no impact on this technique.
Setting up a Project
Though Wing supports the notion of "Projects" for organizing one's work for this debugging scenario you can use the Default Project and simply add your source code directory to it by using Add Directory from the Project menu.
You will also need to specify a Python Path in your Project Properties with something like following (your actual paths depend on your installation of Webware and OS):
Note that on Windows, the path separator should be ';' (semicolon) instead. The Webware MakeAppDir.py script creates a default directory structure and this example assumes that the source code is nested within this directory.
To debug your Webware app you'll actually be running the DebugAppServer and not the regular AppServer, so you'll need to bring in the Debug AppServer and a couple of other files with these steps:
- Copy the DebugAppServer.py, ThreadedAppServer.py, and Launch.py from the WebKit directory and put them in the root of the directory that MakeAppDir.py created.
- Right click on Launch.py in Wing's editor and select the menu choice File Properties. Click the Debug tab and enter DebugAppServer.py in the Run Arguments field. If you're using the default project then leave the initial directory and build command settings as they are.
- If you need to modify the version of Python you're running, you can change the Python Executable on the Environment tab of this debug properties window, or project-wide from the Project Properties.
- Optionally, after adding Launch.py to the project, use the Set Main Debug File item in the Debug menu to cause Wing to always launch this file when debug is started, regardless of which file is current in the editor.
To debug, press the green Debug icon in the toolbar. If you did not set a main debug file in the previous section, you must do this when Launch.py is the current file.
The file properties dialog will appear. Optionally, deselect Show this dialog before each run. If you do this you can access the dialog again later by right clicking on the file in Wing's editor and selecting Properties.
Click OK to start the debug process. The Debug I/O tool will show output from the Webware process as it starts up. What you will see there depends upon your Webware application and server settings, but you should see some log messages scroll by. If there is a path or other kind of problem as the debugging process proceeds errors will display in the Debug I/O tool or in a pop-up error message in Wing if you have a missing library or run into another unhandled exception.
Once the process has started up, you will be able to access web pages from your browser according to your configuration of Webware, just as you would when running the server outside of Wing.
Now for the fun part -- fire up your browser and go to the home page of your application. Go into the source file for any Python servlet in Wing and set a breakpoint somewhere in the code path that you know will be executed when a given page is requested. Navigate to that page in your browser and you should see the Wing program icon in your OS task bar begin to flash. (You'll see that the web page won't finish loading -- this is because the debugger has control now; the page will finish loading when you continue running your app by pressing the Debug icon in the toolbar).
Now you can make use of all of the powerful debugging functionality available in Wing instead of sprinkling your code with print statements.
Wing IDE provides many other options and tools. For more information:
|« 2.10. Using Wing IDE with Paste and Pylons||Table of Contents||2.12. Debugging Web CGIs with Wing IDE »|