|Version 20 (modified by dmartinc, 3 years ago) (diff)|
Most people in the Indico team use Eclipse/PyDev. There's also a small Emacs community.
Eclipse + PyDev
Installation and setup
- 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).
- 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/ )
- Check the boxes for PyDev and next, next, next,....
- Open PyDev perspective by clicking on Window>Open perspective>Other... and selecting PyDev.
- Go to window>preferences and:
- go to PyDev options> Interpreter - Python > New... (interpreter) and locate/choose your python.exe or python (linux).
- 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.
- In General > Workspace > New text file line delimiter, change to 'Other > Unix'.
- Go to General>Editors>Text Editors and check "Insert spaces for tabs" and "Show line numbers".
- Go to XML>XML Files>Editor and choose "Indent using spaces" (size 4)
- Go to Web>HTML Files>Editor and choose "Indent using spaces" (size 4)
- Go to Web>CSS Files>Editor and choose "Indent using spaces" (size 4)
- 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".
- Go to General>Editors>Spelling and uncheck "Enable spell checking".
- Press ok to close.
- 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.
- The whole project will be imported into Eclipse (Team Synch icons might take a while to show up).
- 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).
- add to .cvsignore all the files that you do not want to commit to CVS.
- 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_220.127.116.110479439/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_18.104.22.1680479439/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).
- F3: go to definition
- ctrl+space: auto-suggest and auto-import
- ctrl+shift+R: open resource (quick search of resources)
- ctrl+H: search
- F5: udpate
- ctrl+F6: swicht between tabs
- Select name + F4: Hierarchy view.
And others: http://pydev.org/manual_adv_keybindings.html
- The CDS guys have some nice documentation on this;
- There's a nice Emacs mode from Trac wiki editing;
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.
- 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