= Developer Guidelines - Eclipse = [[TOC]] Eclipse is a full IDE supporting Debugging & Code Completion. !PyDev is an Eclipse module which supports Python. == Installation == Debian: {{{ apt-get install eclipse-platform }}} Note: You may need super user (sudo) or root privileges to run the apt-get command. Windows: 1. Install [http://java.sun.com/javase/downloads/widget/jdk6.jsp Java JDK] 2. Install Eclipse (setup for 3.6 is documented below): * Look for "Latest release" on the [http://download.eclipse.org/eclipse/downloads/ downloads page]. 3. If using JDK 6u21: [http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F#Oracle.2FSun_VM_1.6.0_21_on_Windows modify eclipse.ini] OS X: 1. Download and install the Latest Release from [http://download.eclipse.org/eclipse/downloads/ this page]. Click on the version number and it will take you to the download page. Look for the version titled Mac OS X (Mac / Cocoa / x86_64). Install !PyDev through Eclipse: i. Help menu > Install New Software i. Work with: http://pydev.org/updates i. Add, OK i. tick !PyDev (can exclude the optional !PyDev Mylyn Integration), Next, Next, Accept, Finish - may need to resize the dialog to see the option tos elect !PyDev! - Mac users untick "Show only the lates version of available software" and then tick PyDev for Eclipse 2.8.2. i. tick to trust certificate, Restart now Note: If you have having trouble installing pydev on ubuntu you might need a newer version of eclipse than is in Ubuntu's software center - [http://askubuntu.com/questions/68018/how-do-i-install-eclipse-indigo-3-7-1 see this article on how to install] Speed up Python on Eclipse Win32: * Install the Visual C++ Compiler for Python 2.7: https://www.microsoft.com/en-us/download/details.aspx?id=44266 {{{ cd %USERPROFILE%\.p2\pool\plugins\org.python.pydev.core_7.0.0.201811071319\pysrc python setup_cython.py build_ext --inplace }}} == Configuration == 1. Set up the Python Interpreter: i. Window > Preferences > !PyDev > Interpreters - Python. Click New i. On Windows: Browse to the location of python.exe, e.g. C:\python27\python.exe, OK, OK i. On Linux/OS X: "python" is the name of the interpreter, the location is "/usr/bin/python", OK, OK 1. Add a new !PyDev Project: i. File > New > Project... i. Open the !PyDev folder, and choose !PyDev Project i. Give the project a name "web2py" i. Un-tick "Use Default" i. Browse to the web2py directory (on the Linux VM, this is in {{{/home/dev/web2py}}}) i. Un-tick "Create default 'src' folder and add it to the pythonpath" i. Tick "Add project directory to the pythonpath?" i. Click Finish i. Click "No" when asked to open the perspective 1. Debug Configuration: i. If you are using Juno or later, Run menu items have been hidden. To recover them, open the Debug perspective:[[BR]] Window > Open Perspective > Other > Debug i. From the Run menu, choose Debug Configurations... i. Double-click Python Run i. On the Main tab: Name: Enter (e.g.) web2py i. Project: Select web2py (should be the only option) i. Main module: i. Windows: Browse to web2py.py i. Linux: If browsing to web2py.py gives an error, type the full path, e.g.: /home/web2py/web2py.py i. On the Arguments tab: Type in the program arguments: "-a password" (Choose a password for web2py and substitute it for "password".) i. On the Environment tab, add Variable PYTHONUTF8 with Value 1 (bypasses default cp1252 locale: https://www.python.org/dev/peps/pep-0540. Not needed for core imports as we open in binary mode, but may affect custom code) i. Click Apply. Click Debug which launches the debugger. i. On Windows: If asked, unblock in Windows Firewall (not necessary on the Linux VM). 1. Miscellaneous suggestions for comfort and convenience: i. If the Debug perspective was not opened earlier: Window > Open Perspective > Other > Debug i. Window > Show View > Other > Debug > Expressions i. Window > Show View > Other > !PyDev > !PyDev Package Explorer[[br]] (This is where you will need to select web2py before trying Run or Debug to avoid the empty $project_loc error.) i. Drag the Expressions, Console, Tasks tabs to the upper right, where the Variables tab is. Drag !PyDev Package Explorer to the upper left where Debug is. (This leaves more space for the editor view.) i. Window > Customize Perspective > Tool bar visibility > untick !PyDev Debug, Navigation. Click OK i. Window > Customize Perspective > Command groups availability > untick External Tools, any Java items. Click OK i. You may want to change the layout of the window by dragging sections to convenient regions of the window and resizing them. Combine less-used sections as tabs in the same region. i. Save your modified perspective: Window > Save Perspective As... Choose a new name, e.g. !PyDev Debug. i. Set your default HTML editor 1. Window > Preferences > General > Editors > File Associations 1. Click .htm 1. In the Associated editors section below, click "Add..." 1. Choose "Text Editor" 1. Click OK 1. Text Editor will be added to the editors list. If not selected, click it. 1. Click Default. 1. Repeat the process with .html 1. Click OK i. Window > Preferences > !PyDev > Editor > Code Analysis * untick 'Do code analysis' (to avoid getting lots of red underlines for variables which Eclipse can't see) i. Window > Preferences > General > Editors > Text Editors * tick 'insert spaces for Tabs' * tick Show line numbers * tick Show Print Margin and set the margin to 80 (to assist in our attempt to keep within that width) i. Window > Preferences > General > Workspace * tick 'Refresh on access' * untick 'Build automatically' == Debugging with Eclipse == * Set and remove breakpoints by double clicking in the margin of the code file. * To start running with the debugger: In the toolbar below the main Eclipse menu bar, find the bug icon and click the down-arrow next to it. Click the option that has a "P" superscript. After this, you can just click the bug. (If you get an error that indicates Eclipse tried to run unittests instead, go through the down-arrow menu again.) * F5 Step into functions * F6 Step over lines * F7 Step out of functions * Use expressions (drag and drop from code) or right-click > watch * Examine values of variables in the Variables tab. === Debugging scheduled tasks === https://github.com/sahana/eden/blob/master/static/scripts/tools/run_scheduler_tasks.py === Accessing private data === Some data is marked as private to let other developers know they shouldn't access this directly * e.g. in {{{s3resource.py}}} we have {{{S3Resource.__set}}} & {{{S3Resource.__query}}} This then means that Eclipse can't see these attributes as {{{self.__set}}}, etc. Instead need to use: {{{ xxx._ClassName__AttributeName }}} e.g.: {{{ resource._S3Resource__query resource._S3Resource__set }}} == Related Links == * [wiki:DeveloperGuidelines/Tips#Pythondebugging Debugging Web2Py] * [http://www.eclipse.org/egit/] * [http://eclipse.github.com/] Other Configuration Guides (should not be required): * http://kollerie.wordpress.com/2009/04/07/setting-up-your-ide-for-web2py-development/ * (Simpler Instructions) http://allisterx.blogspot.com/2009/06/using-web2py-framework-on-eclipse.html ---- DeveloperGuidelines