Skip to content

Commit

Permalink
Upgrade tested Python and Django versions (#123)
Browse files Browse the repository at this point in the history
Co-authored-by: David Smith <[email protected]>
Co-authored-by: Gagaro <[email protected]>
  • Loading branch information
3 people authored May 13, 2024
1 parent 53966a7 commit 47a29cf
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 94 deletions.
47 changes: 18 additions & 29 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,43 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on: [push, pull_request]

jobs:
tests_python:
name: Test on Python ${{ matrix.python_version }} and Django ${{ matrix.django_version }}
name: Test on Python ${{ matrix.python_version }}
runs-on: ubuntu-latest
strategy:
matrix:
django_version: [ '3.2', '4.0', '4.1' ]
python_version: [ '3.7', '3.8', '3.9', '3.10' ]
exclude:

- django_version: '4.0'
python_version: '3.7'

- django_version: '4.1'
python_version: '3.7'
python_version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}

- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v4
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.django_version }}
key: ${{ runner.os }}-pip-${{ matrix.python_version }}

- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y libproj-dev libgeos-dev gdal-bin libgdal-dev libsqlite3-mod-spatialite
python -m pip install --upgrade pip
pip install -U flake8 coveralls argparse
pip install -U Django~=${{ matrix.django_version }}
- name: Lint with flake8
run: |
flake8 --ignore=E501,W504 djgeojson
- name: Test Django
run: |
python -W error::DeprecationWarning -W error::PendingDeprecationWarning -m coverage run ./quicktest.py djgeojson
- name: Coverage
if: ${{ success() }}
run: |
coveralls --service=github
python -m pip install --upgrade 'tox>=4.0.0rc3'
- name: Run tox targets for ${{ matrix.python_version }}
run: tox run -f py$(echo ${{ matrix.python_version }} | tr -d .)
12 changes: 0 additions & 12 deletions djgeojson/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
#: Module version, as defined in PEP-0396.
from pkg_resources import DistributionNotFound

pkg_resources = __import__('pkg_resources')
try:
distribution = pkg_resources.get_distribution('django-geojson')
__version__ = distribution.version
except (AttributeError, DistributionNotFound):
__version__ = 'unknown'
import warnings
warnings.warn('No distribution found.')

GEOJSON_DEFAULT_SRID = 4326
5 changes: 3 additions & 2 deletions djgeojson/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.core.exceptions import ValidationError
from django.db.models import JSONField
from django.forms.fields import JSONField as JSONFormField, InvalidJSONInput
from django.forms.fields import InvalidJSONInput
from django.forms.fields import JSONField as JSONFormField
from django.forms.widgets import HiddenInput
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _

try:
Expand Down
1 change: 1 addition & 0 deletions djgeojson/http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import warnings

from django.http import HttpResponse


Expand Down
22 changes: 11 additions & 11 deletions djgeojson/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"""
import json
import logging
from io import StringIO # NOQA

from contextlib import contextmanager
from io import StringIO # NOQA

import django
from django.db.models.base import Model
Expand All @@ -20,19 +19,21 @@
from django.db.models.query import QuerySet
ValuesQuerySet = None

from django.forms.models import model_to_dict
from django.core.serializers.python import (_get_model,
Serializer as PythonSerializer,
Deserializer as PythonDeserializer)
from django.core.exceptions import ImproperlyConfigured
from django.core.serializers.base import (
DeserializationError,
SerializationError,
)
from django.core.serializers.json import DjangoJSONEncoder
from django.core.serializers.base import SerializationError, DeserializationError
from django.core.serializers.python import Deserializer as PythonDeserializer
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.python import _get_model
from django.forms.models import model_to_dict
from django.utils.encoding import smart_str
from django.core.exceptions import ImproperlyConfigured

try:
from django.contrib.gis.geos import WKBWriter
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.db.models.fields import GeometryField
from django.contrib.gis.geos import GEOSGeometry, WKBWriter
except (ImportError, ImproperlyConfigured):
from .nogeos import WKBWriter
from .nogeos import GEOSGeometry
Expand All @@ -41,7 +42,6 @@
from . import GEOJSON_DEFAULT_SRID
from .fields import GeoJSONField


logger = logging.getLogger(__name__)


Expand Down
5 changes: 2 additions & 3 deletions djgeojson/templatetags/geojson_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from django.core.exceptions import ImproperlyConfigured

try:
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.db.models.fields import GeometryField
from django.contrib.gis.geos import GEOSGeometry
except (ImportError, ImproperlyConfigured):
from ..nogeos import GEOSGeometry
from ..fields import GeometryField

from .. import GEOJSON_DEFAULT_SRID
from ..serializers import Serializer, DjangoGeoJSONEncoder

from ..serializers import DjangoGeoJSONEncoder, Serializer

register = template.Library()

Expand Down
19 changes: 9 additions & 10 deletions djgeojson/tests.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import json

import django
from django.forms import HiddenInput
from django.test import TestCase
from django.conf import settings
from django.core import serializers
from django.core.exceptions import ValidationError, SuspiciousOperation
from django.contrib.gis.db import models
from django.contrib.gis.geos import LineString, Point, GeometryCollection
from django.contrib.gis.geos import GeometryCollection, LineString, Point
from django.core import serializers
from django.core.exceptions import SuspiciousOperation, ValidationError
from django.forms import HiddenInput
from django.test import TestCase
from django.utils.encoding import smart_str

from .templatetags.geojson_tags import geojsonfeature
from .fields import GeoJSONField, GeoJSONFormField, GeoJSONValidator
from .serializers import Serializer
from .templatetags.geojson_tags import geojsonfeature
from .views import GeoJSONLayerView, TiledGeoJSONLayerView
from .fields import GeoJSONField, GeoJSONFormField, GeoJSONValidator


settings.SERIALIZATION_MODULES = {'geojson': 'djgeojson.serializers'}

Expand Down Expand Up @@ -678,9 +677,9 @@ def test_within_viewport(self):
response = self.view.render_to_response(context={})
geojson = json.loads(smart_str(response.content))
self.assertEqual(len(geojson['features']), 2)
self.assertAlmostEqual(geojson['features'][0]['geometry']['coordinates'][0], 6.843322039261242)
self.assertAlmostEqual(geojson['features'][0]['geometry']['coordinates'][0], 6.843321961076886)
self.assertAlmostEqual(geojson['features'][0]['geometry']['coordinates'][1], 52.76181518632031)
self.assertAlmostEqual(geojson['features'][1]['geometry']['coordinates'][0], 6.846053318324978)
self.assertAlmostEqual(geojson['features'][1]['geometry']['coordinates'][0], 6.846053240233331)
self.assertAlmostEqual(geojson['features'][1]['geometry']['coordinates'][1], 52.77442791046052)


Expand Down
7 changes: 3 additions & 4 deletions djgeojson/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
from django.contrib.gis.db.models.functions import Intersection
except (ImportError, ImproperlyConfigured):
Intersection = None
from django.views.generic import ListView
from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page
from django.core.exceptions import SuspiciousOperation
from django.core.exceptions import ImproperlyConfigured
from django.views.generic import ListView

try:
from django.contrib.gis.geos import Polygon
Expand All @@ -26,9 +25,9 @@
except (ImportError, ImproperlyConfigured):
from .fields import PointField

from . import GEOJSON_DEFAULT_SRID
from .http import HttpGeoJSONResponse
from .serializers import Serializer as GeoJSONSerializer
from . import GEOJSON_DEFAULT_SRID


class GeoJSONResponseMixin(object):
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
18 changes: 17 additions & 1 deletion quicktest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import os
import sys
import argparse

import django
from django.conf import settings
Expand Down Expand Up @@ -69,6 +69,22 @@ def run_tests(self):

django.setup()

# Workaround for incompatibility between SQLite 3.36+ and SpatiaLite 5,
# as used on GitHub Actions. This change monkey patches
# prepare_database() to avoid a call to InitSpatialMetaDataFull(). See:
# https://code.djangoproject.com/ticket/32935
# https://groups.google.com/g/spatialite-users/c/SnNZt4AGm_o
from django.contrib.gis.db.backends.spatialite.base import DatabaseWrapper

def prepare_database(self):
super(DatabaseWrapper, self).prepare_database()
with self.cursor() as cursor:
cursor.execute("PRAGMA table_info(geometry_columns);")
if cursor.fetchall() == []:
cursor.execute("SELECT InitSpatialMetaData(1)")

DatabaseWrapper.prepare_database = prepare_database

failures = DiscoverRunner().run_tests(self.apps, verbosity=1)
if failures: # pragma: no cover
sys.exit(failures)
Expand Down
14 changes: 8 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from io import open
from setuptools import setup, find_packages

from setuptools import find_packages, setup

here = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -16,14 +17,14 @@
open(os.path.join(here, 'CHANGES'), encoding='utf-8').read(),
license='LPGL, see LICENSE file.',
install_requires=[
'Django>=3.2',
'Django>=4.0',
],
extras_require={
'field': ['django-leaflet>=0.12'],
'docs': ['sphinx', 'sphinx-autobuild'],
},
packages=find_packages(),
python_requires=">=3.5",
python_requires=">=3.8",
include_package_data=True,
zip_safe=False,
classifiers=['Topic :: Utilities',
Expand All @@ -33,9 +34,10 @@
'Environment :: Web Environment',
'Framework :: Django',
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
)
47 changes: 32 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
[tox]
skipsdist = True
envlist =
{py37}-django-{32}
{py38}-django-{32,40,41}
{py39}-django-{32,40,41}
{py310}-django-{32,40,41}
{py310}-isort
{py310}-flake8
flake8
isort
py38-django{40,41,42}
py39-django{40,41,42}
py310-django{40,41,42,50}
py311-django{41,42,50}
py312-django{42,50}

[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}
deps =
flake8: flake8
django-32: Django>=3.2,<3.3
django-40: Django>=4.0,<4.1
django-41: Django>=4.1,<4.2
isort: isort
coverage
django40: Django>=4.0,<4.1
django41: Django>=4.1,<4.2
django42: Django>=4.2,<5.0
django50: Django>=5.0,<5.1
commands =
isort: isort .
flake8: flake8 --ignore=E501,W504 djgeojson
django: python -W error::DeprecationWarning -W error::PendingDeprecationWarning -W ignore:::site -W ignore:::distutils {toxinidir}/quicktest.py djgeojson
python \
-W error::DeprecationWarning \
-W error::PendingDeprecationWarning \
-W ignore:::site \
-W ignore:::distutils \
-m coverage run \
{toxinidir}/quicktest.py djgeojson

[testenv:docs]
basepython = python
changedir = docs
deps =
sphinx
sphinx_rtd_theme
Django>=3.2,<4.1
Django>=5.0,<5.1
commands =
sphinx-build -W -b html -d build/doctrees . build/html

[testenv:flake8]
usedevelop = false
basepython = python3.12
deps = flake8
commands = flake8 --ignore=E501,W504 djgeojson

[testenv:isort]
usedevelop = false
basepython = python3.12
deps = isort
commands = isort .

[isort]
skip_gitignore = true
include_trailing_comma = true
Expand Down

0 comments on commit 47a29cf

Please sign in to comment.