Porting to Python 3, part 4 ("final") #558

Merged
merged 17 commits into from Sep 1, 2011

Conversation

Projects
None yet
4 participants
@vperic
Contributor

vperic commented Aug 17, 2011

This is, tentatively, the final pull request for the GSoC project. There are a few remaining issues (the Issues page is down now so I'll add the numbers when it's up), but I feel Python 3 support is mostly here. I will definitely be sticking around to keep working on this (and PyPy compatibility), as problems will probably arise once people actually use SymPy with Python 3. Notably, this adds a bin/use2to3 script, which will create a "sympy-py3k" directory with Python 3-compatible code in it (see that commit and the script itself for more info). This should make testing this easier and I'd appreciate it if people could test it under Python 3 too and report any issues they might get (that aren't already known). Note, Aaron asked me to refactor this script to use git directly and I'll do that tomorrow; I just wanted to get the initial discussion going on the other commits as it's currently quite useable too.

I've tested this and it passes fine under Python 2, and only the errors already on the issue tracker for Python 3.

@vperic

This comment has been minimized.

Show comment
Hide comment
@vperic

vperic Aug 17, 2011

Contributor

And the issue tracker is alive again. So, this fixes issue 2605, 2608, 2610, 2612 (this should be noted in the relevant commits, too). The remaining issues are 2574 (Wrong assumptions for LambertW(-1) ), 2609 (core/test_priority error under Python 3 ), 2611 (tensor/index_methods errors in Python 3 ). These equate to two failures when running tests and one failure for the doctests (actually 3 separate issues but all in one file). Anything else is "unknown".

Contributor

vperic commented Aug 17, 2011

And the issue tracker is alive again. So, this fixes issue 2605, 2608, 2610, 2612 (this should be noted in the relevant commits, too). The remaining issues are 2574 (Wrong assumptions for LambertW(-1) ), 2609 (core/test_priority error under Python 3 ), 2611 (tensor/index_methods errors in Python 3 ). These equate to two failures when running tests and one failure for the doctests (actually 3 separate issues but all in one file). Anything else is "unknown".

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Aug 17, 2011

Member

Make a note of this pull request on all those issues, please.

Member

asmeurer commented Aug 17, 2011

Make a note of this pull request on all those issues, please.

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Aug 17, 2011

Member

Once again, very good commit messages.

Member

asmeurer commented Aug 17, 2011

Once again, very good commit messages.

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Aug 17, 2011

Member

Other than my comments, the changes look good. I still need to play around with the 2to3 script, and also run the tests.

Member

asmeurer commented Aug 17, 2011

Other than my comments, the changes look good. I still need to play around with the 2to3 script, and also run the tests.

@vperic

This comment has been minimized.

Show comment
Hide comment
@vperic

vperic Aug 18, 2011

Contributor

I've rebased to address Aaron's comments (and of course, lost them). They were all mostly minor, though, and I replied to each one before rebasing (so Aaron will get the mails and can confirm it was fixed). Of course, any further comments/testing is appreciated.

I've also ran the tests under Python 3.1 and the output is the same as for 3.2 (minus the doctest differences, as noted in [this][1] discussion), so that's good. I'd still really like it if someone could test this under Windows (and Mac too, but that is more likely to be fine). I don't really expect problems, but there could be something related to the printers or somesuch.

[1] vperic/sympy@404e19d

EDIT: Actually, I just noticed a large bit of code got in which produce a couple of trivial merge conflicts, so I've rebased the whole pull request on top of latest master.

Contributor

vperic commented Aug 18, 2011

I've rebased to address Aaron's comments (and of course, lost them). They were all mostly minor, though, and I replied to each one before rebasing (so Aaron will get the mails and can confirm it was fixed). Of course, any further comments/testing is appreciated.

I've also ran the tests under Python 3.1 and the output is the same as for 3.2 (minus the doctest differences, as noted in [this][1] discussion), so that's good. I'd still really like it if someone could test this under Windows (and Mac too, but that is more likely to be fine). I don't really expect problems, but there could be something related to the printers or somesuch.

[1] vperic/sympy@404e19d

EDIT: Actually, I just noticed a large bit of code got in which produce a couple of trivial merge conflicts, so I've rebased the whole pull request on top of latest master.

@vperic

This comment has been minimized.

Show comment
Hide comment
@vperic

vperic Aug 18, 2011

Contributor

Oh, note that there's a whitespace code quality failure under Python 3 code. This is a change done by 2to3 and I haven't found a way to work around it. I've reported this upstream[1](Aaron I also cc-ed you there) but there hasn't been any response.

[1] http://bugs.python.org/issue12771

Contributor

vperic commented Aug 18, 2011

Oh, note that there's a whitespace code quality failure under Python 3 code. This is a change done by 2to3 and I haven't found a way to work around it. I've reported this upstream[1](Aaron I also cc-ed you there) but there hasn't been any response.

[1] http://bugs.python.org/issue12771

@@ -150,13 +150,12 @@ gray-scale because we have applied the default color gradient uniformly for
each color component. When defining a color scheme in this way, you might want
to supply a color gradient as well:
- >>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5),
- ................ (0.1,0.1,0.9), (0.9,0.1,0.1)
+ >>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5), (0.1,0.1,0.9), (0.9,0.1,0.1)

This comment has been minimized.

@smichr

smichr Aug 18, 2011

Member

to avoid the long line can this be

>>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5),
... (0.1,0.1,0.9), (0.9,0.1,0.1)
@smichr

smichr Aug 18, 2011

Member

to avoid the long line can this be

>>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5),
... (0.1,0.1,0.9), (0.9,0.1,0.1)

This comment has been minimized.

@vperic

vperic Aug 18, 2011

Contributor

Actually, the line is just one character over 80 so I think it's fine. I can change it though, it's not a problem.

@vperic

vperic Aug 18, 2011

Contributor

Actually, the line is just one character over 80 so I think it's fine. I can change it though, it's not a problem.

This comment has been minimized.

@smichr

smichr Aug 18, 2011

Member

never mind. I can go either way.

@smichr

smichr Aug 18, 2011

Member

never mind. I can go either way.

@smichr

View changes

doc/src/tutorial.txt
@@ -146,7 +146,7 @@ and the denominator, so Rational(1,2) represents 1/2, Rational(5,2) 5/2 and so o
proceed with caution while working with python int's since they truncate
integer division, and that's why::

This comment has been minimized.

@smichr

smichr Aug 18, 2011

Member

how about updating the text and example to say something like

...since in version 3, the ratio of two ints is a Python float (not a SymPy Float)

``python

1/2 #doctest: +SKIP
0.5

and in previous versions (unless division is imported from future) the ratio of two ints is a truncated int

>>> 1/2 #doctest: +SKIP
0

In neither case is a SymPy Number returned.

@smichr

smichr Aug 18, 2011

Member

how about updating the text and example to say something like

...since in version 3, the ratio of two ints is a Python float (not a SymPy Float)

``python

1/2 #doctest: +SKIP
0.5

and in previous versions (unless division is imported from future) the ratio of two ints is a truncated int

>>> 1/2 #doctest: +SKIP
0

In neither case is a SymPy Number returned.

This comment has been minimized.

@vperic

vperic Aug 18, 2011

Contributor

Ok, I'll add another commit (as this is going a bit beyond the scope of the current changes) with this. I'm not sure how to phrase this exactly so I'm just going to copy what you used; if you have a better idea you can push it somewhere and I'll cherry-pick it onto my branch.

@vperic

vperic Aug 18, 2011

Contributor

Ok, I'll add another commit (as this is going a bit beyond the scope of the current changes) with this. I'm not sure how to phrase this exactly so I'm just going to copy what you used; if you have a better idea you can push it somewhere and I'll cherry-pick it onto my branch.

This comment has been minimized.

@smichr

smichr Aug 18, 2011

Member

I agree with your scope sentiment. I'll make the mod and enter a pull
request to your branch.

@smichr

smichr Aug 18, 2011

Member

I agree with your scope sentiment. I'll make the mod and enter a pull
request to your branch.

This comment has been minimized.

@vperic

vperic Aug 18, 2011

Contributor

Great, thanks! You can just push the change somewhere and I'll cherry-pick it from you, you don't need to bother with the pull request machinery.

@vperic

vperic Aug 18, 2011

Contributor

Great, thanks! You can just push the change somewhere and I'll cherry-pick it from you, you don't need to bother with the pull request machinery.

@smichr

View changes

doc/src/tutorial.txt
-So that things pretty print. See the :ref:`printing-tutorial` section below. If you have
-a unicode font installed, your output may look a little different (it will look slightly
-nicer).
+So that things pretty print. See the :ref:`printing-tutorial` section below.

This comment has been minimized.

@smichr

smichr Aug 18, 2011

Member

'This will make things look pretty when printed.'

@smichr

smichr Aug 18, 2011

Member

'This will make things look pretty when printed.'

This comment has been minimized.

@vperic

vperic Aug 18, 2011

Contributor

Ok. Changed that first sentance to "This will make things look better when printed." (I feel that sounds, well, better, than using "pretty").

@vperic

vperic Aug 18, 2011

Contributor

Ok. Changed that first sentance to "This will make things look better when printed." (I feel that sounds, well, better, than using "pretty").

@smichr

View changes

sympy/ntheory/factor_.py
>>> set([igcd(pow(a, M, n) - 1, n) for a in range(2, 256) if
... igcd(pow(a, M, n) - 1, n) != n])
set([1009])
But does aM % d for every divisor of n give 1?
- >>> aM = pow(a, M, n)
+ >>> aM = pow(256, M, n)

This comment has been minimized.

@smichr

smichr Aug 18, 2011

Member

Does the loop variable go to the last indicated value in range in python 3? Because in 2.7 the value of a at the end of the loop is 255. So to be explicit (and consistent with intent) that 256 should be 255 in L463

@smichr

smichr Aug 18, 2011

Member

Does the loop variable go to the last indicated value in range in python 3? Because in 2.7 the value of a at the end of the loop is 255. So to be explicit (and consistent with intent) that 256 should be 255 in L463

This comment has been minimized.

@vperic

vperic Aug 18, 2011

Contributor

No, the behaviour is the same, good catch.

@vperic

vperic Aug 18, 2011

Contributor

No, the behaviour is the same, good catch.

@vperic

This comment has been minimized.

Show comment
Hide comment
@vperic

vperic Aug 18, 2011

Contributor

Thanks for the review, Chris. I've incorporated the changes in the relevant commits but I'll hold off on pushing for the moment in case someone else wants to weight in on the wording for the tutorial or something else.

Also, you run Windows I believe? Would you mind testing the use2to3 script? It should work but rather safe than sorry. It should work with Python 2.7. Of course, it'd also be great if you could run the tests under Python 3 too, but I understand that it can be a chore. Thanks in any case!

Contributor

vperic commented Aug 18, 2011

Thanks for the review, Chris. I've incorporated the changes in the relevant commits but I'll hold off on pushing for the moment in case someone else wants to weight in on the wording for the tutorial or something else.

Also, you run Windows I believe? Would you mind testing the use2to3 script? It should work but rather safe than sorry. It should work with Python 2.7. Of course, it'd also be great if you could run the tests under Python 3 too, but I understand that it can be a chore. Thanks in any case!

@smichr

This comment has been minimized.

Show comment
Hide comment
@smichr

smichr Aug 18, 2011

Member

I'll see what I can do.

Member

smichr commented Aug 18, 2011

I'll see what I can do.

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Aug 18, 2011

Member

Regarding the whitespace issue, that will likely take forever to fix upstream, so for now, let's just have use2to3 run the strip_whitespace utility.

Member

asmeurer commented Aug 18, 2011

Regarding the whitespace issue, that will likely take forever to fix upstream, so for now, let's just have use2to3 run the strip_whitespace utility.

vperic added some commits Jul 22, 2011

utilities/runtests: Fix doctest runner for Python 3
In Python 3, the _load_testfile method has a fourth argument, encoding.
As we already use this, just pass it to the function when under Python
3. However, we then try to decode a str (because we specified
an encoding) which is wrong, so set the encoding to None in Python 3. We
cannot just use None as an encoding as Python 2 relies on the decode
step.

This error only appeared when running .txt doctests, as the usual
doctests use a different codepath.
doc/src/gotchas: Make type() doctest Python 3 compatible
In Python 2, type(float) returns "<type 'float'>", but in Python 3 it
returns "<class 'float'>". This confuses the doctest which must match
output exactly. Use the ellipsis syntax to avoid this. See also commit
b457bee: Make some doctests Python 3 compatible.
doc/../evalf.txt: Skip some doctests related to float()
In Python 3, floats have a higher precision by default and it is not
possible to override it. This is a problem for doctests, which rely on
matching output exactly. As the purpose of these doctests is to show
limitations in Python floats, we can't just convert them to the more
precise SymPy Floats. Fix by skipping the four affected doctests.
utilities/runtest: Wrap a str.encode with a version check
Commit f75a101 (Fix the doctest runner in Python 2.5 with utf-8 files)
introduced the _indent method from upstream. In Python 3, this converts
a (unicode) string to bytes, which don't support regex, thus crashing
when there's a doctest failure (that's the only time this function is
called). Wrap the encode code with a version check and enter it only
under Python 2.
ntheory/factor_: Don't use reduce in doctest
2to3 crashes when ran on a doctest containing reduce(). This is
an upstream problem (issue 12611). Replace the only use of this in our
doctests with a for cycle. This fixes issue #2605.
Fix 2to3 TokenError parsing errors
2to3 reports some errors of the type "TokenError: ('EOF in multi-line
statement', ...)" and can't parse those docstrings. Fix these by
correctly using multi-line strings and statements in doctests.
physics/wigner: Explicitly cast range() arguments to int
In Python 2, a SymPy Float could be used as an argument of range(). This
is no longer possible in Python 3. There are two occurances of this in
wigner.py. In the first, a function which expected an integer (per the
doctest) got a Float and then called range() on it; in the second,
range() was called directly on Floats. Fix by explicitly casting to int.
ntheory/factor_: Fix namespace leak from list comprehension
In Python 3, variables are no longer in the namespace after being used
in a list comprehension. Fix one doctest to directly use a number
instead of a variable.
doc/src/*.txt: Use init_printing() instead of setting the displayhook
Some .txt doctests were setting the sys.displayhook to pprint which
produced subtle errors in Python 3 (printing an extra "None" in some
cases). Instead, use the init_printing() function from
interactive.printing. It is called by default with use_unicode=false,
to match the expected output in the files.

These errors only appeared in tutorial.txt and matrices.txt, but use
init_printing() in four other files which were also setting the
displayhook.

Also skip a doctest in the tutorial demonstrating the old-style
division which no longer exists in Python 3 and modify two doctests in
matrices.txt not to expect a result of None (which wasn't strictly
correct).
printing/printer: Raise AttributeError in a property
The hasattr() function is defined to call getattr() and see if an
exception is raised (in which case the attribute doesn't exist). This
has been changed in Python 3.2 to catch only AttributeErrors and not
all kinds of exceptions. See also issue #2608.

A property in printer.py checked for a key and so could raise a
KeyError, which now wouldn't be caught by hasattr(). Refactor to raise
an AttributeError if the key doesn't exist. This bug was caught by a
test in utilities/tests/test_pickling.
matrices.py: Raise AttributeError in a property
The hasattr() function is defined to call getattr() and see if an
exception is raised (in which case the attribute doesn't exist). This
has been changed in Python 3.2 to catch only AttributeErrors and not all
kinds of exceptions. See also issue #2608 and the previous commit.

The property D ("Dirac conjugation") could raise a ShapeError, which now
wouldn't be caught by hasattr(). Wrap the matrix multiplication with a
try/except statement that catches ShapeError and returns AttributeError
instead. Also change a relevant test to expect an AttributeError now.
Add bin/use2to3 script
SymPy needs a 2to3 run to be usable in Python 3. Unfortunately, running
2to3 on mpmath (which is already compatible) produces garbage code. To
avoid this, we first copy all files (except those from mpmath) to a
"sympy-py3k" directory, run 2to3 on them and then copy over the files
from mpmath. One can then use SymPy normally from the sympy-py3k
directory under Python 3. As running 2to3 is a slow process, we try to
note which files have been updated since the last run and only process
those. Also add "sympy-py3k" to .gitignore.

Finally, this is a first draft of the script. As such, there are several
TODOs which note areas of possible further improvement.
combinatorics/permutations: Use floor division
Some code was using the ambiguous division operator on integers. This
produces floats by default in Python 3 (1.0 as opposed to 1) which
cannot be used as list indices. Fix by using floor division (//) where
appropriate. A doctest was also failing, it expected an implicit cast to
int (1.0 to 1 automatically).

Also remove some redundant casts to int, factorial() returns an int
always.
utilities/runtest: Make findout_terminal_width Python 3 compatible
Commit 76d0046 added a function, findout_terminal_width. This function
relies on regexing the stdout, which is of type str in Python 2. In
Python 3 it is a 'bytes' object and it's not possible to regex it, which
then crashes the doctest runner. Fix by checking if we are under Python
3 and decoding from "utf-8" if that is the case.
quantum/state: Use floor division in doctest
A doctest was using the ambiguous division operator (/). Because the
expected result was floor division, use the unambiguous floor division
operator (//). This removes errors under Python 3 and fixes issue #2610.
quantum/__init__: Change imports syntax for Python 3 compatibility
The __init__.py file for quantum uses some importing magic so that both
"from quantum import *" and "from quantum import State" to work. This
fails under Python 3 because some underlying rules seem to have changed.
The likely cause is that the module names shadow function names (or
vice-versa). Fix by directly import __all__ from the affected modules. A
better fix might be to change the module names, but this is a
backward-incompatible change and this workaround is equivalent
functionally.
@vperic

This comment has been minimized.

Show comment
Hide comment
@vperic

vperic Aug 19, 2011

Contributor

Ok. I've rebased again, changed one commit to skip doctests rather than use the ellipsis syntax (per Aaron's comments here[1]). We were also talking about the use2to3 script, you can see the discussion here[2](yes, the hidden discussions are probably a consequence of me rebasing so often but what can I say, I like to have a clean history), but these changes could go in later too.

I've also added one more commit from Chris improving the tutorial.txt file a bit. @smichr, I edited your commit message to be a bit more informative, I hope it's ok? You also seem to have based your work on an older branch (porting4-2to3 as opposed to porting 4; yes, the names are a bit unfortunate) so there were a few conflicts but I think I did it right.

I'm going on a trip and I won't be able to edit anything for some time, so I'd prefer it if this could go in right now (@rlamy, if you've got the time, I think your ack would be enough to have this in). The improvements to use2to3 ([2] and others) can be done later.

[1] vperic/sympy@3100c28#commitcomment-537246
[2] vperic/sympy@7de283c#commitcomment-537275

Contributor

vperic commented Aug 19, 2011

Ok. I've rebased again, changed one commit to skip doctests rather than use the ellipsis syntax (per Aaron's comments here[1]). We were also talking about the use2to3 script, you can see the discussion here[2](yes, the hidden discussions are probably a consequence of me rebasing so often but what can I say, I like to have a clean history), but these changes could go in later too.

I've also added one more commit from Chris improving the tutorial.txt file a bit. @smichr, I edited your commit message to be a bit more informative, I hope it's ok? You also seem to have based your work on an older branch (porting4-2to3 as opposed to porting 4; yes, the names are a bit unfortunate) so there were a few conflicts but I think I did it right.

I'm going on a trip and I won't be able to edit anything for some time, so I'd prefer it if this could go in right now (@rlamy, if you've got the time, I think your ack would be enough to have this in). The improvements to use2to3 ([2] and others) can be done later.

[1] vperic/sympy@3100c28#commitcomment-537246
[2] vperic/sympy@7de283c#commitcomment-537275

doc/src/tutorial: Misc improvements to the documentation
Improve the explanation of the difference between SymPy numbers and
Python numbers and other small changes.
@smichr

This comment has been minimized.

Show comment
Hide comment
@smichr

smichr Aug 19, 2011

Member

Aaron said it looked fine; I gave it a once over and made some comments; you said that the whitespace thing can wait, so I'm going to push this if all tests pass.

Member

smichr commented Aug 19, 2011

Aaron said it looked fine; I gave it a once over and made some comments; you said that the whitespace thing can wait, so I'm going to push this if all tests pass.

@smichr

This comment has been minimized.

Show comment
Hide comment
@smichr

smichr Aug 19, 2011

Member

ok tests pass under 2.7; I'll try in 3.2

Member

smichr commented Aug 19, 2011

ok tests pass under 2.7; I'll try in 3.2

@smichr

This comment has been minimized.

Show comment
Hide comment
@smichr

smichr Aug 19, 2011

Member

Hmmm...when I start python 3.2 I can't import sympy:

>>> import sympy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\__init__.py", line 20, in <module>
    from sympy.core import *
  File "sympy\core\__init__.py", line 4, in <module>
    from sympify import sympify
ImportError: No module named sympify
Member

smichr commented Aug 19, 2011

Hmmm...when I start python 3.2 I can't import sympy:

>>> import sympy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\__init__.py", line 20, in <module>
    from sympy.core import *
  File "sympy\core\__init__.py", line 4, in <module>
    from sympify import sympify
ImportError: No module named sympify
@vperic

This comment has been minimized.

Show comment
Hide comment
@vperic

vperic Aug 19, 2011

Contributor

Right, you need to use the "use2to3" script. This will create a "sympy-py3k" directory that's a copy of the whole sympy structure, just Python 3 compatible; you can then use sympy from that directory normally. This of course needs to be mentioned in README and other places too, for now lets consider Python 3 support a "developer" feature.

Contributor

vperic commented Aug 19, 2011

Right, you need to use the "use2to3" script. This will create a "sympy-py3k" directory that's a copy of the whole sympy structure, just Python 3 compatible; you can then use sympy from that directory normally. This of course needs to be mentioned in README and other places too, for now lets consider Python 3 support a "developer" feature.

@rlamy

This comment has been minimized.

Show comment
Hide comment
@rlamy

rlamy Aug 19, 2011

Member

Actually, I get the same problem even when I make sure that python3 does import the converted version. For instance:

ronan@ronan-desktop:~/Projets/sympy-git/sympy-py3k$ python3 bin/doctest 
Traceback (most recent call last):
  File "bin/doctest", line 51, in <module>
    import sympy
  File "/media/sda2/Boulot/Projets/sympy-git/sympy-py3k/sympy/__init__.py", line 20, in <module>
    from sympy.core import *
  File "/media/sda2/Boulot/Projets/sympy-git/sympy-py3k/sympy/core/__init__.py", line 4, in <module>
    from sympify import sympify
ImportError: No module named sympify

It seems that use2to3 doesn't convert implicit relative imports (e.g. from sympify import *) to explicit ones (i.e. from .sympify import *).

Apart from that, everything looks good.

Member

rlamy commented Aug 19, 2011

Actually, I get the same problem even when I make sure that python3 does import the converted version. For instance:

ronan@ronan-desktop:~/Projets/sympy-git/sympy-py3k$ python3 bin/doctest 
Traceback (most recent call last):
  File "bin/doctest", line 51, in <module>
    import sympy
  File "/media/sda2/Boulot/Projets/sympy-git/sympy-py3k/sympy/__init__.py", line 20, in <module>
    from sympy.core import *
  File "/media/sda2/Boulot/Projets/sympy-git/sympy-py3k/sympy/core/__init__.py", line 4, in <module>
    from sympify import sympify
ImportError: No module named sympify

It seems that use2to3 doesn't convert implicit relative imports (e.g. from sympify import *) to explicit ones (i.e. from .sympify import *).

Apart from that, everything looks good.

@vperic

This comment has been minimized.

Show comment
Hide comment
@vperic

vperic Aug 19, 2011

Contributor

Huh, that's strange. So it doesn't work at all for you in Python 3? The "import" filter should be getting ran automatically (and is for me). What happens if you run it manually in the sympy-py3k directory, does that make it work ("2to3 -w -n -f import ./")?

Contributor

vperic commented Aug 19, 2011

Huh, that's strange. So it doesn't work at all for you in Python 3? The "import" filter should be getting ran automatically (and is for me). What happens if you run it manually in the sympy-py3k directory, does that make it work ("2to3 -w -n -f import ./")?

@rlamy

This comment has been minimized.

Show comment
Hide comment
@rlamy

rlamy Aug 19, 2011

Member

This was apparently just a fluke. My first bin/use2to3 run missed some of the files. I deleted sympy-py3k/ and tried again and now it works.

Member

rlamy commented Aug 19, 2011

This was apparently just a fluke. My first bin/use2to3 run missed some of the files. I deleted sympy-py3k/ and tried again and now it works.

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Aug 19, 2011

Member

Good thing, because from .module import * doesn't work in Python 2.5.

It does sound like there might be a bug in use2to3 though.

By the way, If all my comments have been addressed and tests pass everywhere, I am +1 to merge.

Member

asmeurer commented Aug 19, 2011

Good thing, because from .module import * doesn't work in Python 2.5.

It does sound like there might be a bug in use2to3 though.

By the way, If all my comments have been addressed and tests pass everywhere, I am +1 to merge.

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Aug 21, 2011

Member

So I finally got around to testing this. Some comments:

  • I still think that the shebang line for use2to3 should be /usr/bin/env python3. That way, I can just type ./bin/use2to3, and it will do the right thing.
  • The tool gave me the following warnings/errors, which I'm assuming you know about

RefactoringTool: Warnings/messages while refactoring:
RefactoringTool: ### In file sympy-py3k/./doc/src/modules/polys/wester.txt ###
RefactoringTool: Line 396: You should use a for loop here
RefactoringTool: There were 2 errors:
RefactoringTool: Can't parse docstring in sympy-py3k/./sympy/utilities/codegen.py line 922: ParseError: bad token: type=55, value=' ', context=('', (922, 40))
RefactoringTool: Can't parse docstring in sympy-py3k/./doc/src/gotchas.txt line 415: ParseError: bad input: type=1, value='x', context=('', (415, 1))
  • If I run isympy (in Python 3), I get:
Traceback (most recent call last):
  File "./bin/isympy", line 163, in <module>
    main()
  File "./bin/isympy", line 159, in main
    from sympy.interactive import init_session
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/__init__.py", line 20, in <module>
    from sympy.core import *
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/__init__.py", line 4, in <module>
    from .sympify import sympify
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/sympify.py", line 5, in <module>
    from .core import all_classes as sympy_classes
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/core.py", line 2, in <module>
    from sympy.core.compatibility import cmp
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/compatibility.py", line 133, in <module>
    import builtins
ImportError: No module named built-ins

This is assumedly because it's still running in Python 2. Therefore, I think the tool should change all shebang lines that it encounters to /usr/bin/env python3.

  • Here are the test and doctest failures I got in Python 3.2, in case there's anything new to you:

Doctests

File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/tensor/index_methods.py", line 298, in sympy.tensor.index_methods.get_contraction_structure
Failed example:
    get_contraction_structure(x[i]*y[i] + A[j, j])
Expected:
    {(i,): set([x[i]*y[i]]), (j,): set([A[j, j]])}
Got:
    {(j,): set([A[j, j]]), (i,): set([x[i]*y[i]])}
**********************************************************************
File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/tensor/index_methods.py", line 311, in sympy.tensor.index_methods.get_contraction_structure
Failed example:
    sorted(d[x[i, i]*y[j, j]])  # factors are contracted ``first''
Exception raised:
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/doctest.py", line 1253, in __run
        compileflags, 1), test.globs)
      File "<doctest sympy.tensor.index_methods.get_contraction_structure[10]>", line 1, in <module>
        sorted(d[x[i, i]*y[j, j]])  # factors are contracted ``first''
    TypeError: unorderable types: dict() < dict()
**********************************************************************
File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/tensor/index_methods.py", line 324, in sympy.tensor.index_methods.get_contraction_structure
Failed example:
    d[x[i]*(A[i, j]*x[j] + y[i])]
Exception raised:
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/doctest.py", line 1253, in __run
        compileflags, 1), test.globs)
      File "<doctest sympy.tensor.index_methods.get_contraction_structure[14]>", line 1, in <module>
        d[x[i]*(A[i, j]*x[j] + y[i])]
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/interactive/printing.py", line 17, in displayhook
        print(stringify_func(arg))
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 517, in sstrrepr
        s = p.doprint(expr)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/printer.py", line 227, in doprint
        return self._str(self._print(expr))
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/printer.py", line 251, in _print
        return getattr(self, printmethod)(expr, *args)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 189, in _print_list
        return "[%s]"%self.stringify(expr, ", ")
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 30, in stringify
        return sep.join([self.parenthesize(item, level) for item in args])
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 30, in <listcomp>
        return sep.join([self.parenthesize(item, level) for item in args])
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 27, in parenthesize
        return self._print(item)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/printer.py", line 251, in _print
        return getattr(self, printmethod)(expr, *args)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 82, in _print_dict
        keys.sort( key=cmp_to_key(Basic.compare_pretty) )
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/compatibility.py", line 119, in __lt__
        return mycmp(self.obj, other.obj) < 0
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/basic.py", line 262, in compare_pretty
        return cmp(a,b)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/compatibility.py", line 137, in cmp
        return (a > b) - (a < b)
    TypeError: unorderable types: NoneType() > tuple()

Regular Tests

  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/solvers/tests/test_solvers.py", line 230, in test_tsolve
    assert solve(3*x+5+2**(-5*x+3), x) in [
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/solvers/solvers.py", line 563, in solve
    solution = _solve(f, *symbols, **flags)
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/solvers/solvers.py", line 861, in _solve
    result = list(map(simplify, result))
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/simplify/simplify.py", line 1647, in simplify
    expr1 = cancel(powsimp(expr))
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/simplify/simplify.py", line 1218, in powsimp
    return Add(*[powsimp(t, deep, combine, force) for t in expr.args])
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/simplify/simplify.py", line 1218, in <listcomp>
    return Add(*[powsimp(t, deep, combine, force) for t in expr.args])
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/simplify/simplify.py", line 1262, in powsimp
    bpos = b.is_positive
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/assumptions.py", line 155, in getit
    return self._what_known_about(fact)
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/assumptions.py", line 383, in _what_known_about
    a = _real_cmp0_table[k][cmp(self.evalf(), 0)]
KeyError: (0 < 6.10079316127918 + 2.7219358435534*I) - (6.10079316127918 + 2.7219358435534*I < 0)

____________________________________________________________________________________________________________________________________________________________________________________________________________
_____________________________________________________________________________ sympy/core/tests/test_arit.py:test_Add_primitive _____________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_arit.py", line 1190, in test_Add_primitive
    assert (3*x + 6).primitive() == (3, x + 2)
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
_______________________________________________________________________________ sympy/core/tests/test_exprtools.py:test_Term _______________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_exprtools.py", line 72, in test_Term
    assert Term((2*x + 2)*(3*x + 6)**2) == Term(18, Factors({x + 1: 1, x + 2: 2}), Factors({}))
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
____________________________________________________________________________ sympy/core/tests/test_exprtools.py:test_gcd_terms _____________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_exprtools.py", line 77, in test_gcd_terms
    assert _gcd_terms(f) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
_______________________________________________________________________________ sympy/core/tests/test_match.py:test_complex ________________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_match.py", line 123, in test_complex
    assert (a+b*I).match(x+y*I) == {x : a, y : b}
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
________________________________________________________________________________ sympy/core/tests/test_priority.py:test_div ________________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_priority.py", line 88, in test_div
    assert l/h == h/l == 'high'
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
________________________________________________________________ sympy/utilities/tests/test_code_quality.py:test_whitespace_and_exceptions _________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/utilities/tests/test_code_quality.py", line 110, in test_whitespace_and_exceptions
    check_directory_tree(SYMPY_PATH, test, exclude)
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/utilities/tests/test_code_quality.py", line 64, in check_directory_tree
    file_check(fname)
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/utilities/tests/test_code_quality.py", line 86, in test
    assert False, message_space % (fname, idx+1)
AssertionError: File contains trailing whitespace: /users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/ntheory/factor_.py, line 320.
  • When this gets in, see if my recent fix to the test runner makes the skip messages appear correctly when you run the tests with -v in Python 3. Ditto for listing XPASSed tests at the end.
  • Regarding that last failure, like I said, just run the strip_whitepace utility in use2to3.
Member

asmeurer commented Aug 21, 2011

So I finally got around to testing this. Some comments:

  • I still think that the shebang line for use2to3 should be /usr/bin/env python3. That way, I can just type ./bin/use2to3, and it will do the right thing.
  • The tool gave me the following warnings/errors, which I'm assuming you know about

RefactoringTool: Warnings/messages while refactoring:
RefactoringTool: ### In file sympy-py3k/./doc/src/modules/polys/wester.txt ###
RefactoringTool: Line 396: You should use a for loop here
RefactoringTool: There were 2 errors:
RefactoringTool: Can't parse docstring in sympy-py3k/./sympy/utilities/codegen.py line 922: ParseError: bad token: type=55, value=' ', context=('', (922, 40))
RefactoringTool: Can't parse docstring in sympy-py3k/./doc/src/gotchas.txt line 415: ParseError: bad input: type=1, value='x', context=('', (415, 1))
  • If I run isympy (in Python 3), I get:
Traceback (most recent call last):
  File "./bin/isympy", line 163, in <module>
    main()
  File "./bin/isympy", line 159, in main
    from sympy.interactive import init_session
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/__init__.py", line 20, in <module>
    from sympy.core import *
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/__init__.py", line 4, in <module>
    from .sympify import sympify
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/sympify.py", line 5, in <module>
    from .core import all_classes as sympy_classes
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/core.py", line 2, in <module>
    from sympy.core.compatibility import cmp
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/compatibility.py", line 133, in <module>
    import builtins
ImportError: No module named built-ins

This is assumedly because it's still running in Python 2. Therefore, I think the tool should change all shebang lines that it encounters to /usr/bin/env python3.

  • Here are the test and doctest failures I got in Python 3.2, in case there's anything new to you:

Doctests

File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/tensor/index_methods.py", line 298, in sympy.tensor.index_methods.get_contraction_structure
Failed example:
    get_contraction_structure(x[i]*y[i] + A[j, j])
Expected:
    {(i,): set([x[i]*y[i]]), (j,): set([A[j, j]])}
Got:
    {(j,): set([A[j, j]]), (i,): set([x[i]*y[i]])}
**********************************************************************
File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/tensor/index_methods.py", line 311, in sympy.tensor.index_methods.get_contraction_structure
Failed example:
    sorted(d[x[i, i]*y[j, j]])  # factors are contracted ``first''
Exception raised:
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/doctest.py", line 1253, in __run
        compileflags, 1), test.globs)
      File "<doctest sympy.tensor.index_methods.get_contraction_structure[10]>", line 1, in <module>
        sorted(d[x[i, i]*y[j, j]])  # factors are contracted ``first''
    TypeError: unorderable types: dict() < dict()
**********************************************************************
File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/tensor/index_methods.py", line 324, in sympy.tensor.index_methods.get_contraction_structure
Failed example:
    d[x[i]*(A[i, j]*x[j] + y[i])]
Exception raised:
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/doctest.py", line 1253, in __run
        compileflags, 1), test.globs)
      File "<doctest sympy.tensor.index_methods.get_contraction_structure[14]>", line 1, in <module>
        d[x[i]*(A[i, j]*x[j] + y[i])]
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/interactive/printing.py", line 17, in displayhook
        print(stringify_func(arg))
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 517, in sstrrepr
        s = p.doprint(expr)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/printer.py", line 227, in doprint
        return self._str(self._print(expr))
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/printer.py", line 251, in _print
        return getattr(self, printmethod)(expr, *args)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 189, in _print_list
        return "[%s]"%self.stringify(expr, ", ")
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 30, in stringify
        return sep.join([self.parenthesize(item, level) for item in args])
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 30, in <listcomp>
        return sep.join([self.parenthesize(item, level) for item in args])
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 27, in parenthesize
        return self._print(item)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/printer.py", line 251, in _print
        return getattr(self, printmethod)(expr, *args)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/printing/str.py", line 82, in _print_dict
        keys.sort( key=cmp_to_key(Basic.compare_pretty) )
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/compatibility.py", line 119, in __lt__
        return mycmp(self.obj, other.obj) < 0
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/basic.py", line 262, in compare_pretty
        return cmp(a,b)
      File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/compatibility.py", line 137, in cmp
        return (a > b) - (a < b)
    TypeError: unorderable types: NoneType() > tuple()

Regular Tests

  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/solvers/tests/test_solvers.py", line 230, in test_tsolve
    assert solve(3*x+5+2**(-5*x+3), x) in [
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/solvers/solvers.py", line 563, in solve
    solution = _solve(f, *symbols, **flags)
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/solvers/solvers.py", line 861, in _solve
    result = list(map(simplify, result))
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/simplify/simplify.py", line 1647, in simplify
    expr1 = cancel(powsimp(expr))
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/simplify/simplify.py", line 1218, in powsimp
    return Add(*[powsimp(t, deep, combine, force) for t in expr.args])
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/simplify/simplify.py", line 1218, in <listcomp>
    return Add(*[powsimp(t, deep, combine, force) for t in expr.args])
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/simplify/simplify.py", line 1262, in powsimp
    bpos = b.is_positive
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/assumptions.py", line 155, in getit
    return self._what_known_about(fact)
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy-py3k/sympy/core/assumptions.py", line 383, in _what_known_about
    a = _real_cmp0_table[k][cmp(self.evalf(), 0)]
KeyError: (0 < 6.10079316127918 + 2.7219358435534*I) - (6.10079316127918 + 2.7219358435534*I < 0)

____________________________________________________________________________________________________________________________________________________________________________________________________________
_____________________________________________________________________________ sympy/core/tests/test_arit.py:test_Add_primitive _____________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_arit.py", line 1190, in test_Add_primitive
    assert (3*x + 6).primitive() == (3, x + 2)
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
_______________________________________________________________________________ sympy/core/tests/test_exprtools.py:test_Term _______________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_exprtools.py", line 72, in test_Term
    assert Term((2*x + 2)*(3*x + 6)**2) == Term(18, Factors({x + 1: 1, x + 2: 2}), Factors({}))
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
____________________________________________________________________________ sympy/core/tests/test_exprtools.py:test_gcd_terms _____________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_exprtools.py", line 77, in test_gcd_terms
    assert _gcd_terms(f) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
_______________________________________________________________________________ sympy/core/tests/test_match.py:test_complex ________________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_match.py", line 123, in test_complex
    assert (a+b*I).match(x+y*I) == {x : a, y : b}
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
________________________________________________________________________________ sympy/core/tests/test_priority.py:test_div ________________________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/core/tests/test_priority.py", line 88, in test_div
    assert l/h == h/l == 'high'
AssertionError
____________________________________________________________________________________________________________________________________________________________________________________________________________
________________________________________________________________ sympy/utilities/tests/test_code_quality.py:test_whitespace_and_exceptions _________________________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/utilities/tests/test_code_quality.py", line 110, in test_whitespace_and_exceptions
    check_directory_tree(SYMPY_PATH, test, exclude)
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/utilities/tests/test_code_quality.py", line 64, in check_directory_tree
    file_check(fname)
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/utilities/tests/test_code_quality.py", line 86, in test
    assert False, message_space % (fname, idx+1)
AssertionError: File contains trailing whitespace: /users/aaronmeurer/documents/python/sympy/sympy/sympy-py3k/sympy/ntheory/factor_.py, line 320.
  • When this gets in, see if my recent fix to the test runner makes the skip messages appear correctly when you run the tests with -v in Python 3. Ditto for listing XPASSed tests at the end.
  • Regarding that last failure, like I said, just run the strip_whitepace utility in use2to3.
@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Aug 21, 2011

Member

When this gets in, see if my recent fix to the test runner makes the skip messages appear correctly when you run the tests with -v in Python 3. Ditto for listing XPASSed tests at the end.

I guess this change is already part of this branch, but it doesn't work. So this will have to be looked into.

Member

asmeurer commented Aug 21, 2011

When this gets in, see if my recent fix to the test runner makes the skip messages appear correctly when you run the tests with -v in Python 3. Ditto for listing XPASSed tests at the end.

I guess this change is already part of this branch, but it doesn't work. So this will have to be looked into.

@rlamy

This comment has been minimized.

Show comment
Hide comment
@rlamy

rlamy Aug 25, 2011

Member

These errors are known. I'm not sure how the shebang lines should be handled, 2to3 doesn't change them, apparently, but I don't know the rationale for that behaviour. In any case, explicitly invoking the scripts with python3 (e.g. python3 bin/doctest) should work everywhere. I'd say that we should worry about it later on and merge it as is.

I'd still like to get confirmation that it works OK on Windows before merging this in though. @smichr?

And BTW, the relative import syntax should work in 2.5.

Member

rlamy commented Aug 25, 2011

These errors are known. I'm not sure how the shebang lines should be handled, 2to3 doesn't change them, apparently, but I don't know the rationale for that behaviour. In any case, explicitly invoking the scripts with python3 (e.g. python3 bin/doctest) should work everywhere. I'd say that we should worry about it later on and merge it as is.

I'd still like to get confirmation that it works OK on Windows before merging this in though. @smichr?

And BTW, the relative import syntax should work in 2.5.

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Aug 25, 2011

Member

Right. It's mostly a convenience thing so that you can type ./sympy-py3k/bin/isympy instead of python3 sympy-py3k/bin/isympy. If you don't have python3 in your env PATH, I don't know how you plan to open Python 3 anyway, but it's trivial to add it, or to call it the hard way if you don't want to. In my experience, 99% of Python 3 installations will add a python3 shortcut.

But I do agree that this can go in without my comments being fixed. Just make sure that they are mentioned in the issues.

And BTW, the relative import syntax should work in 2.5.

Vlad and I discussed this a while back. Apparently due to some bug, relative import * does not work in Python 2.5 (I hope I remember this correctly), and since Python 2.5 is in security fix only mode, it can't be fixed.

Member

asmeurer commented Aug 25, 2011

Right. It's mostly a convenience thing so that you can type ./sympy-py3k/bin/isympy instead of python3 sympy-py3k/bin/isympy. If you don't have python3 in your env PATH, I don't know how you plan to open Python 3 anyway, but it's trivial to add it, or to call it the hard way if you don't want to. In my experience, 99% of Python 3 installations will add a python3 shortcut.

But I do agree that this can go in without my comments being fixed. Just make sure that they are mentioned in the issues.

And BTW, the relative import syntax should work in 2.5.

Vlad and I discussed this a while back. Apparently due to some bug, relative import * does not work in Python 2.5 (I hope I remember this correctly), and since Python 2.5 is in security fix only mode, it can't be fixed.

@rlamy

This comment has been minimized.

Show comment
Hide comment
@rlamy

rlamy Sep 1, 2011

Member

I found a Windows system to test this. Python3 conversion and tests seem to work, so I'm pushing this in.

Vlad and I discussed this a while back. Apparently due to some bug, relative import * does not work in Python 2.5 (I hope I remember this correctly), and since Python 2.5 is in security fix only mode, it can't be fixed.

OK.

Member

rlamy commented Sep 1, 2011

I found a Windows system to test this. Python3 conversion and tests seem to work, so I'm pushing this in.

Vlad and I discussed this a while back. Apparently due to some bug, relative import * does not work in Python 2.5 (I hope I remember this correctly), and since Python 2.5 is in security fix only mode, it can't be fixed.

OK.

rlamy added a commit that referenced this pull request Sep 1, 2011

Merge pull request #558 from vperic/porting4
Porting to Python 3, part 4 ("final")

@rlamy rlamy merged commit 77c3a74 into sympy:master Sep 1, 2011

@vperic

This comment has been minimized.

Show comment
Hide comment
@vperic

vperic Sep 4, 2011

Contributor

Thanks Ronan, everyone. I've closed the relevant issues on the tracker. I've also opened an issue for the requested improvements to bin/use2to3 [1]. If there is something I missed, please comment. I also plan to improve the documentation (so that users actually know that Python 3 is supported), but didn't open an issue for it.

[1] http://code.google.com/p/sympy/issues/detail?id=2673

Contributor

vperic commented Sep 4, 2011

Thanks Ronan, everyone. I've closed the relevant issues on the tracker. I've also opened an issue for the requested improvements to bin/use2to3 [1]. If there is something I missed, please comment. I also plan to improve the documentation (so that users actually know that Python 3 is supported), but didn't open an issue for it.

[1] http://code.google.com/p/sympy/issues/detail?id=2673

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment