diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index da38750..33851e6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,3 @@ -# 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] @@ -11,44 +8,36 @@ jobs: 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 .) diff --git a/djgeojson/__init__.py b/djgeojson/__init__.py index 17af772..e27b3fb 100644 --- a/djgeojson/__init__.py +++ b/djgeojson/__init__.py @@ -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 diff --git a/djgeojson/fields.py b/djgeojson/fields.py index 1121803..6d51d81 100644 --- a/djgeojson/fields.py +++ b/djgeojson/fields.py @@ -1,9 +1,10 @@ from __future__ import unicode_literals +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: diff --git a/djgeojson/http.py b/djgeojson/http.py index f35d9bb..d4d1f88 100644 --- a/djgeojson/http.py +++ b/djgeojson/http.py @@ -1,4 +1,5 @@ import warnings + from django.http import HttpResponse diff --git a/djgeojson/serializers.py b/djgeojson/serializers.py index e5b96cc..a1a8a3b 100644 --- a/djgeojson/serializers.py +++ b/djgeojson/serializers.py @@ -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 @@ -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 @@ -41,7 +42,6 @@ from . import GEOJSON_DEFAULT_SRID from .fields import GeoJSONField - logger = logging.getLogger(__name__) diff --git a/djgeojson/templatetags/geojson_tags.py b/djgeojson/templatetags/geojson_tags.py index 4e6a1ba..efe5572 100644 --- a/djgeojson/templatetags/geojson_tags.py +++ b/djgeojson/templatetags/geojson_tags.py @@ -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() diff --git a/djgeojson/tests.py b/djgeojson/tests.py index a7770bd..e9274f5 100644 --- a/djgeojson/tests.py +++ b/djgeojson/tests.py @@ -3,20 +3,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'} diff --git a/djgeojson/views.py b/djgeojson/views.py index 66459cb..20e0c6a 100644 --- a/djgeojson/views.py +++ b/djgeojson/views.py @@ -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 @@ -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): diff --git a/docs/conf.py b/docs/conf.py index 04d9fde..cb8cd7d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,8 +12,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 diff --git a/quicktest.py b/quicktest.py index c8d17a4..f22dbed 100644 --- a/quicktest.py +++ b/quicktest.py @@ -1,6 +1,6 @@ +import argparse import os import sys -import argparse import django from django.conf import settings diff --git a/setup.py b/setup.py index 13788e4..ee3dbb2 100644 --- a/setup.py +++ b/setup.py @@ -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__)) @@ -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', ], ) diff --git a/tox.ini b/tox.ini index d551d5f..a8c542b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,26 +1,31 @@ [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{32,40,41,42} + py39-django{32,40,41,42} + py310-django{32,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 + django32: Django>=3.2,<4.0 + 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 @@ -28,10 +33,22 @@ 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