[Django] #27830: Use distutils.version.LooseVersion instead of custom version parsing

30 views
Skip to first unread message

Django

unread,
Feb 13, 2017, 4:30:49 AM2/13/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
-----------------------------------------+------------------------
Reporter: NotSqrt | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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`([[https://github.com/psycopg/psycopg2/commit/b4b8b5f16440d11f8551be23c3f7517e060cf274|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
[[https://packaging.pypa.io/en/latest/version/|packaging]], the reference
implementation of [[https://www.python.org/dev/peps/pep-0440/|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 !

--
Ticket URL: <https://code.djangoproject.com/ticket/27830>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 13, 2017, 7:04:23 AM2/13/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+------------------------------------
Reporter: NotSqrt | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Bug
* component: Uncategorized => Core (Other)
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27830#comment:1>

Django

unread,
Feb 14, 2017, 11:33:05 AM2/14/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+----------------------------------------
Reporter: NotSqrt | Owner: ChillarAnand
Type: Bug | Status: assigned

Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by ChillarAnand):

* status: new => assigned
* owner: nobody => ChillarAnand


--
Ticket URL: <https://code.djangoproject.com/ticket/27830#comment:2>

Django

unread,
Feb 15, 2017, 9:04:27 AM2/15/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+----------------------------------------
Reporter: NotSqrt | Owner: ChillarAnand
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by ChillarAnand):

* cc: anand21nanda@… (added)
* has_patch: 0 => 1


Comment:

Fixed in [https://github.com/django/django/pull/8068 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27830#comment:3>

Django

unread,
Feb 15, 2017, 10:01:14 AM2/15/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+----------------------------------------
Reporter: NotSqrt | Owner: ChillarAnand
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


Comment:

Additional tests are needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/27830#comment:4>

Django

unread,
Apr 6, 2017, 9:35:49 AM4/6/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+----------------------------------------
Reporter: NotSqrt | Owner: ChillarAnand
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------

Comment (by ChillarAnand):

Added additional test cases.

--
Ticket URL: <https://code.djangoproject.com/ticket/27830#comment:5>

Django

unread,
Jun 5, 2017, 5:20:54 PM6/5/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+----------------------------------------
Reporter: NotSqrt | Owner: ChillarAnand
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------

Comment (by Tim Graham):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27830#comment:6>

Django

unread,
Jun 8, 2017, 10:34:45 AM6/8/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+----------------------------------------
Reporter: NotSqrt | Owner: ChillarAnand
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------

Comment (by ChillarAnand):

Good catch. Replaced it with distutils.version.LooseVersion.

--
Ticket URL: <https://code.djangoproject.com/ticket/27830#comment:7>

Django

unread,
Jun 12, 2017, 3:05:15 PM6/12/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+----------------------------------------
Reporter: NotSqrt | Owner: ChillarAnand
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27830#comment:8>

Django

unread,
Jun 13, 2017, 11:18:05 AM6/13/17
to django-...@googlegroups.com
#27830: Use distutils.version.LooseVersion instead of custom version parsing
------------------------------+----------------------------------------
Reporter: NotSqrt | Owner: ChillarAnand
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"08bda82c237b9ad071538c2386b8bfc62fef7f7f" 08bda82c]:
{{{
#!CommitTicketReference repository=""
revision="08bda82c237b9ad071538c2386b8bfc62fef7f7f"
Fixed #27830 -- Used distutils.version.LooseVersion for version parsing.
}}}

Reply all
Reply to author
Forward
0 new messages