wiki:Dev/Tools

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

minor

Development Tools


A. IDEs

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


I. Eclipse + PyDev

1. Installation and setup

  1. Downloading and installing Eclipse + PyDev
    1. 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.
    2. 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.
  1. 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.
  1. Configure Eclipse and PyDev. For this, go to the menu Window > Preferences and perform the following operations:
    1. 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.
    2. 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".
    3. 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.
    4. 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 Web > Javascript > Code style > Formatter. Click on the New button and choose a name (e.g. "Indico"). Select "tab policy" as "spaces only" (size 4) in the Indentation section.
      • 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.
    5. Press ok to close the Preferences dialog.
  1. 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.
  1. 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).
  1. Install and configure tools for additional formatting help:
    1. 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.
    2. TODO info on how to configure PyDev? formatter and Pylint in accord with PEP08

2. Debugging with PyDev

  1. Configuration
    1. 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.
    2. 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.
    3. 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:
          <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>
      
      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.
    4. 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):
         export PYTHONPATH=${PYTHONPATH}:/home/dmartinc/Applications/eclipse/plugins/org.python.pydev.debug_1.5.3.1260479439/pysrc/
      
      in your .bashrc file (this will only work for new consoles).

  1. Using the debugger.
    1. Change to the Debug perspective by going to Window > Open Perspective.
    2. 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.
    3. Placing breakpoints: if you want to place a breakpoint, place the following line in your code:
      import pydevd; pydevd.settrace(stdoutToServer = True, stderrToServer = True)
      
    4. 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.
  1. Debugging tips
    1. 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.
    2. 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

  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: refresh the project after external file system changes.
  6. ctrl + F6: swicht between tabs
  7. Select name + F4: Hierarchy view.
  8. ctrl + M: maximize and unmaximize current tab

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


II. Emacs




B. 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.

I. Git4Eclipse

This is an Eclipse plugin that integrates git functionality in Eclipse.

  1. Installation
    1. 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.
    2. 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 .
    3. Create the PyDev project if you have not done already (see point 4 of PyDev installation and setup].
    4. Tell Git4Eclipse to follow your Indico project:
      • Right-click on the project and select Team > Share Project...
      • Select Git > your indico.git project.

II. TortoiseGit

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