Tuesday, November 18, 2014

Eclipse and helpful plugins

I've been using Eclipse for years on Windows and around 4 months ago decided to use it on Linux so I can use PyDev instead of PyCharm for my Python development projects on Linux (PyCharm also works on both, I am just more familiar with Eclipse than Intellij so prefer to use that IDE).  Now I use PyDev on both my Linux and Windows enviroments and havent noticed a huge difference.  Once you figure out some of the quirks, using PyDev with Eclipse as my IDE has been a big time saver.

pre-reqs

  • java jdk
    • define JAVA_HOME
  • gradle
    • define GRADLE_HOME

Windows Install:

Debian Linux Install

  • download eclipse tar.gz file
  • extract it to /usr/share
  • add /usr/share/eclipse to PATH
    • vim ~/.profile or ~/.bashrc
      • PATH="$PATH:/usr/share/eclipse" 
  • vim /usr/share/eclipse/eclipse.ini and add
    • --launcher.GTK_version
    • 2
    • /usr/share/eclipse/eclipse.ini contents
      -startup
       plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
      --launcher.library
      plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140603-1326
      -product
      org.eclipse.epp.package.java.product
      --launcher.defaultAction
      openFile
      -showsplash
      org.eclipse.platform
      --launcher.XXMaxPermSize
      256m
      --launcher.defaultAction
      openFile
      --launcher.GTK_version
      2
      --launcher.appendVmargs
      -vmargs
      -Dosgi.requiredJavaVersion=1.6
      -XX:MaxPermSize=256m
      -Xms40m
      -Xmx512m

Plugins

to install plugins, start up Eclipse and go to (assumes Kepler or Luna versions of Eclipse):
Help -> Eclipse Marketplace ...
enter name of plugin in Finder.  below are some useful/necessary plugins
  • gradle: Gradle IDE Pack
  • git: EGit - Git Team Provider (comes by default with Luna)
  • maven: Maven Integration for Eclipse (comes by default with Luna)
  • pydev: PyDev - Python IDE for Eclipse
  • testng: TestNG for Eclipse 

Issues and Workarounds

JUnit test run fails with java.lang.SecurityException...hamcrest dependency

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:952)
  .
  .
https://code.google.com/p/hamcrest/issues/detail?id=128
I had same problem with Eclipse+Maven+Hamcrest combination. The hamcrest-library-1.3.jar in maven dependencies had collision with Eclipse embedded Hamcrest. I found corresponding issue on Eclipse https://bugs.eclipse.org/bugs/show_bug.cgi?id=405276, but it is still not resolved in my Eclipse Version: Luna Release (4.4.0) Build id: 20140612-0600. So I found alternative simple solution:
    • rename the file $ECLIPSE_HOME\plugins\org.hamcrest.core_1.3.0.v201303031735.jar to something like *.bak or remove the file. Eclipse ignores the embedded Hamcrest :) and Maven dependencies will be used instead.

Wonky Eclipse maven project error

eclipse An internal error occurred during: "Updating Maven Project". Could not create bundle file.
  • open cmd box and cd to project dir
  • > mvn eclipse:eclipse
  • > mvn eclipse:clean
may need to refresh project in eclipse or delete project and reimport it.

Monday, November 17, 2014

Python for Windows/Linux, Coding Guidelines (PEP8) and PyDev...the Reader's Digest Version

Python for Windows

Download Python

  • https://www.python.org/download/
  • by default, installs to c:\Python## where ## is version number, ex Python34
  • installer updates/adds HKEY_LOCAL_MACHINE\SOFTWARE\PYTHON registry entry

Adding HKEY_CURRENT_USER Registry Entry

Some Python module installers look in the HKEY_CURRENT_USER registry entry for the Python settings so need
to get the info from there:
  • http://choorucode.com/2012/04/28/python-version-not-found-in-registry-error/
    1. open regedit
    2. navigate to Computer->HKEY_LOCAL_MACHINE->SOFTWARE->Python->PythonCore
    3. right click 3.4->Export
    4. save as .reg file on your system, ex. c:\Users\yourname\python3.4.reg
    5. edit .reg file and change all HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER
    6. open cmd box as administrator
    7. cd to where the .reg fiel was saved
    8. install using regedit command
      • c:> regedit python3.4.reg
        • keys should be successfully added to registry
        • verify using that Computer->HKEY_CURRENT_USER->SOFTWARE->Python->PythonCore exists

Python for Linux

Below are some Python libraries that I needed to download:
  • > sudo apt-get update
  • > sudo apt-get upgrade
  • > sudo apt-get install libpq-dev python-dev libjpeg-dev libpng-dev

Python Common

Installing Python Modules

Module install can be done using pip or by double clicking the module if it is an installer.

Python Communities

For Q&A with history, see the Python Forums.

Python Coding Guidelines

Pep8 is the coding convention guideline for Python.  There are different command line tools and IDE tools that can be used to help enforce the guidelines.
  • pep8.py and autopep8.py are 2 modules that can be used
  • PyDev (eclipse plugin) can be configured to use pep8
    • in eclipse, go to Window->Preferences->PyDev->Editor->Code Analysis
    • select pep8.py tab
    • choose the radio button for warning and click Ok
  • http://pep8online.com/
    • browser based python code checker
    • go to the url, paste in your code, see the code guideline violations

PyDev

PyDev is a Python IDE for Eclipse, which may be used for Python, Jython and IronPython development.  It supports code creation, code refactoring, graphical debugging, code analysis and many other features.
Below are some helpful links:
In order to use PyDev, you must have Python (3.4)  and Eclipse (Kepler or Luna) installed.  This page assumes both are already installed.

PyDev Install

PyDev is a Python IDE for Eclipse, which may be used for Python, Jython and IronPython development.  It supports code creation, code refactoring, graphical debugging, code analysis and many other features.
Below are some helpful links:
In order to use PyDev, you must have Python (2.7/3.4)  and Eclipse (Kepler or Luna) installed.  This page assumes both are already installed.
  • install  eclipse pydev plugin
    • open eclipse -> Help -> Eclipse Marketplace...
    • type Python in Find: box and hit enter
    • in PyDev -Python IDE for Eclipse, click Install
      • accept license and install
  • configure Python install location in eclipse
    • Window -> Preferences -> PyDev -> Interpreters -> Python Interpreter
    • Press the New... button and enter Interpreter Name and path to your python.exe
    • click OK,  then click OK again on the System PYTHONPATH dialog box and OK on the Python Interpreters dailog box

Configure PyDev to use pep8

    • in exclise, go to Window->Preferences->PyDev->Editor->Code Analysis
    • select pep8.py tab
    • choose the radio button for warning and click Ok

Unresolved Import Errors

Problem:
Imports cause compile errors even when path to module is appended to the sys path:
import sys
sys.path.append('..')
sys.path.append('../../lib/Core')
sys.path.append('../../lib/Insight')
from SysTestCommon import SysTestCommon
from RemoteLog import python_grep
 
Unresolved import: SysTestCommon
 
settings Found at: TestBidderReqs
from SysTestCommon import SysTestCommon

Solution:
  • make sure any folders with modules you want to import has an __init__.py
    • __init__.py file makes the folder a Python package which makes all modules in the package accessible via import statements
  • right click your pydev project and select Properties
  • select PyDev - PYTHONPATH -> External Libraries
  • select Add source folders (any folder that has an __init__.py) and add any source files you want your project to have access to
  • click OK
  • restart eclipse for change to take effect (File -> Restart)
  • your project code will then be able to import modules from those source folders.