A good development environment setup for Web2Py

joeriks picture joeriks · Nov 2, 2010 · Viewed 11k times · Source

Have been trying out Web2Py for a couple of days now and I decided it to be a keeper. But there is one thing that concerns me a lot and that might be a showstopper in the end. I need a nice development environment & setup I can trust and be productive with. Coming from the MS Visual Studio world I'm looking for something with good autocomplete / intellisense + functions for versioning and deployment.

I did some attempts to edit my code in Eclipse but it needs additional setup to run with autocomplete, and for debugging I dont know if it's possible. (Noticed there was a Django project template in Eclipse which is a bit tempting I must say.)

Wing Ide has a instruction on how to get web2py up and running and I am up to testing that one. Not free, but very cheap compared to much in the Windows world.

I also want a good versioning (hg) setup, and preferably a semi-automatic FTP-deployment-method.

What IDE do Web2Py developers use, and how do your setup look like?

A complete setup script for a project in a good IDE would be awesome! (Just like the installation is, one click to get it running 100%).

Pycharm looks good, perhaps that one can add web2py support http://youtrack.jetbrains.net/issue/PY-1648

Thanks a lot!

Answer

mwolfe02 picture mwolfe02 · Nov 2, 2010

Scripts

Once I create a new project in web2py I add a few scripts to my main app folder:

web2py\applications\myapp\DebugWinpdb.bat:

C:\Python25\Scripts\winpdb.bat ..\..\web2py.py -i 127.0.0.1 -p8000 -mypassword

web2py\applications\myapp\DebugShell.bat:

C:\Python25\Scripts\winpdb.bat ..\..\web2py.py -S myapp -M

web2py\applications\myapp\Shell.bat:

python ..\..\web2py.py -S myapp -M

IDE

As others have stated you need to do some extra stuff to get autocomplete/intellisense for web2py no matter what IDE you use.

For me NetBeans was a good compromise between does-everything-if-only-you-can-figure-out-how (Eclipse/PyDev) and does-the-basics-but-few-extras (PyScripter).

NetBeans Setup (Project Properties):

  • Python Category
    • Python Platform: Python 2.x (default is Jython)
  • Run Category
    • Main Module: web2py.py
    • Application Arguments: -i 127.0.0.1 -p 8000 -a mypassword

NetBeans Pros:

  • Tight Mercurial integration
    • Highlights which lines have been added, changed, or deleted in your source file as you edit it
    • Selective rollback of individual changes you've made since your last commit
    • One of the nicest visual diff viewers I have used
  • Python PEP8 style hints (fully customizable)
    • Name "foo" is not a valid class name according to your code style (CapitalizedWords)
    • Name "Bar" is not a valid function name according to your code style (lowercase_with_underscores)
    • Auto-format hotkey (corrects spacing around operators, etc)
  • Navigation within source file
    • semantically indexes current source file
    • organizes alphabetically by type (Class, method, attribute, etc)
    • makes even enormous style sheets manageable

NetBeans Cons:

  • Integrated Debugger doesn't work with web2py (that one really hurts)
  • Long startup time (but acceptably snappy for me once up and running)

Version Control

I use and highly recommend Mercurial for source control. As mentioned earlier, NetBeans has great support for Mercurial but there are some things I'd just rather do in TortoiseHg.

TortoiseHg Pros:

  • Shell overlay icons
  • Repository Explorer
    • view repos history with graphical display of branching/merging
    • one stop shop for Incoming, Outgoing, Push, Pull, Update, etc with button for Commit tool
  • Commit tool
    • Hunk Selection: cherry pick changes from within a file for more focused Commits
    • Add, Remove, Diff, Revert, Move, Remove, Forget

TortoiseHg Cons:

  • No easy way to drop directly into a command line
  • Bug that regularly prevents files from being removed during commit (waits indef for a lock to be released; running hg addremove from command line is a reliable workaround)

Publishing

I use a combination of WinSCP (for browsing), PuTTY (for terminal commands), and TortoiseHg (for push/pull of my repos) to work with my shared hosting account on Webfaction.

The first thing I do is set up public/private key encryption. If you are having trouble getting this set up between Windows and Linux, try these instructions from Andre Molnar. Short story is you need to generate your private key using ssh-keygen on Linux, copy it down to your Windows machine using WinSCP, then convert it for use with WinSCP and PuTTY.

Then add the following lines to your global mercurial.ini file:

[ui]
ssh = "C:\Program Files\TortoiseHg\TortoisePlink.exe" -ssh -2 -i "c:\path\to\your\privatekey.ppk"

Even if you have to connect to multiple servers, you need only copy your public key to each of the different servers. You'll also want to let WinSCP and PuTTY know where your private key is located, but those are fairly easy to figure out.