Skip to content

Instantly share code, notes, and snippets.

@jams2
Created December 2, 2019 14:53
Show Gist options
  • Save jams2/11a60020a1ada897d79fc4c77fb587eb to your computer and use it in GitHub Desktop.
Save jams2/11a60020a1ada897d79fc4c77fb587eb to your computer and use it in GitHub Desktop.
Fixing Django/GEOS compatibility
"""The version regex in django/contrib/gis/geos/libgeos.py fails on
the latest homebrew geos install at time of writing, with message:
django.contrib.gis.geos.error.GEOSException: Could not parse version info string "3.8.0-CAPI-1.13.1 "
The trailing whitespace is the culprit. Add a r'\s?$' to the end of the pattern.
"""
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+)?( \w+)?\s?$'
)
@rodridev
Copy link

Thank you!

@dpetukhov
Copy link

I have the same error on Ubuntu 20.04 and Django 1.11.25 on python2.
I fixed it by changing file /home/dima/.virtualenvs/irkru/lib/python2.7/site-packages/django/contrib/gis/geos/libgeos.py on line 196 from this:

def geos_version_info():
    """
    Returns 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)

to this:

def geos_version_info():
    """
    Returns 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().strip()
    m = version_regex.match(ver)

Why they don't include this simple fix in Django 1.11 update?
And why version info of the package has a trailing whitespace?

It used to work fine on Ubuntu 18, but crashes after update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment