Single Python 2 and 3 compatible codebase #2318

Merged
merged 29 commits into from Jul 28, 2013
Commits
Jump to file
The table of contents is too big for display.
+5,059 −4,325
Split
View
@@ -37,7 +37,6 @@ my/
# Files generated by setup.py
dist/
build/
-py3k-sympy/
# Files generated by setupegg.py
sympy.egg-info/
View
@@ -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
View
@@ -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
-----
View
@@ -14,6 +14,8 @@
correct.
"""
+from __future__ import print_function
+
from glob import glob
import re
import difflib
@@ -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():
@@ -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
@@ -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,
@@ -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)
@@ -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:
@@ -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):
@@ -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 = []
@@ -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
@@ -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:
@@ -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)
@@ -22,6 +22,8 @@
$ bin/coverage_report.py -c
"""
+from __future__ import print_function
+
import os
import re
import sys
@@ -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()))
View
@@ -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 = []
@@ -29,6 +29,8 @@
"""
+from __future__ import print_function
+
from glob import glob
@@ -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(" ]")
View
@@ -1,5 +1,7 @@
"""Functions to get the correct sympy version to run tests."""
+from __future__ import print_function
+
import os
import sys
View
@@ -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
@@ -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
@@ -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)
Oops, something went wrong.