Skip to content

Commit

Permalink
Remove requirement for Python GDAL and memcached.
Browse files Browse the repository at this point in the history
Add Python 3 testing to Travis, and work around issue with echo/YAML
indenting.
  • Loading branch information
dracos committed Nov 25, 2014
1 parent 9db8044 commit d69bc2a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ notifications:
skip_join: true

language: python

python:
- "2.7"
- "3.2"

env:
- MODULES="Django>=1.4,<1.5"
- MODULES="Django>=1.5,<1.6"
- MODULES="Django>=1.6,<1.7"
- MODULES="Django>=1.7,<1.8"

# Django 1.4 did not support Python 3.
matrix:
exclude:
- python: "3.2"
env: MODULES="Django>=1.4,<1.5"

install:
- sudo rm /etc/apt/sources.list.d/ubuntugis-stable-source.list
- sudo apt-get update -qq
Expand All @@ -37,6 +48,8 @@ before_script:
# - createdb -U postgres mapit
# - psql -U postgres -d mapit -c 'create extension postgis;'
- createdb -U postgres -T template_postgis mapit
- "echo -e 'MAPIT_DB_NAME: mapit\nMAPIT_DB_USER: postgres\nDJANGO_SECRET_KEY: secret' > conf/general.yml"
- "echo 'MAPIT_DB_NAME: mapit' > conf/general.yml"
- "echo 'MAPIT_DB_USER: postgres' >> conf/general.yml"
- "echo 'DJANGO_SECRET_KEY: secret' >> conf/general.yml"
script:
- python -Wall manage.py test mapit
10 changes: 8 additions & 2 deletions mapit/views/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from django.db.utils import DatabaseError
except:
from psycopg2 import DatabaseError
from osgeo import gdal

try:
from osgeo import gdal
PYGDAL = True
except ImportError:
PYGDAL = False

from django.contrib.gis.geos import Point
from django.http import HttpResponse, HttpResponseRedirect
Expand Down Expand Up @@ -294,7 +299,8 @@ def area_from_code(request, code_type, code_value, format='json'):
@ratelimit(minutes=3, requests=100)
def areas_by_point(request, srid, x, y, bb=False, format='json'):
location = Point(float(x), float(y), srid=int(srid))
gdal.UseExceptions()
if PYGDAL:
gdal.UseExceptions()
try:
location.transform(settings.MAPIT_AREA_SRID, clone=True)
except:
Expand Down
19 changes: 12 additions & 7 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# present. Obviously you can just edit any part of this file, it is a normal
# Django settings.py file.
try:
config = yaml.load( open(os.path.join(BASE_DIR, 'conf', 'general.yml'), 'r') )
with open(os.path.join(BASE_DIR, 'conf', 'general.yml'), 'r') as fp:
config = yaml.load(fp)
except:
config = {}

Expand Down Expand Up @@ -49,13 +50,17 @@
}
CACHE_MIDDLEWARE_SECONDS = 0
else:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'TIMEOUT': 86400,
try:
import memcache
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'TIMEOUT': 86400,
}
}
}
except ImportError:
pass
CACHE_MIDDLEWARE_SECONDS = 86400
CACHE_MIDDLEWARE_KEY_PREFIX = config.get('MAPIT_DB_NAME')

Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ Django>=1.4
South==1.0
psycopg2
PyYAML
python-memcached
GDAL
Shapely

0 comments on commit d69bc2a

Please sign in to comment.