Re: [Django] #32528: Replace django.utils.topological_sort with graphlib.

9 views
Skip to first unread message

Django

unread,
Jan 17, 2023, 8:03:11 AM1/17/23
to django-...@googlegroups.com
#32528: Replace django.utils.topological_sort with graphlib.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: backport, graphlib, | Triage Stage: Accepted
toposort, topological sort |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* stage: Someday/Maybe => Accepted


Comment:

Whoop! The time has come. New [https://github.com/django/django/pull/16468
PR].

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

Django

unread,
Jan 17, 2023, 8:04:07 AM1/17/23
to django-...@googlegroups.com
#32528: Replace django.utils.topological_sort with graphlib.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: backport, graphlib, | Triage Stage: Accepted
toposort, topological sort |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Nick Pope:

Old description:

> In Python 3.9 we have a new standard library module,
> [https://docs.python.org/3/library/graphlib.html graphlib], that includes
> a topological sort implementation.
> Let's use this instead of our custom implementation in
> `django.utils.topological_sort`.
>
> This will require a backport for Python 3.8, the minimum supported
> version for Django 4.0, but when support for Python 3.8 is removed we can
> simply drop the backport. When using Python 3.9+ we'll just use the
> module direct from the standard library.

New description:

In Python 3.9 we have a new standard library module,
[https://docs.python.org/3/library/graphlib.html graphlib], that includes
a topological sort implementation.
Let's use this instead of our custom implementation in
`django.utils.topological_sort`.

~~This will require a backport for Python 3.8, the minimum supported
version for Django 4.0, but when support for Python 3.8 is removed we can
simply drop the backport. When using Python 3.9+ we'll just use the module
direct from the standard library.~~

--

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

Django

unread,
Jan 18, 2023, 4:16:45 AM1/18/23
to django-...@googlegroups.com
#32528: Replace django.utils.topological_sort with graphlib.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: backport, graphlib, | Triage Stage: Ready for
toposort, topological sort | checkin

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Jan 19, 2023, 1:45:27 AM1/19/23
to django-...@googlegroups.com
#32528: Replace django.utils.topological_sort with graphlib.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed

Cleanup/optimization |
Component: Utilities | Version: dev
Severity: Normal | Resolution: fixed

Keywords: backport, graphlib, | Triage Stage: Ready for
toposort, topological sort | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"1e62a6420230c512b78433265ae8003f27c6eaeb" 1e62a642]:
{{{
#!CommitTicketReference repository=""
revision="1e62a6420230c512b78433265ae8003f27c6eaeb"
Refs #32528 -- Simplified Media.merge().

This avoids building up a second datastructure for the duplicate files
warning case and simply flatten and strip duplicates if that case ever
arises.
}}}

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

Django

unread,
Jan 19, 2023, 1:45:27 AM1/19/23
to django-...@googlegroups.com
#32528: Replace django.utils.topological_sort with graphlib.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed
Cleanup/optimization |
Component: Utilities | Version: dev
Severity: Normal | Resolution: fixed
Keywords: backport, graphlib, | Triage Stage: Ready for
toposort, topological sort | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"1282b5e4207440af659ef0e0e0c486fdfba8e7b7" 1282b5e]:
{{{
#!CommitTicketReference repository=""
revision="1282b5e4207440af659ef0e0e0c486fdfba8e7b7"
Fixed #32528 -- Replaced django.utils.topological_sort with
graphlib.TopologicalSort().

graphlib.TopologicalSort() is available since Python 3.9.
}}}

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

Django

unread,
Jan 19, 2023, 1:45:28 AM1/19/23
to django-...@googlegroups.com
#32528: Replace django.utils.topological_sort with graphlib.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed
Cleanup/optimization |
Component: Utilities | Version: dev
Severity: Normal | Resolution: fixed
Keywords: backport, graphlib, | Triage Stage: Ready for
toposort, topological sort | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"39f83765e12b0e5d260b7939fc3fe281d879b279" 39f8376]:
{{{
#!CommitTicketReference repository=""
revision="39f83765e12b0e5d260b7939fc3fe281d879b279"
Refs #32528 -- Simplified MigrationAutodetector._sort_migrations().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32528#comment:9>

Reply all
Reply to author
Forward
0 new messages