|Version 27 (modified by dmartinc, 4 years ago) (diff)|
Most people in the Indico team use Eclipse/PyDev. There's also a small Emacs community.
I. Eclipse + PyDev
1. Installation and setup
- Downloading and installing Eclipse + PyDev
- Download Eclipse at http://www.eclipse.org/downloads/ . Eclipse IDE for Java EE Developers is the best option because it comes with Web Tools (HTML / JS / CSS editors, etc). It is not recommended to install eclipse from Ubuntu's package manager because as of January 2010, Ubuntu 9.10 Synaptic Package Manager's eclipse package does not come with Web Tools.
- To install PyDev:
- Go to the menu: Help > Install New Software.
- Press the Add.. button, choose a name for the PyDev site, and write http://pydev.org/updates in the Location field.
- Note: at this point, if you are using Ubuntu 9.10, some Eclipse buttons will seem 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
- The PyDev package should now appear in the Install New Software window. Check the PyDev package and press next, next, etc. Previously you also needed to install PyDev extensions but this is no longer necessary: !Pydev extensions are included into !Pydev since version 1.5.
- Restart Eclipse when requested.
- Open the PyDev perspective by clicking on Window > Open perspective > Other... and selecting PyDev. Close the Java EE perspective unless you will need it later.
- Configure Eclipse and PyDev. For this, go to the menu Window > Preferences and perform the following operations:
- Select the Python interpreter. For this, go to PyDev options> Interpreter - Python > New... (interpreter) and locate/choose your python.exe or python (Linux). In the lasts versions of Eclipse there should even be an Auto Config button.
- Change the default text encoding and new line delimiter. For this, go to General > Workspace and select: "Other: utf-8" under Text file encoding and "Other: Unix" under "New text file line delimeter".
- Make Eclipse refresh the source code automatically on after external file system changes. In the same screen as before (General > Workspace> Text file encoding), select "Refresh automatically". With this, you will not need to press F5 to update manually, but Eclipse may slow down quite a bit when refreshing.
- Configure the different editors and file types:
- Go to General > Editors > Text Editors and check "Insert spaces for tabs" and "Show line numbers".
- Go to General > Editors > Spelling and uncheck "Enable spell checking".
- 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 > Content Types:
- Under Content types, select HTML, click on "Add..." and enter the *.tpl file type.
- Then select XML, click "Add..." and enter *.wohl.
- Press ok to close the Preferences dialog.
- Create the Indico project inside PyDev. This step assumes you already cloned the repository to your local computer (see TODO: put link here)
- Go to the menu File > New > PyDev project (if you are do not see !Pydev project, probably you are not in the PyDev perspective).
- Write a project name (e.g. "cds-indico).
- Uncheck "use default".
- Select the root code folder of your indico local repository (...../cds-indico).
- Choose the grammar version matching your Python version.
- Uncheck "Create default src folder"
- Click Finish.
- Configure the Indico project:
- Right click on the project name and select Properties.
- Go to the PyDev - PYTHONPATH section and add the project source folders (indico, tests, bin) in order to be able to use F3 (jump to definition).
- Install and configure tools for additional formatting help:
- To remove trailing whitespaces, which give a lot of problems when integrating branches in git, install AnyEditTools. You can do this by using the http://andrei.gmxhome.de/eclipse/ URL in Help > Install New Software. There's a lot of packages; search for the AnyEditTools package with the highest version number.
- TODO info on how to configure PyDev? formatter and Pylint in accord with PEP08
2. Debugging with PyDev
- Locate a folder similar to: .../eclipse/plugins/org.python.pydev.debug_126.96.36.1990479439/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. Press the Add Source Folder button and add the previous folder. This is so that when you "import pydevd" (the debugging breakpoint statement import), PyDev does not underline it in red.
- Add the folder to your Apache Python path. For this, edit /etc/apache2/sites-available/default (or similar) and edit the different Indico <Directory> elements to become something similar to:
In a normal Indico Apache configuration there should be 2 directory elements in /etc/apache2/sites-available/default, the /htdocs one, /htdocs/services. Do the same one in the default-ssl configuration file if you have configured HTTPs for Indico.
<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_188.8.131.520479439/pysrc']" SetHandler python-program PythonHandler MaKaC.services.handler Allow from All </Directory>
- Add the folder to your PYTHONPATH so that it is available when you execute Python scripts from the console, such as tests. For example, if you use a bash console in Linux, you can do this by adding a line in your ~/.bashrc file (this will only work for new consoles):
in your .bashrc file (this will only work for new consoles).
- Using the debugger.
- Change to the Debug perspective by going to Window > Open Perspective.
- Start the debug server: this is necessary before placing breakpoints and running the code (from Apache or from a console script). For this, in the Debug perspective, press a little icon in the top toolbar with a green bug and a P.
- Placing breakpoints: if you want to place a breakpoint, place the following line in your code:
import pydevd; pydevd.settrace(stdoutToServer = True, stderrToServer = True)
- Execute your code by loading a page in Apache or launching the console script. The execution should stop in the breakpoint and you are now able to do step-by-step execution, see variable values, etc.
- Debugging tips
- It is recommended to make a code template for import pydevd; pydevd.settrace(stdoutToServer = True, stderrToServer = True) 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. You must use stdoutToServer = True, stderrToServer = True for the console to work (in Indico, at least). 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).
For the original guide, see http://pydev.org/manual_adv_remote_debugger.html .
3. Eclipse + PyDev Shortcuts
- F3: go to definition
- ctrl + space: auto-suggest and auto-import
- ctrl + shift + R: open resource (quick search of resources)
- ctrl + H: search
- F5: refresh the project after external file system changes.
- ctrl + F6: swicht between tabs
- Select name + F4: Hierarchy view.
- ctrl + M: maximize and unmaximize current tab
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.
This is an Eclipse plugin that integrates git functionality in Eclipse.
- The installation is similar to PyDev and AnyEditTools:
- Go to Help > Install New Software
- Add a new site by using http://www.jgit.org/updates as the URL
- Check ONLY the option: Eclipse Git Plugin - Release Build.
- Click Install...and next and accept (license).
- Restart Eclipse when requested.
- Clone your git repo if you have not done already (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 .
- Create the PyDev project if you have not done already (see point 4 of PyDev installation and setup].
- Tell Git4Eclipse to follow your Indico project:
- Right-click on the project and select Team > Share Project...
- Select Git > your indico.git project.
- The installation is similar to PyDev and AnyEditTools: