Skip to content

Development on Linux

Irwan Fathurrahman edited this page Feb 3, 2017 · 1 revision

Development under Gnu/Linux

Cadasta-qgis-plugin is written in python and runs as a plugin in.

Quick Installation Guide - Linux (Debian based)

These instructions are for setting up a development environment on a Debian based linux system such as Ubuntu or Mint.

To develop on the plugin, you first need to copy it to your local system. If you are a developer, the simplest way to do that is go to :file:`~/.qgis2/python/plugins` and clone Cadasta-qgis-plugin from our GitHub repository page like this:

git clone git://github.com/kartoza/cadasta-qgis-plugin.git develop        (for read only)
git clone [email protected]:kartoza/cadasta-qgis-plugin.git develop   (to commit changes)

QGIS installed in a non-standard location

For running unit tests that need QGIS, you may need to adjust PYTHONPATH and QGIS_PREFIX_PATH if QGIS is running in a non standard location. For example with QGIS built from source into /usr/local (and python bindings global install option disabled), you could run these commands (or add them to your ~/ .bashrc):

export QGIS_PREFIX_PATH=/usr/local
export PYTHONPATH=$PYTHONPATH:/usr/local/share/qgis/python/

Note

The above can be set within Eclipse's project properties if you are running your tests using the PyDev IDE environment. We also provide an example helper script run-env-linux.sh that you can use to set up your environment (it will work with the fabgis install described above). To use it do source run-env-linux.sh after which make targets etc. should work.

Adding Cadasta-qgis-plugin to your python path:

Lastly, you should add the Cadasta-qgis-plugin plugin folder to your PYTHONPATH so that package and module paths can be resolved correctly. E.g:

export PYTHONPATH=$PYTHONPATH:${HOME}/.qgis2/python/plugins/cadasta-qgis-plugin

Once again you could add this to your .bashrc or set it in Eclipse for convenience if needed.

Running tests

You can run all tests (which includes code coverage reports and other diagnostics) by doing this within the Cadasta-qgis-plugin plugin folder:

source run-env-linux.sh     (optional, depends on your setup)
make test

You can also run individual tests using nose. For example to run the safe_qgis tools tests you would do:

nosetests -v cadasta.api.test

If you wish to run tests under xvfb (a virtual framebuffer), you can do:

sudo apt-get install xvfb

To run tests under xvfb you can now do:

xvfb-run --server-args="-screen 0, 1024x768x24" make guitest

Developing using Eclipse (Linux)

Note

This is optional - you can use any environment you like for editing python, or even a simple text editor.

Warning

This section of the documentation is no longer maintained - we recommend using PyCharm Professional rather. We have a project wide license for PyCharm Professional so please contact us if you need it.

If you wish to use an IDE for development, please refer to this article for detailed information on how to get the basic Eclipse with PyDev setup.

Creating a project

The procedure for doing this is to do: :menuselection:`File --> New --> Project...` and then from the resulting dialog do :menuselection:`PyDev --> PyDev Project`.

In the resulting project dialog, set the following details:

At this point you should should click the link entitled 'Please configure an interpreter in related preferences before continuing.' And on the resulting dialog do:

In the dialog that appears do:

Another dialog will appear. Tick the first entry in the list that points to your:

~/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/org.python.pydev_2.3.0.2011121518/

(or simply click the 'Select All' button)

You will be returned to the Python Interpreters list and should see an entry for System Python 2.7 listed there. Now do in the Libraries tab:

Remote Debugging with Eclipse

For remote debugging, you should add pydevd to your PYTHONPATH before starting QGIS for example (you will need to adjust these paths to match your system):

export PYTHONPATH=$PYTHONPATH:/home/timlinux/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/org.python.pydev.debug_2.3.0.2011121518/pysrc/

Note

If you are running with remote debugging enabled, be sure to start the PyDev debug server first before launching the Cadasta-qgis-plugin QGIS plugin otherwise QGIS will likely crash when it can't find the debug server.

You will need to ensure that the PYTHONPATH containing your pydev package folder is set before you launch QGIS - for example by adding the above line to your ~/.bashrc or by making a small batch file containing the above export and then sourcing the file before launching QGIS e.g.:

source riab_paths.sh
/usr/local/bin/qgis

Running Unit tests from the IDE

Python has very good integrated support for unit testing. The first thing you should do after setting up the IDE project is to run the tests. You can run tests in the following ways:

  • For the entire Cadasta-qgis-plugin package
  • For individual sub packages (e.g. engine, gui, storage, impact_functions)
  • for an individual test module within a package
  • for an class within a test module
  • for an individual method within a test class

You can view these individual entities by browsing and expanding nodes in the project panel in the left of the IDE.

Note

If you run the test suite for the entire Cadasta-qgis-plugin package, it will mistakenly treat the sphinx documentation conf.py (docs.source.conf) as a test and fail for that test. This is 'normal' and can be ignored.