wiki:Dev/Tools

Version 20 (modified by dmartinc, 3 years ago) (diff)

Added more info about debugging interactive console

Development Tools

IDEs

Most people in the Indico team use Eclipse/PyDev. There's also a small Emacs community.

Eclipse + PyDev

Installation and setup

  1. Download Eclipse (JEE is the best option because it comes with Web Tools): http://www.eclipse.org/downloads/ (as of January 2010, Ubuntu 9.10 Synaptic Package Manager's eclipse package does not come with Web Tools).
  2. Install PyDev by adding the URL http://pydev.org/updates in Eclipse>Help>Install New Software: link 'Available Software Sites' and Add... (!Pydev extensions are included into !Pydev since version 1.5). Note: if you are having problems under Ubuntu 9.10, such as some Eclipse buttons seeming unresponsive, or the PyDev packages not appearing after you add the pydev.org/updates site, check: http://mou.me.uk/2009/10/31/fixing-eclipse-in-ubuntu-9-10-karmic-koala/ )
  3. Check the boxes for PyDev and next, next, next,....
  4. Open PyDev perspective by clicking on Window>Open perspective>Other... and selecting PyDev.
  5. Go to window>preferences and:
    1. go to PyDev options> Interpreter - Python > New... (interpreter) and locate/choose your python.exe or python (linux).
    2. change default encoding: go to General>Workspace> Text file encoding (other: utf-8). On this screen you might also want to select "Refresh automatically" which will make it unnecessary to press F5 when adding new files from outside eclipse.
    3. In General > Workspace > New text file line delimiter, change to 'Other > Unix'.
    4. Go to General>Editors>Text Editors and check "Insert spaces for tabs" and "Show line numbers".
    5. Go to Web>Javascript>Code style>Formatter: click new and give a name; in indentation select "tab policy" as "spaces only" (size 4).
    6. Go to XML>XML Files>Editor and choose "Indent using spaces" (size 4)
    7. Go to Web>HTML Files>Editor and choose "Indent using spaces" (size 4)
    8. Go to Web>CSS Files>Editor and choose "Indent using spaces" (size 4)
    9. Go to General>Editors>File associations. Add file type *.tpl and add associated editor "HTML Editor". Add file type *.wohl and add associated editor "XML Editor".
    10. Go to General>Editors>Spelling and uncheck "Enable spell checking".
    11. Press ok to close.
  6. Go to PyDev perspective. Go to File>New>PyDev project. Write a project name (e.g. "indicodev"), uncheck use default, select the root code folder of your indico (...../cds-indico/) (if you do not have it yet, check it out from the repository), choose the grammar version matching with your python version, uncheck "Create default src folder...." and click Finish.
  7. The whole project will be imported into Eclipse (Team Synch icons might take a while to show up).
  8. Go to project properties: PyDev - PYTHONPATH and add the project source folders (indico, tests, bin) in order to be able to use F3 (jump to definition).
  9. add to .cvsignore all the files that you do not want to commit to CVS.
  10. Install AnyEditTools (tool to remove automatically trailing white spaces)

How to debug with PyDev

For a complete guide, see http://pydev.org/manual_adv_remote_debugger.html .

For a quick and short summary that explains how to "add pydevd.py to your path":

  • Locate a folder similar to: .../eclipse/plugins/org.python.pydev.debug_1.5.3.1260479439/pysrc . Copy its address somewhere, we will need to paste it later in a couple places.
  • Go to your PyDev project and in the properties, go to PyDev - PYTHONPATH, External Libraries tab, Add Source Folder. This is so that when you "import pydevd" (the debugging breakpoint statement import), PyDev does not underline it in red.
  • Add this folder to your Apache python path. For this, edit /etc/apache2/sites-available/default (or similar) and edit it to have something like this:
        <Directory "/home/dmartinc/indico/cds-indico/indico/htdocs/services">
            PythonPath "sys.path+['/home/dmartinc/indico/cds-indico/indico','/home/dmartinc/indico/cds-indico/indico/htdocs','/home/dmartinc/Applications/eclipse/plugins/org.python.pydev.debug_1.5.3.1260479439/pysrc']"
            SetHandler python-program
            PythonHandler MaKaC.services.handler
            Allow from All
        </Directory>
    
    (Note that I have added the PyDev debug module folder at the end of the PythonPath line)

If you execute tests from the console, you will have to execute them while adding this folder to your PYTHONPATH as well (Note: if you do this, write some doc here explaining the exact way).

Do the same for all the other <Directory> elements (in my case, the /htdocs one, and the /htdocs and /htdocs/services one in the default-ssl configuration file).

  • Now you are set. If you want to put a breakpoint, write:
    import pydevd; pydevd.settrace()
    

or, if you want to redirect the output to the PyDev debugging console:

import pydevd; pydevd.settrace(stdoutToServer = True, stderrToServer = True)

and before you reload the browser and Apache executes the Python code, go to the Eclipse Debug perspective and start the PyDev debug server (a little icon in the top toolbar with a green bug and a P). Then, the execution should stop at the breakpoint.

It is recommended to make a code template for import pydevd; pydevd.settrace() by going to Eclipse Options > PyDev > Editor > Templates.

  • There are 3 ways of seeing the values of variables during execution:
    • The Variables view will show all the local and global objects, and you can see the attributes with a tree-like interface;
    • The Expressions view (not shown by default) lets you write watch expressions.
    • The Console view will have an interactive Python console. Look for the console with the name Debug Server. If you have used stdoutToServer = True, stderrToServer = True, this is where messages will be printed. To have the console display the values of the expressions you write, just write in the white space of the console. Your expression will appear in green. Press Enter 2 times and the value will appear (often it takes a short but noticeable time).

Shortcuts

  1. F3: go to definition
  2. ctrl+space: auto-suggest and auto-import
  3. ctrl+shift+R: open resource (quick search of resources)
  4. ctrl+H: search
  5. F5: udpate
  6. ctrl+F6: swicht between tabs
  7. Select name + F4: Hierarchy view.

And others: http://pydev.org/manual_adv_keybindings.html

Emacs

Git

Git is the version control system that is currently used by Indico. On a UNIX system, getting Git working should be fairly easy. If you're working on Windows, you can still run it (though with 50% awesomeness). See GitAndWindows.

Git4Eclipse

  • Go to Help > Software Updates > Available Software > Add site.
  • Add http://www.jgit.org/updates
  • Now in the tree you should see: http://www.jgit.org/updates
  • Check JUST the option: Eclipse Git Plugin - Release Build.
  • Click Install...and next and accept (license).
  • Restart Eclipse.
  • Clone your git repo (much easier from command line):
    • from Git bash, go to your working folder and do: git clone http://cdsware.cern.ch/repo/cds-indico.git
    • from Eclipse, go to File > New > PyDev Project. Write a project name (e.g. "indico.git"), uncheck use default, select the root code folder of your indico (...../cds-indico), choose the grammar version matching with your python version, uncheck "Create default src folder...." and click Finish.
    • From PyDev Package Explorer view. Right-click on your new project and then Team > Share Project...> Git > your indico.git project > select

TortoiseGit

Get it at http://code.google.com/p/tortoisegit/downloads/list