Commit d9bcba9b authored by Claude Paroz's avatar Claude Paroz
Browse files

Removed many HAS_GEOS conditional imports

parent 61d09e61
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
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
+10 −21
Original line number Diff line number Diff line
@@ -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',
    ]
+0 −10
Original line number Diff line number Diff line
@@ -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):
    """
+4 −4
Original line number Diff line number Diff line
@@ -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

+5 −7
Original line number Diff line number Diff line
@@ -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")
Loading