Opened 8 years ago
Closed 8 years ago
#27830 closed Bug (fixed)
Use distutils.version.LooseVersion instead of custom version parsing
Reported by: | NotSqrt | Owned by: | ChillarAnand |
---|---|---|---|
Component: | Core (Other) | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | anand21nanda@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Hi !
As discussed with Tim Graham in https://groups.google.com/forum/#!topic/django-users/BM3d679AsyA
django/db/backends/postgresql_psycopg2/base.py:psycopg2_version
can't handle versions like 2.7b1
or 2.7b2.dev0
(the current git versions), because it only returns (2, )
, which is lower than the minimal requirement of (2, 4, 5)
.
A possibility is to use :
from distutils.version import LooseVersion LooseVersion(psycopg2.__version__.split(' ', 1)[0]) >= LooseVersion('2.4.5')
Another possibility is packaging, the reference implementation of PEP-440, which is a dependency of setuptools (previously included in its vendor libs), so very probably installed everywhere !
While searching for "version" in the django code base, there appears to be multiple regex used to parse version strings : mysql, postgresql, gdal, geos.
This could probably be more DRY, and correct.
I've seen things like if geos_version_info()['version'] < '3.3.0':
, which might fail at some point.
Thanks !
Change History (8)
comment:1 by , 8 years ago
Component: | Uncategorized → Core (Other) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:6 by , 8 years ago
I'm doubtful that packaging
is always available. I created a Python 3.6.1 virtualenv and can import setuptools ('36.0.1') but not packaging.
Fixed in PR