Re: [sage-devel] Re: print to python3
I am wondering why no one mentions the "six" package to maintain a temporary py2/py3-compatible codebase. I have an experience of moving my own small project from python 2 to python 3 with the "six" package quite successfully. The strategy was to add "import six" at every file and make the file work on both python2 and python3. After a period of keeping the stable py2/py3-compatible version for a while, then I dropped supporting python2 and started replacing all the compatible code based on "six" to pure python3 code. Of course, compared with Sage, my own project was a tiny thing. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On Wed, May 25, 2016 at 6:54 PM, Harald Schillywrote: > On Wed, May 25, 2016 at 6:28 PM, Nils Bruin wrote: >> In that case it might be worth considering if we can integrate our preparser >> steps into the lib2to3.refactor framework: > > I'm by far not an expert on parsers, but I think forking that 2to3 > part in the standard library could work (i.e. a lot of careful work, > but then it's much more robust). Internally, I think this tool works > by being able to parse both python versions into a syntax tree -- > that's done in a .c file, such that this grammar definition is being > compiled to run quickly. Then, there are many python files in fixes/ > which are doing the transformations of the parsed tree. There is also > a fix_print.py, which would need that little bit of patching to handle > the case of tuples vs. concatenated strings better. SageMath specific > transformations would be additional fix_*.py transformations. I like the sound of this too. lib2to3 can be pretty powerful. Its biggest downside is lack of documentation (at least, last I tried to do anything with it). For example it can be hard to figure out how to write a fixer. Interest in lib2to3 has also declined as it became clear, through practice, that it was not a long-term viable solution for supporting Python 2 and 3 simultaneously, and that for any reasonably complicated project it didn't do enough to be worth the trouble. But for this use of translating statements typed into a REPL I think it could be very useful. Especially if we only enable a limited subset of fixers that are easy to reason about (e.g. print, iteritems, etc.) -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On Wed, May 25, 2016 at 6:28 PM, Nils Bruinwrote: > In that case it might be worth considering if we can integrate our preparser > steps into the lib2to3.refactor framework: I'm by far not an expert on parsers, but I think forking that 2to3 part in the standard library could work (i.e. a lot of careful work, but then it's much more robust). Internally, I think this tool works by being able to parse both python versions into a syntax tree -- that's done in a .c file, such that this grammar definition is being compiled to run quickly. Then, there are many python files in fixes/ which are doing the transformations of the parsed tree. There is also a fix_print.py, which would need that little bit of patching to handle the case of tuples vs. concatenated strings better. SageMath specific transformations would be additional fix_*.py transformations. -- h -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On Wednesday, May 25, 2016 at 8:23:07 AM UTC-7, Harald Schilly wrote: > > I haven't read all the posting here, but just to throw in an idea that > might not have been mentioned before: we could use this 2to3 utility in the > preparsing step. I.e. an extended pipeline like input → preparser → 2to3 → > evaluation. > That is a very attractive idea, because we get to reuse a lot of careful work other people have already done on the subject. It's also quite conceivable that the 2to3 step is not *that* much more expensive than our current preparser. In that case it might be worth considering if we can integrate our preparser steps into the lib2to3.refactor framework: it is a full parser, so it will be a lot more powerful and robust than the regex/substitution approach taken now. We'd also get to formalize the sage grammar extensions into a formal grammar description. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On Tuesday, May 24, 2016 at 5:48:59 PM UTC+2, John Cremona wrote: > > We seem to be stuck. > I haven't read all the posting here, but just to throw in an idea that might not have been mentioned before: we could use this 2to3 utility in the preparsing step. I.e. an extended pipeline like input → preparser → 2to3 → evaluation. Below is a sample code that does that, which is my just showing me that this is doable from within SageMath (running on SMC, SageMath 6.10) %python from lib2to3 import refactor FIXERS_2TO3 = refactor.get_fixers_from_package("lib2to3.fixes") rt = refactor.RefactoringTool(FIXERS_2TO3) processed = preparse("""\ print "hello" for k, v in d.iteritems(): print k, v f(x) = 1+x^2 [blah(a,b) for a,b in x.iteritems()] print range(10) print dict.keys() """) tree = rt.refactor_string(processed, "SageMath2to3") print(unicode(tree)) which produces print("hello") for k, v in d.items(): print(k, v) __tmp__=var("x"); f = symbolic_expression(Integer(1)+x**Integer(2)).function (x) [blah(a,b) for a,b in x.items()] print(list(range(Integer(10 print(list(dict.keys())) Notable: * didn't destroy or got confused by SageMath's preparse step (tested with this f(x) = ... and Integer) * iteritems → items * did wrap list( ... ) around these new generators, which are different from py2 (yes, that's not always intelligent, but hey that's the tradeoff) * did fix williams example Missing: * As mentioned somewhere here, the print function needs fine-tuning to be more equivalent, but that's doable with a bit of heuristics. My perspective on that is, that we could use this as a way to keep the UI in a long-term compatibility mode. At first, it's a default, but then we can figure out a way to make this somehow prominent and urge everyone to think about switching this compatibility mode layer off. Of course, my small test here is also by no means a full test. There are likely some hurdles left. -- harald -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
> > Most Sage users do not care a fig about Python versions, but will care > if after 10 years of being able to type "print a" they are suddenly > forced into typing "(print(a)". Iwas thinking about this from a user > perspective not a developer perspective. > > Bingo. > Also, I think the longer we delay on becoming Python3 compliant, the more we are losing in potential users and developers who are starting by learning Python3. That's ridiculous. The changes between P2 and P3, while nontrivial, are much more casual for most users. Where we will lose people is by once again following the common (not universal) open-source mantra of "if it's good for developers, it must be good for users". As William says, > I'm here from endless users (eg each year at the sage booth) about minor deprecations that piss them off. This print thing will be horrible. Yup. > However, if we make switching from Python2 to Python3 trivial/smooth/easy for end users, they'll all switch no problem and love it. Double yup! Though perhaps harder. On deprecation (if that is possible), I would personally vote for X = 2 as many people don't teach the same course every year, but I know I might be in the minority on that. I also like Fernando's post - my assumption in our having py2/py3 package availability was that we were planning on supporting both, but maybe that is not possible/too crazy. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
This looks helpful: http://python-future.org/compatible_idioms.html I was looking for a simple-minded person's guide to what they would actually have to change to make the transition. There is a lot of ranting out there and stuff wriiten for people for whom programming seems more and end in itself than a means to an end. Apart from print there is string stuff (not very relevant for users or most ordinary developers), iteration through dictionaries, xrange & range, map & imap, zip & izip, and that is about it (filtering by things which I think *I* would need to know and change for Sage development. John On 25 May 2016 at 11:38, Simon Kingwrote: > Hi William, > > On 2016-05-24, William Stein wrote: >> The last thing we want is: >> >> - I upgraded to Sage-7.3 and *all* my 100s of worksheets I use in >> teaching broke due to print statements.I spent 10 hours going >> through and fixing them all -- ugh. Misery. >> >> Then... >> >> - I upgraded to sage-7.5 and all my code broke again due to (some >> other python3 feature we enable)... I spent 10 hours going through >> and fixing them all -- ugh. Misery and pain. >> >> Then... >> >> - I upgraded to Sage-8.0 and all my code broke badly again due to >> Sage switching to Python3! I spent hours rewriting my code a third >> time, running scripts (like the 2-to-3 convertor, but preparser >> aware?), etc. > > +1 > > I found it quite annoying when my spkg stopped working for some > silly reason, I fixed it, then it broke for another reason, etc. That > frustrating experience shouldn't happen too often. > > Cheers, > Simon > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
We seem to be stuck. The possibilities are (1) make "print a" just stop working at some point (maybe not yet) (2) as (1) but with a deprecation warning (3) continue to support "print a" for ever. All three have had some negative votes! Jeroen, I also do not like "endless" deprecation warnings, but if it was limited to one per session (assuming that is technically possible) it would not be so bad? John On 24 May 2016 at 14:35, Jeroen Demeyerwrote: > On 2016-05-24 15:27, Travis Scrimshaw wrote: >> >> every time, not just the first > > > -1. We should not annoy our users with endless deprecation warnings. > > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On 2016-05-24 15:27, Travis Scrimshaw wrote: every time, not just the first -1. We should not annoy our users with endless deprecation warnings. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On Tuesday, May 24, 2016 at 7:55:49 AM UTC-5, vdelecroix wrote: > > On 24/05/16 07:48, John Cremona wrote: > > On 24 May 2016 at 13:17, Jeroen Demeyer> wrote: > >> On 2016-05-24 14:06, John Cremona wrote: > >>> > >>> Would it be possible for > >>> > >>> sage: a=3 > >>> sage: print a > >>> > >>> to work on the command line, using the preparser? > >> > >> > >> That already works today. > > > > But would it still work after a total conversion of Sage to Python 3? > > > > Most Sage users do not care a fig about Python versions, but will care > > if after 10 years of being able to type "print a" they are suddenly > > forced into typing "(print(a)". Iwas thinking about this from a user > > perspective not a developer perspective. > > > > I agree with John. We should add a DeprecationWarning in the Sage > preparser right now for "print X, Y, Z" and make it such that "print(X, > Y, Z)" really behaves like Python 3. > > Nothing will change with .py files. But in the console, notebook and > .sage files users would be noticed. > > I also agree with John's suggestion as a *temporary* measure which warns users (every time, not just the first) that it will no longer be supported, which will include anyones .sage files too. Also, I think the longer we delay on becoming Python3 compliant, the more we are losing in potential users and developers who are starting by learning Python3. Best, Travis -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On 24/05/16 07:48, John Cremona wrote: On 24 May 2016 at 13:17, Jeroen Demeyerwrote: On 2016-05-24 14:06, John Cremona wrote: Would it be possible for sage: a=3 sage: print a to work on the command line, using the preparser? That already works today. But would it still work after a total conversion of Sage to Python 3? Most Sage users do not care a fig about Python versions, but will care if after 10 years of being able to type "print a" they are suddenly forced into typing "(print(a)". Iwas thinking about this from a user perspective not a developer perspective. I agree with John. We should add a DeprecationWarning in the Sage preparser right now for "print X, Y, Z" and make it such that "print(X, Y, Z)" really behaves like Python 3. Nothing will change with .py files. But in the console, notebook and .sage files users would be noticed. Vincent If you want that to continue working, it's better to not switch to Python 3 style printing. It's kind of silly to change Sage to use Python 3 printing and at the same time add a hack to support Python 2 printing. Better stick with Python 2 printing then... -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On Tue, 24 May 2016, John Cremona wrote: Most Sage users do not care a fig about Python versions, but will care if after 10 years of being able to type "print a" they are suddenly forced into typing "(print(a)". Iwas thinking about this from a user perspective not a developer perspective. You have very good perspective. Can we add a deprecation warning to old-style print? -- Jori Mäntysalo
Re: [sage-devel] Re: print to python3
On 24 May 2016 at 13:17, Jeroen Demeyerwrote: > On 2016-05-24 14:06, John Cremona wrote: >> >> Would it be possible for >> >> sage: a=3 >> sage: print a >> >> to work on the command line, using the preparser? > > > That already works today. But would it still work after a total conversion of Sage to Python 3? Most Sage users do not care a fig about Python versions, but will care if after 10 years of being able to type "print a" they are suddenly forced into typing "(print(a)". Iwas thinking about this from a user perspective not a developer perspective. John > > If you want that to continue working, it's better to not switch to Python 3 > style printing. It's kind of silly to change Sage to use Python 3 printing > and at the same time add a hack to support Python 2 printing. Better stick > with Python 2 printing then... > > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On 2016-05-24 14:06, John Cremona wrote: in code (*.py) files. For .py code files, there is not really an issue since those can just do from __future__ import ... -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On 2016-05-24 14:06, John Cremona wrote: Would it be possible for sage: a=3 sage: print a to work on the command line, using the preparser? That already works today. If you want that to continue working, it's better to not switch to Python 3 style printing. It's kind of silly to change Sage to use Python 3 printing and at the same time add a hack to support Python 2 printing. Better stick with Python 2 printing then... -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On 24 May 2016 at 12:33, Frédéric Chapotonwrote: > Hello everybody, > > we are now almost ready to try to use the Python 3 print() function > everywhere in Sage: doctests, command-line, notebook. > This big switch is the aim of ticket http://trac.sagemath.org/ticket/20668. > It still has to wait for an update of sagenb and for the next beta. > > This is an important change, that will likely break a lot of code by our > users. So we have to discuss if we all agree to make this change right now, > and if yes, how > to advertise for it and to warn everybody very loud, and to what documents > to point to help people adapt their code. > > I propose to add a message below the banner saying something like "WARNING: > the behaviour of print has been changed. It is now a function: use > print("text")" > with a link to a webpage (on the wiki ?) explaining the reasons for the > change and how to cope with it > Would it be possible for sage: a=3 sage: print a to work on the command line, using the preparser? I think that would make users a lot less annoyed. I *only* mean on the command line and notebook cells, not in code (*.py) files. John > Please express yourself on the subject. > > Frederic > > > Le samedi 21 mai 2016 09:09:26 UTC+2, Frédéric Chapoton a écrit : >> >> Hello, >> >> concerning changing the behaviour of print to python3 style, >> >> There are still a few tickets needing review: >> >> http://trac.sagemath.org/query?status=!closed=python3 >> >> Frederic >> >> >> Le mardi 3 mai 2016 20:50:21 UTC+2, Frédéric Chapoton a écrit : >>> >>> Hello, >>> >>> I am trying to move toward using the python3 syntax for print. >>> >>> This is done by small chunks, using a lot of tiny tickets, according the >>> folders in sage, mostly. >>> These tickets can be found at the bottom of >>> >>> http://trac.sagemath.org/query?status=!closed=python3 >>> >>> If some of you could find time to review one of those, that would help to >>> advance the change. >>> >>> Many thanks to those that have already reviewed some of these. >>> >>> cheers, >>> Frederic > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
Because if you do that now, it triggers doctests failure all over the place. Le lundi 16 mai 2016 11:49:45 UTC+2, Jeroen Demeyer a écrit : > > On 2016-05-16 11:34, Frédéric Chapoton wrote: > > Once this is done, the plan is > > to add "from __future__ import print_function" to src/sage/all.py. > > Why only "once this is done". What makes that file so special? > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: print to python3
On 2016-05-16 11:34, Frédéric Chapoton wrote: Once this is done, the plan is to add "from __future__ import print_function" to src/sage/all.py. Why only "once this is done". What makes that file so special? -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.