sagemath/sage

For Sage 9.2: Remove python 2 support from sagelib

Closed this issue · 50 comments

Python 3 support (#15530) was completed for Sage 9.0 (thanks in particular to the leadership of Frédéric Chapoton). Official support for Python 2.7 by the CPython core developers is ending January 1, 2020.

To enable major package upgrades and other changes that require Python 3.x (#29141),
this ticket removes Python 2 support in Sage for Sage 9.2.

Depends on #26403
Depends on #28660

CC: @timokau @fchapoton @dimpase

Component: python3

Keywords: days101

Author: Erik Bray

Branch: f368e32

Reviewer: Dima Pasechnik

Issue created by migration from https://trac.sagemath.org/ticket/28000

Description changed:

--- 
+++ 
@@ -1 +1,7 @@
+Python 3 support (#15530) is nearly complete (thanks in particular to the dogged efforts of Frédéric Chapoton).
 
+Official support for Python 2.7 by the CPython core developers is ending January 1, 2020.
+
+Because Sage's Python 3 support is likely to make it in just under the wire, there will still be some time while Sage continues to support Python 2; we probably will not want to drop it as soon as Python 3 support is complete.  But the sooner the better.
+
+This task is to remind us to do that.
comment:3

What needs to be done for this ticket?

comment:4

Go through and remove all hacks related to supporting Python 2. It will be interesting to see how big a change it takes even now. It's rather early to go through and do that in earnest, but it would be fun to just try and see what it takes.

slel commented

Changed keywords from none to days101

comment:6

One example: #27696 (remove the doctesting hack for "long", which just converts it to "int" when using Python 3.

slel commented
comment:7

Also, this ticket can be set as a dependency for other tickets that depend on the
removal of Python 2 support. Many dependency upgrades will depend on that.

Might it make sense to migrate the whole Jupyter part to Python3-only versions
before completely removing Python 3 support? Even when building Sage for
Python 2, we ship Python 3 too anyway.

comment:8

I made some progress at days101 removing all dependency on the six module for Python 2/3 support and that alone was a HUGE change (and not even quite finished yet). Will post a branch once I'm done with that.

comment:9

Here's some of my progress on this so far: Probably one of the biggest, most pervasive steps, being complete removal of dependency on six.

Of course, this step is optional--we can keep using six while otherwise dropping support for Python 2. But this makes it quite explicit.

It's pretty hard to avoid making a patch bomb of this. It's not all bad though--I started this months ago, and then once I got it finished I rebased on current develop and only had about a dozen minor merge conflicts.

Author: Erik Bray

Branch pushed to git repo; I updated commit sha1. New commits:

8f3cacbTrac #28000: Remove sagelib dependency on six

Branch pushed to git repo; I updated commit sha1. New commits:

736c7a2One Python 2-specific block that did not use six.PY2.

Changed commit from 8f3cacb to 736c7a2

comment:12

Other tasks:

  • remove or revise the doctests labeled # py2. Ideally, all such tests should be evaluated on a case-by-case basis, some should just be removed, but perhaps some should be modified to work with Python 3.
  • #28426: with a Python 3 build, do not build Python 2.
  • remove some packages which are only necessary with Python 2: typing (#28499) is the only one I know of currently, but I wouldn't be surprised if there were others.
  • remove the legacy Sage notebook — at least, I don't think it works with Python 3 now, and I don't think anyone is working on it. This means we should deprecate it ASAP. (#25837)
comment:13

My branch for this has some other in-progress changes that it seems I haven't pushed yet. I'll do so next time I rebase this branch.

comment:14

Oh right, one of the changes I started was to remove unnecessary from __future__ imports, but it seems until we have #26403, to my slight surprise, some of them are still needed in Cython modules, e.g. to have the print() function by default.

Dependencies: #26403

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

d2c4427Trac #28000: Remove sagelib dependency on six
aab5d3bOne Python 2-specific block that did not use six.PY2.
50b8951Trac #28000: Get rid of most `__nonzero__` references and/or replace them with __bool__

Changed commit from 736c7a2 to 50b8951

comment:17

Rebased, but no guarantee there are no new bugs or new uses of six I didn't miss. I didn't check yet.

Changed commit from 50b8951 to 1f6a41d

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

972f431Trac #28000: Remove sagelib dependency on six
4c35164One Python 2-specific block that did not use six.PY2.
1f6a41dTrac #28000: Get rid of most `__nonzero__` references and/or replace them with __bool__
comment:19

Updated again after removing two new uses of six that have since appeared.

slel commented

Changed dependencies from #26403 to #26403, #28660

comment:21

Do we remove all doctests tagged # py2 here or on a separate ticket?

comment:22

You could do it here, or a separate ticket (and make it a dependency of this ticket). It's going to be a patch bomb no matter what, but I don't see the harm in trying to split it up wehre possible.

Changed commit from 1f6a41d to 0e37a95

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

b4fa8dbTrac #28000: Remove sagelib dependency on six
0ff5ac8Trac #28000: One Python 2-specific block that did not use six.PY2.
0e37a95Trac #28000: Get rid of most `__nonzero__` references and/or replace them with __bool__
comment:24

Rebased on 9.0

Description changed:

--- 
+++ 
@@ -5,3 +5,6 @@
 Because Sage's Python 3 support is likely to make it in just under the wire, there will still be some time while Sage continues to support Python 2; we probably will not want to drop it as soon as Python 3 support is complete.  But the sooner the better.
 
 This task is to remind us to do that.
+
+See also:
+- #29141: Meta-ticket: Upgrades and other changes that require dropping py2 support or separate package versions for py2/py3

Description changed:

--- 
+++ 
@@ -1,10 +1,5 @@
-Python 3 support (#15530) is nearly complete (thanks in particular to the dogged efforts of Frédéric Chapoton).
+Python 3 support (#15530) was completed for Sage 9.0 (thanks in particular to the leadership of Frédéric Chapoton). Official support for Python 2.7 by the CPython core developers is ending January 1, 2020.
 
-Official support for Python 2.7 by the CPython core developers is ending January 1, 2020.
+To enable major package upgrades and other changes that require Python 3.x (#29141), 
+this ticket removes Python 2 support in Sage for Sage 9.2.
 
-Because Sage's Python 3 support is likely to make it in just under the wire, there will still be some time while Sage continues to support Python 2; we probably will not want to drop it as soon as Python 3 support is complete.  But the sooner the better.
-
-This task is to remind us to do that.
-
-See also:
-- #29141: Meta-ticket: Upgrades and other changes that require dropping py2 support or separate package versions for py2/py3
comment:27

Needs rebasing!

comment:29

Related: #27826

comment:31

Rebased. I haven't seen activity from embray for a while. Perhaps this is ready for review?


New commits:

f368e32trac 28000: rebase commits from Erik M. Bray :

Changed commit from 0e37a95 to f368e32

comment:32

Let's see if this finds a reviewer

Reviewer: Dima Pasechnik

comment:33

testing.

comment:34

OK, this makes sense and appears to work. A long, but straightforward patch, also touching quite a bit of whitespace (which probably could have waited for another place, but OK).

Should removing Python2 spkg be done elsewhere?

comment:35

Replying to @dimpase:

Should removing Python2 spkg be done elsewhere?

Yes, see #29141 (Meta-ticket: Remove Python 2 support for Sage 9.2; upgrades enabled by the removal)

Changed commit from f368e32 to none

comment:37

\(^O^)/

Hopefully the divergence between sage-the-distribution and sage-on-distro will decrease now and packaging will become simpler again.

comment:38

Thanks for finally getting this ticket merged! Sorry I haven't had much time to work on it. As others have noted this does not take care of all tasks related to dropping Python 2 support--it was just me doing as much as I could in one place. Took hours!

comment:39

This breaks on Python 3.5, I've created #29753 for that

comment:40

Does anyone know of any docker setups from tox.ini that have Python 3.5?

comment:41

Python 3.5 will be gone in Sept, why would wr spend time trying to support it?

comment:42

This accidentally broke the Macaulay2 interface. Follow up at #29759 with a trivial fix.