Wingware Python IDE

The Intelligent Development Environment for Python Programmers

Wing IDE is an integrated development environment that can be used to write,
test, and debug Python code and HTML templates that are written for web2py,
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.

Introduction

Wing IDE allows you to debug Python code and templates running under web2py 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 web2py server is run from within Wing, as opposed to
attaching to a remote process.

Setting up a Project

Download and install web2py. On some OSes you can use the regular install,
but at least on Windows you need to use the web2py sources instead because
the regular install is missing modules necessary for debugging. When the sources
are being used, you will also need to install Python if you don't already
have it.

Then launch Wing and create a new project from the Project menu. Select
web2py as your project type, and point the PythonExecutable at the Python
executable (python or python.exe) used for web2py. Click OK and then
save the project (for example, as web2py.wpr within the web2py directory).

Next add the web2py directory to your project by going to the Project view,
right clicking, and selecting AddDirectory. After the project view
populates, find and right click on the file web2py.py and select SetAsMainDebugFile.

On Windows, if you are working from sources, you may also need to install
pywin32

Debugging

You can now debug web2py by clicking on the green Debug icon in Wing's
toolbar and waiting for the web2py console to appear. Enter a password and start
the server as usual.

Once web2py is running, open a file in Wing that you know will be reached when
you load a page of your web2py application in your web browser. Place a
breakpoint in the code and load the page in your web browser. Wing should stop
at the breakpoint. Use the StackData tool or DebugProbe (in Wing
Pro) to look around.

An example is to set a breakpoint in applications/welcome/views/default/index.html,
which is loaded when you go to the URL http://127.0.0.1:8000/welcome/default/index
(assuming local web2py install running on port 8000).

Notice that breakpoints work both in Python code and HTML template files.

Wing's DebugProbe (in the Tools menu) is similar to running a shell
from web2py (with pythonweb2py.py-SmyApp-M) but additionally includes
your entire context and provides auto-completion. You can easily inspect or
modify variables, manually make function calls, and continue debugging from your
current context.

Setting Run Arguments

When you start debugging, Wing will show the FileProperties for web2py.py.
This includes a RunArguments field under the Debug tab where you can
add any web2py option. For example, adding -a'<recycle>' will give you
somewhat faster web2py startup since it avoids showing the Tk dialogs and
automatically opening a browser window. This is handy once you already have a
target page in your browser. Run pythonweb2py.py--help for a list of all
the available options.

To avoid seeing the FileProperties dialog each time you debug, un-check the
"Show this dialog before each run" check box. You can access it subsequently
with the CurrentFileProperties item in the Source menu or by right
clicking on the editor and selecting Properties.

Hung Cron Processes

Web2py may spawn cron sub-processes that fail to terminate on some OSes when
web2py is debugged from Wing IDE. This can lead to unresponsiveness of the debug
process until those sub-processes are killed. To avoid this, add the parameter
-N to prevent the cron processes from being spawned.

Better Static Auto-completion

Working in your code when the debugger is not runnng by default misses some
auto-completion options because of how web2py works. For example, auto-completion
after typing db. will fail because db is not explicitly defined. To
fix this, you can add some hints for Wing as follows at the top of the file:

Then go into Projectproperties in the Project menu and add the
following path under PythonPath:

/path/to/web2py/applications/examples/models

Replace /path/to according to where you unpacked web2py. This path may
vary depending on which app you are working with.

Now, typing db. should bring up an auto-completer with the contents
of db even if the debugger is not running.

Exception Reporting in Old Web2Py Versions

This section is only relevant if you are using a very old web2py, before
version 1.62 .

As shipped, web2py version 1.61 and earlier contain a catch-all exception
handler to report unexpected errors in your web browser as tickets. This is
useful when tracking problems on a live site.

To make debugging more convenient, change the exceptException,exception
clause in the definition of restricted at the end of the file
src/gluon/restricted.py in your web2py installation to read as follows: