Removed many HAS_GEOS conditional imports

This commit is contained in:
Claude Paroz 2015-04-24 17:24:07 +02:00
parent 61d09e61f5
commit d9bcba9b29
20 changed files with 78 additions and 145 deletions

View File

@ -1,15 +1,5 @@
from django.core.exceptions import ImproperlyConfigured
# Want to get everything from the 'normal' models package.
from django.db.models import * # NOQA
from django.utils.version import get_docs_version
from django.contrib.gis.geos import HAS_GEOS
if not HAS_GEOS:
raise ImproperlyConfigured(
"GEOS is required and has not been detected. Are you sure it is installed? "
"See also https://docs.djangoproject.com/en/%s/ref/contrib/gis/install/geolibs/" % get_docs_version())
# Geographic aggregate functions
from django.contrib.gis.db.models.aggregates import * # NOQA

View File

@ -3,29 +3,18 @@ The GeoDjango GEOS module. Please consult the GeoDjango documentation
for more details:
http://geodjango.org/docs/geos.html
"""
__all__ = ['HAS_GEOS']
from .collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon # NOQA
from .error import GEOSException, GEOSIndexError # NOQA
from .factory import fromfile, fromstr # NOQA
from .geometry import GEOSGeometry, wkt_regex, hex_regex # NOQA
from .io import WKTReader, WKTWriter, WKBReader, WKBWriter # NOQA
from .libgeos import geos_version, geos_version_info # NOQA
from .linestring import LineString, LinearRing # NOQA
from .point import Point # NOQA
from .polygon import Polygon # NOQA
try:
from .libgeos import geos_version, geos_version_info # NOQA: flake8 detects only the last __all__
geos_version_info()
HAS_GEOS = True
__all__ += ['geos_version', 'geos_version_info']
except ImportError:
HAS_GEOS = False
if HAS_GEOS:
from .geometry import GEOSGeometry, wkt_regex, hex_regex
from .point import Point
from .linestring import LineString, LinearRing
from .polygon import Polygon
from .collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon
from .error import GEOSException, GEOSIndexError
from .io import WKTReader, WKTWriter, WKBReader, WKBWriter
from .factory import fromfile, fromstr
__all__ += [
'GEOSGeometry', 'wkt_regex', 'hex_regex', 'Point', 'LineString',
'LinearRing', 'Polygon', 'GeometryCollection', 'MultiPoint',
'MultiLineString', 'MultiPolygon', 'GEOSException', 'GEOSIndexError',
'WKTReader', 'WKTWriter', 'WKBReader', 'WKBWriter', 'fromfile',
'fromstr',
]

View File

@ -2,16 +2,6 @@ from ctypes import c_void_p
from django.contrib.gis.geos.error import GEOSException
# Trying to import GDAL libraries, if available. Have to place in
# try/except since this package may be used outside GeoDjango.
try:
from django.contrib.gis import gdal
except ImportError:
# A 'dummy' gdal module.
class GDALInfo(object):
HAS_GDAL = False
gdal = GDALInfo()
class GEOSBase(object):
"""

View File

@ -6,10 +6,10 @@ from __future__ import unicode_literals
from ctypes import addressof, byref, c_double
from django.contrib.gis.gdal.error import SRSException
from django.contrib.gis import gdal
from django.contrib.gis.geometry.regex import hex_regex, json_regex, wkt_regex
from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.base import GEOSBase, gdal
from django.contrib.gis.geos.base import GEOSBase
from django.contrib.gis.geos.coordseq import GEOSCoordSeq
from django.contrib.gis.geos.error import GEOSException, GEOSIndexError
from django.contrib.gis.geos.libgeos import GEOM_PTR
@ -449,7 +449,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
if self.srid:
try:
return gdal.OGRGeometry(self.wkb, self.srid)
except SRSException:
except gdal.SRSException:
pass
return gdal.OGRGeometry(self.wkb)
@ -461,7 +461,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
if self.srid:
try:
return gdal.SpatialReference(self.srid)
except SRSException:
except gdal.SRSException:
pass
return None

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
from django.contrib.gis.db.models.functions import (
Area, Distance, Length, Perimeter, Transform,
)
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.geos import GEOSGeometry, LineString, Point
from django.contrib.gis.measure import D # alias for Distance
from django.db import connection
from django.db.models import Q
@ -11,12 +11,10 @@ from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
from django.utils.deprecation import RemovedInDjango21Warning
from ..utils import no_oracle, oracle, postgis, spatialite
if HAS_GEOS:
from django.contrib.gis.geos import GEOSGeometry, LineString, Point
from .models import (AustraliaCity, Interstate, SouthTexasInterstate,
SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode)
from .models import (
AustraliaCity, CensusZipcode, Interstate, SouthTexasCity, SouthTexasCityFt,
SouthTexasInterstate, SouthTexasZipcode,
)
@skipUnlessDBFeature("gis_enabled")

View File

@ -4,23 +4,22 @@ import os
import re
from unittest import skipUnless
from django.contrib.gis.db.models import Extent3D, Union
from django.contrib.gis.db.models.functions import (
AsGeoJSON, AsKML, Length, Perimeter, Scale, Translate,
)
from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
from django.utils._os import upath
from django.utils.deprecation import (
RemovedInDjango20Warning, RemovedInDjango21Warning,
)
if HAS_GEOS:
from django.contrib.gis.db.models import Union, Extent3D
from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon
from .models import (City3D, Interstate2D, Interstate3D, InterstateProj2D,
InterstateProj3D, Point2D, Point3D, MultiPoint3D, Polygon2D, Polygon3D)
from .models import (
City3D, Interstate2D, Interstate3D, InterstateProj2D, InterstateProj3D,
MultiPoint3D, Point2D, Point3D, Polygon2D, Polygon3D,
)
if HAS_GDAL:
from django.contrib.gis.utils import LayerMapping, LayerMapError

View File

@ -1,14 +1,11 @@
from __future__ import unicode_literals
from django.contrib.gis.geos import HAS_GEOS
from django.test import TestCase, override_settings, skipUnlessDBFeature
if HAS_GEOS:
from django.contrib.gis import admin
from django.contrib.gis.geos import Point
from django.test import TestCase, override_settings, skipUnlessDBFeature
from .admin import UnmodifiableAdmin
from .models import site, City
from .models import City, site
@skipUnlessDBFeature("gis_enabled")

View File

@ -3,13 +3,11 @@ from __future__ import unicode_literals
from xml.dom import minidom
from django.conf import settings
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.sites.models import Site
from django.test import (
TestCase, modify_settings, override_settings, skipUnlessDBFeature,
)
if HAS_GEOS:
from .models import City

View File

@ -2,21 +2,17 @@ from __future__ import unicode_literals
import re
from decimal import Decimal
from unittest import skipUnless
from django.contrib.gis.db.models import functions
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.geos import (
LineString, Point, Polygon, fromstr, geos_version_info,
)
from django.db import connection
from django.test import TestCase, skipUnlessDBFeature
from django.utils import six
from ..utils import mysql, oracle, postgis, spatialite
if HAS_GEOS:
from django.contrib.gis.geos import (
LineString, Point, Polygon, fromstr, geos_version_info,
)
from .models import Country, City, State, Track
from .models import City, Country, State, Track
@skipUnlessDBFeature("gis_enabled")
@ -385,8 +381,9 @@ class GISFunctionsTests(TestCase):
)
@skipUnlessDBFeature("has_SymDifference_function")
@skipUnless(HAS_GEOS and geos_version_info()['version'] >= '3.3.0', "GEOS >= 3.3 required")
def test_sym_difference(self):
if geos_version_info()['version'] < '3.3.0':
self.skipTest("GEOS >= 3.3 required")
geom = Point(5, 23, srid=4326)
qs = Country.objects.annotate(sym_difference=functions.SymDifference('mpoly', geom))
for country in qs:

View File

@ -3,15 +3,12 @@ from __future__ import unicode_literals
from datetime import datetime
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.db.models import Extent
from django.contrib.gis.shortcuts import render_to_kmz
from django.db.models import Count, Min
from django.test import TestCase, skipUnlessDBFeature
from ..utils import no_oracle
if HAS_GEOS:
from django.contrib.gis.db.models import Extent
from .models import City, PennsylvaniaCity, State, Truth

View File

@ -2,12 +2,10 @@ from __future__ import unicode_literals
import json
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.geos import LinearRing, Point, Polygon
from django.core import serializers
from django.test import TestCase, skipUnlessDBFeature
if HAS_GEOS:
from django.contrib.gis.geos import LinearRing, Point, Polygon
from .models import City, MultiFields, PennsylvaniaCity

View File

@ -5,7 +5,6 @@ from io import BytesIO
from xml.dom import minidom
from django.conf import settings
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.sites.models import Site
from django.test import (
TestCase, ignore_warnings, modify_settings, override_settings,
@ -13,7 +12,6 @@ from django.test import (
)
from django.utils.deprecation import RemovedInDjango20Warning
if HAS_GEOS:
from .models import City, Country

View File

@ -4,7 +4,11 @@ import re
import tempfile
from django.contrib.gis import gdal
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.db.models import Extent, MakeLine, Union
from django.contrib.gis.geos import (
GeometryCollection, GEOSGeometry, LinearRing, LineString, Point, Polygon,
fromstr,
)
from django.core.management import call_command
from django.db import connection
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
@ -14,12 +18,10 @@ from django.utils.deprecation import (
)
from ..utils import no_oracle, oracle, postgis, spatialite
if HAS_GEOS:
from django.contrib.gis.db.models import Extent, MakeLine, Union
from django.contrib.gis.geos import (fromstr, GEOSGeometry,
Point, LineString, LinearRing, Polygon, GeometryCollection)
from .models import Country, City, PennsylvaniaCity, State, Track, NonConcreteModel, Feature, MinusOneSRID
from .models import (
City, Country, Feature, MinusOneSRID, NonConcreteModel, PennsylvaniaCity,
State, Track,
)
def postgis_bug_version():

View File

@ -8,15 +8,12 @@ from unittest import skipUnless
from django.contrib.gis.db.models.functions import Area, Distance
from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.measure import D
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
from django.utils._os import upath
from django.utils.deprecation import RemovedInDjango21Warning
from ..utils import oracle, postgis
if HAS_GEOS:
from .models import City, County, Zipcode

View File

@ -8,8 +8,14 @@ from binascii import a2b_hex, b2a_hex
from io import BytesIO
from unittest import skipUnless
from django.contrib.gis import gdal
from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.geos import (
HAS_GEOS, GeometryCollection, GEOSException, GEOSGeometry, GEOSIndexError,
LinearRing, LineString, MultiLineString, MultiPoint, MultiPolygon, Point,
Polygon, fromfile, fromstr, geos_version_info,
)
from django.contrib.gis.geos.base import GEOSBase
from django.contrib.gis.shortcuts import numpy
from django.utils import six
from django.utils.encoding import force_bytes
@ -17,14 +23,6 @@ from django.utils.six.moves import range
from ..test_data import TestDataMixin
if HAS_GEOS:
from django.contrib.gis.geos import (
GEOSException, GEOSIndexError, GEOSGeometry, GeometryCollection, Point,
MultiPoint, Polygon, MultiPolygon, LinearRing, LineString,
MultiLineString, fromfile, fromstr, geos_version_info,
)
from django.contrib.gis.geos.base import gdal, GEOSBase
@skipUnless(HAS_GEOS, "Geos is required.")
class GEOSTest(unittest.TestCase, TestDataMixin):

View File

@ -5,16 +5,12 @@
import unittest
from unittest import skipUnless
from django.contrib.gis.geos import HAS_GEOS
if HAS_GEOS:
from django.contrib.gis.geos import (
fromstr, LinearRing, LineString, MultiPoint, Point, Polygon,
HAS_GEOS, LinearRing, LineString, MultiPoint, Point, Polygon, fromstr,
)
from django.contrib.gis.geos.error import GEOSIndexError
if HAS_GEOS:
def api_get_distance(x):
return x.distance(Point(-200, -200))

View File

@ -4,13 +4,10 @@ import binascii
import unittest
from unittest import skipUnless
from django.contrib.gis.geos import HAS_GEOS
from django.utils.six import memoryview
if HAS_GEOS:
from django.contrib.gis.geos import (
GEOSGeometry, WKTReader, WKTWriter, WKBReader, WKBWriter,
HAS_GEOS, GEOSGeometry, WKBReader, WKBWriter, WKTReader, WKTWriter,
)
from django.utils.six import memoryview
@skipUnless(HAS_GEOS, "Geos is required.")

View File

@ -1,6 +1,8 @@
from __future__ import unicode_literals
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.db.models import F, Collect, Count, Extent, Union
from django.contrib.gis.geometry.backend import Geometry
from django.contrib.gis.geos import GEOSGeometry, MultiPoint, Point
from django.db import connection
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
from django.test.utils import override_settings
@ -8,13 +10,9 @@ from django.utils import timezone
from django.utils.deprecation import RemovedInDjango20Warning
from ..utils import no_oracle
if HAS_GEOS:
from django.contrib.gis.db.models import Collect, Count, Extent, F, Union
from django.contrib.gis.geometry.backend import Geometry
from django.contrib.gis.geos import GEOSGeometry, Point, MultiPoint
from .models import City, Location, DirectoryEntry, Parcel, Book, Author, Article, Event
from .models import (
Article, Author, Book, City, DirectoryEntry, Event, Location, Parcel,
)
@skipUnlessDBFeature("gis_enabled")

View File

@ -1,16 +1,13 @@
from unittest import skipUnless
from django.contrib.gis import forms
from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.geos import GEOSGeometry
from django.forms import ValidationError
from django.test import SimpleTestCase, skipUnlessDBFeature
from django.utils import six
from django.utils.html import escape
if HAS_GEOS and HAS_GDAL:
from django.contrib.gis import forms
from django.contrib.gis.geos import GEOSGeometry
@skipUnless(HAS_GDAL, "GeometryFieldTest needs GDAL support")
@skipUnlessDBFeature("gis_enabled")

View File

@ -7,15 +7,12 @@ from unittest import skipUnless
from django.conf import settings
from django.contrib.gis.geoip import HAS_GEOIP
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.geos import HAS_GEOS, GEOSGeometry
from django.utils import six
if HAS_GEOIP:
from django.contrib.gis.geoip import GeoIP, GeoIPException
if HAS_GEOS:
from django.contrib.gis.geos import GEOSGeometry
# Note: Requires use of both the GeoIP country and city datasets.
# The GEOIP_DATA path should be the only setting set (the directory