Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Python 2 and 3 compatible codebase #2318

Merged
merged 29 commits into from Jul 28, 2013
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c86aa77
Single Python 2 and 3 compatible codebase
flacjacket Jul 22, 2013
c34a96d
Remove use2to3
flacjacket Jul 25, 2013
66857af
Update Travis configuration for Python 3 codebase
flacjacket Jul 25, 2013
02c207b
Fix isympy for use with Python 3
flacjacket Jul 25, 2013
ad38b78
arit test fix
flacjacket Jul 25, 2013
9dd8e15
liealgebra test fix
flacjacket Jul 25, 2013
42bb553
vandermode example fixes
flacjacket Jul 25, 2013
896f9cf
Fix Python 3 doctest runner
flacjacket Jul 25, 2013
20f9323
doctest fix
flacjacket Jul 25, 2013
354b6a9
Merge branch 'master' into single_code_base
flacjacket Jul 25, 2013
2fa98e4
doctest fix
flacjacket Jul 25, 2013
cc2e3f0
Update doctest print function to pass in Python 2
flacjacket Jul 25, 2013
b36abac
Merge branch 'master' into single_code_base
flacjacket Jul 25, 2013
41d97c4
Port sympy/liealgebras/type_b.py
certik Jul 25, 2013
c023171
Add comment on Python 2/3 compatibility fixes
flacjacket Jul 25, 2013
6a09690
Implement u_decode in compatibility, change from PY2 to PY3
flacjacket Jul 25, 2013
86e6024
Remove filter and callable from compatibility file
flacjacket Jul 25, 2013
32636ab
Remove use2to3 references in docs
flacjacket Jul 25, 2013
7700c0f
Remove cmp() from compatibility
flacjacket Jul 25, 2013
8519425
Make setup/setupegg install isympy to isympy3
flacjacket Jul 26, 2013
cc95a49
Python 3 fix in sympy/utilities/runtests.py
flacjacket Jul 26, 2013
593f5c0
Fix import in examples
flacjacket Jul 26, 2013
77f2366
Merge branch 'master' into single_code_base
flacjacket Jul 26, 2013
f6c15ba
Python 3.2 unicode fixes for circuitplot
flacjacket Jul 26, 2013
73bdfd6
Extra print function fixes
flacjacket Jul 26, 2013
113cce5
Add __future__ print_function and division imports
flacjacket Jul 26, 2013
4cf6aa2
Merge branch 'master' into single_code_base
flacjacket Jul 27, 2013
076e414
Stats Python 3 fix-ups
flacjacket Jul 27, 2013
5844d48
Small fix-ups for Python 3
flacjacket Jul 28, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -49,7 +49,6 @@ before_install:
pip install "matplotlib==1.2.1";
fi
install:
- if [[ $TRAVIS_PYTHON_VERSION == '3.2' || $TRAVIS_PYTHON_VERSION == '3.3' ]]; then python bin/use2to3; cd py3k-sympy; fi
- python setup.py install
script:
- bin/test_travis.sh
Expand Down
12 changes: 2 additions & 10 deletions README.rst
Expand Up @@ -110,16 +110,8 @@ SymPy also supports Python 3. If you want to install the latest version in
Python 3, get the Python 3 tarball from
https://pypi.python.org/pypi/sympy/

To build the git version in Python 3, run::

$ ./bin/use2to3

Note that this command only works if you clone from git. When ran, it will
create a new directory, py3k-sympy, which holds a Python 3 compatible version
of the code. SymPy can then be used normally with Python 3 from that directory
(installation, interactive shell, tests, etc.). If you make any changes to
the Python 2 source, just run that command again to update the Python 3
source.
To install the SymPy for Python 3, simply run the above commands with a Python
3 interpreter.

Clean
-----
Expand Down
4 changes: 3 additions & 1 deletion bin/adapt_paths.py
Expand Up @@ -14,6 +14,8 @@
correct.
"""

from __future__ import print_function

from glob import glob
import re
import difflib
Expand All @@ -36,7 +38,7 @@ def fix_file(filename):
fromfile=filename, tofile=filename + ".new", lineterm="")
import sys
for l in d:
print l
print(l)


for x in get_files_mpmath():
Expand Down
92 changes: 47 additions & 45 deletions bin/coverage_doctest.py
Expand Up @@ -17,6 +17,8 @@
If no arguments are given, all files in sympy/ are checked.
"""

from __future__ import print_function

import os
import sys
import re
Expand Down Expand Up @@ -55,13 +57,13 @@

def print_header(name, underline=None, color=None):

print
print()
if color:
print "%s%s%s" % (c_color % colors[color], name, c_normal)
print("%s%s%s" % (c_color % colors[color], name, c_normal))
else:
print name
print(name)
if underline and not color:
print underline*len(name)
print(underline*len(name))


def print_coverage(module_path, c, c_md, c_mdt, c_idt, c_sph, f, f_md, f_mdt,
Expand Down Expand Up @@ -114,14 +116,14 @@ def print_coverage(module_path, c, c_md, c_mdt, c_idt, c_sph, f, f_md, f_mdt,
colors[equal_100_color], sphinx_score, total_members -
total_sphinx, total_members, c_normal)
if verbose:
print '\n' + '-'*70
print module_path
print '-'*70
print('\n' + '-'*70)
print(module_path)
print('-'*70)
else:
if sphinx:
print "%s: %s %s" % (module_path, score_string, sphinx_score_string)
print("%s: %s %s" % (module_path, score_string, sphinx_score_string))
else:
print "%s: %s" % (module_path, score_string)
print("%s: %s" % (module_path, score_string))

if verbose:
print_header('CLASSES', '*', not no_color and big_header_color)
Expand All @@ -132,22 +134,22 @@ def print_coverage(module_path, c, c_md, c_mdt, c_idt, c_sph, f, f_md, f_mdt,
if c_md:
print_header('Missing docstrings', '-', not no_color and small_header_color)
for md in c_md:
print ' * ' + md
print(' * ' + md)
if c_mdt:
print_header('Missing doctests', '-', not no_color and small_header_color)
for md in c_mdt:
print ' * ' + md
print(' * ' + md)
if c_idt:
# Use "# indirect doctest" in the docstring to
# supress this warning.
print_header('Indirect doctests', '-', not no_color and small_header_color)
for md in c_idt:
print ' * ' + md
print '\n Use \"# indirect doctest\" in the docstring to supress this warning'
print(' * ' + md)
print('\n Use \"# indirect doctest\" in the docstring to supress this warning')
if c_sph:
print_header('Not imported into Sphinx', '-', not no_color and small_header_color)
for md in c_sph:
print ' * ' + md
print(' * ' + md)

print_header('FUNCTIONS', '*', not no_color and big_header_color)
if not f:
Expand All @@ -156,27 +158,27 @@ def print_coverage(module_path, c, c_md, c_mdt, c_idt, c_sph, f, f_md, f_mdt,
if f_md:
print_header('Missing docstrings', '-', not no_color and small_header_color)
for md in f_md:
print ' * ' + md
print(' * ' + md)
if f_mdt:
print_header('Missing doctests', '-', not no_color and small_header_color)
for md in f_mdt:
print ' * ' + md
print(' * ' + md)
if f_idt:
print_header('Indirect doctests', '-', not no_color and small_header_color)
for md in f_idt:
print ' * ' + md
print '\n Use \"# indirect doctest\" in the docstring to supress this warning'
print(' * ' + md)
print('\n Use \"# indirect doctest\" in the docstring to supress this warning')
if f_sph:
print_header('Not imported into Sphinx', '-', not no_color and small_header_color)
for md in f_sph:
print ' * ' + md
print(' * ' + md)

if verbose:
print '\n' + '-'*70
print score_string
print('\n' + '-'*70)
print(score_string)
if sphinx:
print sphinx_score_string
print '-'*70
print(sphinx_score_string)
print('-'*70)


def _is_indirect(member, doc):
Expand Down Expand Up @@ -399,7 +401,7 @@ def coverage(module_path, verbose=False, no_color=False, sphinx=True):
m = sys.modules[module_path]
except Exception as a:
# Most likely cause, absence of __init__
print "%s could not be loaded due to %s." % (module_path, repr(a))
print("%s could not be loaded due to %s." % (module_path, repr(a)))
return 0, 0, 0

c_skipped = []
Expand Down Expand Up @@ -546,7 +548,7 @@ def go(sympy_top, file, verbose=False, no_color=False, exact=True, sphinx=True):

return 0, 0, 0
if not os.path.exists(file):
print "File %s does not exist." % file
print("File(%s does not exist." % file)
sys.exit(1)

# Relpath for constructing the module name
Expand Down Expand Up @@ -582,19 +584,19 @@ def go(sympy_top, file, verbose=False, no_color=False, exact=True, sphinx=True):
args = parser.parse_args()

if args.sphinx and not os.path.exists(os.path.join(sympy_top, 'doc', '_build', 'html')):
print """
print("""
Cannot check Sphinx coverage without a documentation build. To build the
docs, run "cd doc; make html". To skip checking Sphinx coverage, pass --no-sphinx.
"""
""")
sys.exit(1)

full_coverage = True

for file in args.path:
file = os.path.normpath(file)
print 'DOCTEST COVERAGE for %s' % (file)
print '='*70
print
print('DOCTEST COVERAGE for %s' % (file))
print('='*70)
print()
doctests, total_sphinx, num_functions = go(sympy_top, file, verbose=args.verbose,
no_color=args.no_color, sphinx=args.sphinx)
if num_functions == 0:
Expand All @@ -611,38 +613,38 @@ def go(sympy_top, file, verbose=False, no_color=False, exact=True, sphinx=True):
sphinx_score = int(sphinx_score)
if total_sphinx > 0:
full_coverage = False
print
print '='*70
print()
print('='*70)

if args.no_color:
print "TOTAL DOCTEST SCORE for %s: %s%% (%s of %s)" % \
(get_mod_name(file, sympy_top), score, doctests, num_functions)
print("TOTAL DOCTEST SCORE for %s: %s%% (%s of %s)" % \
(get_mod_name(file, sympy_top), score, doctests, num_functions))

elif score < 100:
print "TOTAL DOCTEST SCORE for %s: %s%s%% (%s of %s)%s" % \
print("TOTAL DOCTEST SCORE for %s: %s%s%% (%s of %s)%s" % \
(get_mod_name(file, sympy_top), c_color % (colors["Red"]),
score, doctests, num_functions, c_normal)
score, doctests, num_functions, c_normal))

else:
print "TOTAL DOCTEST SCORE for %s: %s%s%% (%s of %s)%s" % \
print("TOTAL DOCTEST SCORE for %s: %s%s%% (%s of %s)%s" % \
(get_mod_name(file, sympy_top), c_color % (colors["Green"]),
score, doctests, num_functions, c_normal)
score, doctests, num_functions, c_normal))

if args.sphinx:
if args.no_color:
print "TOTAL SPHINX SCORE for %s: %s%% (%s of %s)" % \
print("TOTAL SPHINX SCORE for %s: %s%% (%s of %s)" % \
(get_mod_name(file, sympy_top), sphinx_score,
num_functions - total_sphinx, num_functions)
num_functions - total_sphinx, num_functions))

elif sphinx_score < 100:
print "TOTAL SPHINX SCORE for %s: %s%s%% (%s of %s)%s" % \
print("TOTAL SPHINX SCORE for %s: %s%s%% (%s of %s)%s" % \
(get_mod_name(file, sympy_top), c_color % (colors["Red"]),
sphinx_score, num_functions - total_sphinx, num_functions, c_normal)
sphinx_score, num_functions - total_sphinx, num_functions, c_normal))

else:
print "TOTAL SPHINX SCORE for %s: %s%s%% (%s of %s)%s" % \
print("TOTAL SPHINX SCORE for %s: %s%s%% (%s of %s)%s" % \
(get_mod_name(file, sympy_top), c_color % (colors["Green"]),
sphinx_score, num_functions - total_sphinx, num_functions, c_normal)
sphinx_score, num_functions - total_sphinx, num_functions, c_normal))

print
print()
sys.exit(not full_coverage)
8 changes: 5 additions & 3 deletions bin/coverage_report.py
Expand Up @@ -22,6 +22,8 @@
$ bin/coverage_report.py -c
"""
from __future__ import print_function

import os
import re
import sys
Expand Down Expand Up @@ -107,6 +109,6 @@ def make_report(source_dir, report_dir, use_cache=False):

make_report(source_dir, **options.__dict__)

print "The generated coverage report is in covhtml directory."
print "Open %s in your web browser to view the report" % os.sep.join(
'sympy covhtml index.html'.split())
print("The generated coverage report is in covhtml directory.")
print("Open %s in your web browser to view the report" % os.sep.join(
'sympy covhtml index.html'.split()))
2 changes: 2 additions & 0 deletions bin/doctest
Expand Up @@ -7,6 +7,8 @@ The advantage over py.test is that it only depends on sympy and should just
work in any circumstances. See "sympy.dotest?" for documentation.
"""

from __future__ import print_function

# files listed here can be in unix forward slash format with paths
# listed relative to sympy (which contains bin, etc...)
blacklist = []
Expand Down
8 changes: 5 additions & 3 deletions bin/generate_test_list.py
Expand Up @@ -29,6 +29,8 @@
"""

from __future__ import print_function

from glob import glob


Expand Down Expand Up @@ -57,7 +59,7 @@ def get_paths(level=15):
g = [".".join(x.split("/")[:-1]) for x in g]
g = list(set(g))
g.sort()
print "tests = ["
print("tests = [")
for x in g:
print " '%s'," % x
print " ]"
print(" '%s'," % x)
print(" ]")
2 changes: 2 additions & 0 deletions bin/get_sympy.py
@@ -1,5 +1,7 @@
"""Functions to get the correct sympy version to run tests."""

from __future__ import print_function

import os
import sys

Expand Down
34 changes: 18 additions & 16 deletions bin/mailmap_update.py
Expand Up @@ -7,6 +7,8 @@
# - Check doc/src/aboutus.rst
# - Make it easier to update .mailmap or AUTHORS with the correct entries.

from __future__ import print_function

import os
import sys

Expand Down Expand Up @@ -49,32 +51,32 @@

exit1 = False

print blue(filldedent("""Read the text at the top of AUTHORS and the text at
print(blue(filldedent("""Read the text at the top of AUTHORS and the text at
the top of .mailmap for information on how to fix the below errors. If
someone is missing from AUTHORS, add them where they would have been if they
were added after their first pull request was merged ( checkout the merge
commit from the first pull request and see who is at the end of the AUTHORS
file at that commit."""))
file at that commit.""")))

print
print yellow("People who are in AUTHORS but not in git:")
print
print()
print(yellow("People who are in AUTHORS but not in git:"))
print()

for name in sorted(set(authors) - set(git_people)):
if name.startswith("*"):
# People who are in AUTHORS but predate git
predate_git += 1
continue
exit1 = True
print name
print(name)

print
print yellow("People who are in git but not in AUTHORS:")
print
print()
print(yellow("People who are in git but not in AUTHORS:"))
print()

for name in sorted(set(git_people) - set(authors) - set(authors_skip)):
exit1 = True
print name
print(name)

# + 1 because the last newline is stripped by strip()
authors_count = AUTHORS[AUTHORS.find(firstauthor):].strip().count("\n") + 1
Expand All @@ -85,18 +87,18 @@
)
git_count = len(git_people)

print
print yellow("There are {git_count} people in git, and {adjusted_authors_count} "
print()
print(yellow("There are {git_count} people in git, and {adjusted_authors_count} "
"(adjusted) people from AUTHORS".format(git_count=git_count,
adjusted_authors_count=adjusted_authors_count))
adjusted_authors_count=adjusted_authors_count)))

if git_count != adjusted_authors_count:
error("These two numbers are not the same!")
else:
print
print green(filldedent("""Congratulations. The AUTHORS and .mailmap files
print()
print(green(filldedent("""Congratulations. The AUTHORS and .mailmap files
appear to be up to date. You should now verify that doc/src/aboutus has %s
people.""" % authors_count))
people.""" % authors_count)))

if exit1:
sys.exit(1)
2 changes: 2 additions & 0 deletions bin/py.bench
Expand Up @@ -2,6 +2,8 @@

# hook in-tree SymPy into Python path, if possible
# TODO this should be shared with isympy
from __future__ import print_function

import os
import sys

Expand Down