diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5ad9b63 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: python + +python: +- '2.7' + +install: pip install -r pip-requirements.txt + +script: ./build.sh diff --git a/README.md b/README.md index d3d39c7..b1ba7f2 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,8 @@ python setup.py develop ``` Make sure to add `ogdch_actions` to `ckan.plugins` in your config file. + +### For development +* install the `pre-commit.sh` script as a pre-commit hook in your local repositories: +** `ln -s ../../pre-commit.sh .git/hooks/pre-commit` + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a392fb1 --- /dev/null +++ b/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +function cleanup { + exit $? +} + +trap "cleanup" EXIT + +# Check PEP-8 code style and McCabe complexity +flake8 --show-pep8 --show-source ckanext + +# run tests +# nosetests --verbose diff --git a/ckanext/ogdch_actions/__init__.py b/ckanext/ogdch_actions/__init__.py index 62a0942..2e2033b 100644 --- a/ckanext/ogdch_actions/__init__.py +++ b/ckanext/ogdch_actions/__init__.py @@ -4,4 +4,4 @@ pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) \ No newline at end of file + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/ckanext/ogdch_actions/actions.py b/ckanext/ogdch_actions/actions.py index 907d653..9a94f81 100644 --- a/ckanext/ogdch_actions/actions.py +++ b/ckanext/ogdch_actions/actions.py @@ -12,6 +12,7 @@ _group_list_dictize = ckan.lib.dictization.model_dictize.group_list_dictize _select = sqlalchemy.sql.select + class OGDActions(p.SingletonPlugin): p.implements(p.IActions) @@ -69,8 +70,8 @@ def group_list_translated(self, context, data_dict): is_org = group_type == 'organization' query = model.Session.query(model.Group).join(model.GroupRevision) - query = query.filter(model.GroupRevision.state=='active') - query = query.filter(model.GroupRevision.is_organization==is_org) + query = query.filter(model.GroupRevision.state == 'active') + query = query.filter(model.GroupRevision.is_organization == is_org) orgs = query.all() @@ -90,7 +91,7 @@ def dataset_count(self, context, data_dict): model = context['model'] query = model.Session.query(model.Package) - query = query.filter(model.Package.state=='active') - query = query.filter(model.Package.type=='dataset') + query = query.filter(model.Package.state == 'active') + query = query.filter(model.Package.type == 'dataset') return {'count': query.count()} diff --git a/pip-requirements.txt b/pip-requirements.txt index e69de29..c9846c5 100644 --- a/pip-requirements.txt +++ b/pip-requirements.txt @@ -0,0 +1,5 @@ +# This file lists the dependencies of this extension. +# Install with a command like: pip install -r pip-requirements.txt +boto==2.9.8 +xlrd==0.9.2 +flake8==2.1.0 diff --git a/pre-commit.sh b/pre-commit.sh new file mode 100755 index 0000000..5854a50 --- /dev/null +++ b/pre-commit.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +function cleanup { + if [[ $? > 0 ]] ; then + echo "You might want to run 'git stash pop' in order to get your files back" + fi +} + +trap "cleanup" EXIT + +FILENAME=$0 +if [ -h $FILENAME ] ; then + FILENAME=`readlink -e $FILENAME` +fi +DIR=`dirname $FILENAME` + +# make sure only changes of the current commit are affected +git stash -q -u --keep-index + +flake8 ckanext + +exit_code=$? + +git stash pop -q + +exit $exit_code diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..ef09bcb --- /dev/null +++ b/setup.cfg @@ -0,0 +1 @@ +[flake8]