mirror of https://github.com/django/django.git
Fixed #28441 -- Fixed GEOS version parsing with a commit hash at the end.
This commit is contained in:
parent
78f7f68021
commit
78c155cf2e
|
@ -9,7 +9,7 @@ from .error import GEOSException # NOQA
|
||||||
from .factory import fromfile, fromstr # NOQA
|
from .factory import fromfile, fromstr # NOQA
|
||||||
from .geometry import GEOSGeometry, hex_regex, wkt_regex # NOQA
|
from .geometry import GEOSGeometry, hex_regex, wkt_regex # NOQA
|
||||||
from .io import WKBReader, WKBWriter, WKTReader, WKTWriter # NOQA
|
from .io import WKBReader, WKBWriter, WKTReader, WKTWriter # NOQA
|
||||||
from .libgeos import geos_version, geos_version_info # NOQA
|
from .libgeos import geos_version # NOQA
|
||||||
from .linestring import LinearRing, LineString # NOQA
|
from .linestring import LinearRing, LineString # NOQA
|
||||||
from .point import Point # NOQA
|
from .point import Point # NOQA
|
||||||
from .polygon import Polygon # NOQA
|
from .polygon import Polygon # NOQA
|
||||||
|
|
|
@ -8,11 +8,9 @@
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
from ctypes import CDLL, CFUNCTYPE, POINTER, Structure, c_char_p
|
from ctypes import CDLL, CFUNCTYPE, POINTER, Structure, c_char_p
|
||||||
from ctypes.util import find_library
|
from ctypes.util import find_library
|
||||||
|
|
||||||
from django.contrib.gis.geos.error import GEOSException
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.utils.functional import SimpleLazyObject
|
from django.utils.functional import SimpleLazyObject
|
||||||
from django.utils.version import get_version_tuple
|
from django.utils.version import get_version_tuple
|
||||||
|
@ -179,29 +177,7 @@ class GEOSFuncFactory:
|
||||||
# explicitly to c_char_p to ensure compatibility across 32 and 64-bit platforms.
|
# explicitly to c_char_p to ensure compatibility across 32 and 64-bit platforms.
|
||||||
geos_version = GEOSFuncFactory('GEOSversion', restype=c_char_p)
|
geos_version = GEOSFuncFactory('GEOSversion', restype=c_char_p)
|
||||||
|
|
||||||
# Regular expression should be able to parse version strings such as
|
|
||||||
# '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1', '3.4.0dev-CAPI-1.8.0' or '3.4.0dev-CAPI-1.8.0 r0'
|
|
||||||
version_regex = re.compile(
|
|
||||||
r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))'
|
|
||||||
r'((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)( r\d+)?$'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def geos_version_info():
|
|
||||||
"""
|
|
||||||
Return a dictionary containing the various version metadata parsed from
|
|
||||||
the GEOS version string, including the version number, whether the version
|
|
||||||
is a release candidate (and what number release candidate), and the C API
|
|
||||||
version.
|
|
||||||
"""
|
|
||||||
ver = geos_version().decode()
|
|
||||||
m = version_regex.match(ver)
|
|
||||||
if not m:
|
|
||||||
raise GEOSException('Could not parse version info string "%s"' % ver)
|
|
||||||
return {key: m.group(key) for key in (
|
|
||||||
'version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor')}
|
|
||||||
|
|
||||||
|
|
||||||
def geos_version_tuple():
|
def geos_version_tuple():
|
||||||
"""Return the GEOS version as a tuple (major, minor, subminor)."""
|
"""Return the GEOS version as a tuple (major, minor, subminor)."""
|
||||||
return get_version_tuple(geos_version_info()['version'])
|
return get_version_tuple(geos_version().decode())
|
||||||
|
|
|
@ -9,4 +9,5 @@ Django 1.11.5 fixes several bugs in 1.11.4.
|
||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Fixed GEOS version parsing if the version has a commit hash at the end (new
|
||||||
|
in GEOS 3.6.2) (:ticket:`28441`).
|
||||||
|
|
|
@ -678,7 +678,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
||||||
self.assertFalse(MultiLineString(ls_closed, ls_not_closed).closed)
|
self.assertFalse(MultiLineString(ls_closed, ls_not_closed).closed)
|
||||||
self.assertTrue(MultiLineString(ls_closed, ls_closed).closed)
|
self.assertTrue(MultiLineString(ls_closed, ls_closed).closed)
|
||||||
|
|
||||||
with mock.patch('django.contrib.gis.geos.libgeos.geos_version_info', lambda: {'version': '3.4.9'}):
|
with mock.patch('django.contrib.gis.geos.libgeos.geos_version', lambda: b'3.4.9'):
|
||||||
with self.assertRaisesMessage(GEOSException, "MultiLineString.closed requires GEOS >= 3.5.0."):
|
with self.assertRaisesMessage(GEOSException, "MultiLineString.closed requires GEOS >= 3.5.0."):
|
||||||
MultiLineString().closed
|
MultiLineString().closed
|
||||||
|
|
||||||
|
@ -1296,22 +1296,18 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
||||||
'{"coordinates": [[[0, 0], [0, 1], [1, 1], [0, 0]]], "type": "Polygon"}',
|
'{"coordinates": [[[0, 0], [0, 1], [1, 1], [0, 0]]], "type": "Polygon"}',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_geos_version(self):
|
|
||||||
"""Testing the GEOS version regular expression."""
|
|
||||||
from django.contrib.gis.geos.libgeos import version_regex
|
|
||||||
versions = [('3.0.0rc4-CAPI-1.3.3', '3.0.0', '1.3.3'),
|
|
||||||
('3.0.0-CAPI-1.4.1', '3.0.0', '1.4.1'),
|
|
||||||
('3.4.0dev-CAPI-1.8.0', '3.4.0', '1.8.0'),
|
|
||||||
('3.4.0dev-CAPI-1.8.0 r0', '3.4.0', '1.8.0')]
|
|
||||||
for v_init, v_geos, v_capi in versions:
|
|
||||||
m = version_regex.match(v_init)
|
|
||||||
self.assertTrue(m, msg="Unable to parse the version string '%s'" % v_init)
|
|
||||||
self.assertEqual(m.group('version'), v_geos)
|
|
||||||
self.assertEqual(m.group('capi_version'), v_capi)
|
|
||||||
|
|
||||||
def test_geos_version_tuple(self):
|
def test_geos_version_tuple(self):
|
||||||
with mock.patch('django.contrib.gis.geos.libgeos.geos_version_info', lambda: {'version': '3.4.9'}):
|
versions = (
|
||||||
self.assertEqual(geos_version_tuple(), (3, 4, 9))
|
(b'3.0.0rc4-CAPI-1.3.3', (3, 0, 0)),
|
||||||
|
(b'3.0.0-CAPI-1.4.1', (3, 0, 0)),
|
||||||
|
(b'3.4.0dev-CAPI-1.8.0', (3, 4, 0)),
|
||||||
|
(b'3.4.0dev-CAPI-1.8.0 r0', (3, 4, 0)),
|
||||||
|
(b'3.6.2-CAPI-1.10.2 4d2925d6', (3, 6, 2)),
|
||||||
|
)
|
||||||
|
for version_string, version_tuple in versions:
|
||||||
|
with self.subTest(version_string=version_string):
|
||||||
|
with mock.patch('django.contrib.gis.geos.libgeos.geos_version', lambda: version_string):
|
||||||
|
self.assertEqual(geos_version_tuple(), version_tuple)
|
||||||
|
|
||||||
def test_from_gml(self):
|
def test_from_gml(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in New Issue