From 8dff14430e779a29f90420f6d3093d4313c2db50 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 22 Aug 2017 14:18:23 -0700 Subject: [PATCH] tools: Remove old python 3 compatibility checker. Now that we've migrated over to Python 3, this tool is no longer required. Fixes #6217. --- docs/testing.md | 24 ------ requirements/README.md | 4 +- requirements/dev.txt | 2 - requirements/dev_lock.txt | 3 +- requirements/py3k.txt | 4 - tools/check-py3 | 134 ----------------------------- tools/test-all | 2 - tools/travis/setup-static-analysis | 9 +- tools/travis/static-analysis | 2 - 9 files changed, 5 insertions(+), 179 deletions(-) delete mode 100644 requirements/py3k.txt delete mode 100755 tools/check-py3 diff --git a/docs/testing.md b/docs/testing.md index 49dcab06c3..1a9e482317 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -200,27 +200,3 @@ Firebug for Firefox is also pretty good. They both have profilers, but Chrome's is a sampling profiler while Firebug's is an instrumenting profiler. Using them both can be helpful because they provide different information. - -## Python 3 Compatibility - -Zulip is working on supporting Python 3, and all new code in Zulip -should be Python 2+3 compatible. We have converted most of the codebase -to be compatible with Python 3 using a suite of 2to3 conversion tools -and some manual work. In order to avoid regressions in that -compatibility as we continue to develop new features in Zulip, we have a -special tool, `tools/check-py3`, which checks all code for Python 3 -syntactic compatibility by running a subset of the automated migration -tools and checking if they trigger any changes. `tools/check-py3` is run -automatically in Zulip's Travis CI tests (in the 'static-analysis' -build) to avoid any regressions, but is not included in `test-all` since -it is quite slow. - -To run `tools/check-py3`, you need to install the `modernize` and -`future` Python packages (which are included in -`requirements/py3k.txt`, which itself is included in -`requirements/dev.txt`, so you probably already have these packages -installed). - -To run `check-py3` on just the Python files in a particular directory, you -can change the current working directory (e.g. `cd zerver/`) and run -`check-py3` from there. diff --git a/requirements/README.md b/requirements/README.md index cc3e969f53..3e03e8b135 100644 --- a/requirements/README.md +++ b/requirements/README.md @@ -5,10 +5,10 @@ dev prod + + + | +->common<-+ v -mypy,docs,py3k +mypy,docs ``` -Of the files, only dev, prod, py3k, and mypy have been used in the install +Of the files, only dev, prod, and mypy have been used in the install scripts directly. The rest are implicit dependencies. common and dev are locked. diff --git a/requirements/dev.txt b/requirements/dev.txt index 025045b0d8..0bfed248cc 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -4,8 +4,6 @@ # moto s3 mock moto==1.0.1 --r py3k.txt - # Needed for running tools/run-dev.py Twisted==17.5.0 diff --git a/requirements/dev_lock.txt b/requirements/dev_lock.txt index e5e0ab00ab..829db21872 100644 --- a/requirements/dev_lock.txt +++ b/requirements/dev_lock.txt @@ -50,7 +50,7 @@ docopt==0.6.2 docutils==0.14 first==2.0.1 fonttools==3.15.0 -future==0.16.0 +future==0.16.0 # via python-twitter gitdb==0.6.4 gitlint==0.8.2 google-api-python-client==1.6.2 @@ -72,7 +72,6 @@ markdown-include==0.5.1 markdown==2.6.9 # via markdown-include markupsafe==1.0 mock==2.0.0 -modernize==0.5 moto==1.0.1 ndg-httpsclient==0.4.2 oauth2client==4.1.2 diff --git a/requirements/py3k.txt b/requirements/py3k.txt deleted file mode 100644 index cadd048fb9..0000000000 --- a/requirements/py3k.txt +++ /dev/null @@ -1,4 +0,0 @@ -six==1.10.0 -typing==3.6.2 -future==0.16.0 -modernize==0.5 diff --git a/tools/check-py3 b/tools/check-py3 deleted file mode 100755 index be21c31aec..0000000000 --- a/tools/check-py3 +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/bash -set -e -fixers=" -lib2to3.fixes.fix_apply -lib2to3.fixes.fix_except -lib2to3.fixes.fix_exitfunc -lib2to3.fixes.fix_funcattrs -lib2to3.fixes.fix_has_key -lib2to3.fixes.fix_idioms -lib2to3.fixes.fix_intern -lib2to3.fixes.fix_isinstance -lib2to3.fixes.fix_methodattrs -lib2to3.fixes.fix_ne -lib2to3.fixes.fix_numliterals -lib2to3.fixes.fix_paren -lib2to3.fixes.fix_reduce -lib2to3.fixes.fix_renames -lib2to3.fixes.fix_repr -lib2to3.fixes.fix_standarderror -lib2to3.fixes.fix_sys_exc -lib2to3.fixes.fix_throw -lib2to3.fixes.fix_tuple_params -lib2to3.fixes.fix_types -lib2to3.fixes.fix_ws_comma -lib2to3.fixes.fix_xreadlines -libfuturize.fixes.fix_absolute_import -libfuturize.fixes.fix_future_standard_library_urllib -libfuturize.fixes.fix_next_call -libfuturize.fixes.fix_print_with_import -libfuturize.fixes.fix_raise -libmodernize.fixes.fix_basestring -libfuturize.fixes.fix_division_safe -libmodernize.fixes.fix_file -libmodernize.fixes.fix_filter -libmodernize.fixes.fix_imports_six -libmodernize.fixes.fix_input_six -libmodernize.fixes.fix_int_long_tuple -libmodernize.fixes.fix_map -libmodernize.fixes.fix_raise_six -libmodernize.fixes.fix_xrange_six -libmodernize.fixes.fix_zip -libmodernize.fixes.fix_unicode_type -libpasteurize.fixes.fix_newstyle -" - -echo; echo "Testing for additions of Python 2 patterns we've removed as part of moving towards Python 3 compatibility."; echo - -if [ -n "$(git status --porcelain)" ]; then - echo "The repository is not clean. check-py3 can only be run if the repository is clean." - echo "Displaying output from 'git status --porcelain' to help debug" - git status --porcelain - exit 1 -fi - -script_dir=$(dirname "$0") -lister_path="$script_dir/lister.py" -python_files="$($lister_path -f py)" - -if [ -z "$python_files" ]; then - echo "There are no python files to check in the current directory." - exit 0 -fi - -quick=1 -if [ "$1" == "--find-fixers" ]; then - quick=0 -fi - -fixer_options="" -for fixer in $fixers; do - fixer_options+="-f $fixer " -done - -failed=0 -# run quick check -echo "Running quick Python 3 compatibility test" -echo "$python_files" | xargs futurize $fixer_options -j4 -n -w >/dev/null 2>/dev/null -if ! git diff --exit-code; then - # Clear the output from this one - git reset --hard >/dev/null - failed=1 -fi - -# run slow check -if [ "$failed" = "1" -a "$quick" == "0" ]; then - echo "Running each fixer separately to find out which fixers need to be applied" - for fixer in $fixers; do - echo "Running Python 3 compatibility test $fixer" - echo "$python_files" | xargs futurize -f $fixer -j4 -n -w >/dev/null 2>/dev/null - if ! git diff --exit-code; then - # Clear the output from this one - git reset --hard >/dev/null - fi - done -fi - -# The dict fixer tries to add list() even in for loops over an -# iterator where it's just counterproductive. To address this, we run -# the fixer but check for lines which don't include code that works -# with iterators (currently for, join, and from_iterable). -fixer="libmodernize.fixes.fix_dict_six" -echo "Running python 3 compatability test $fixer" -echo "$python_files" | xargs python-modernize -f $fixer -j4 -n -w >/dev/null 2>/dev/null -if git --no-pager diff | grep "^+ " | grep -v '[ ]*for' | grep -v [.]join | grep -v from_iterable; then - echo - echo "Error: the above are changes suggested by python-modernize " - echo "to handle the list=>iterator transition in Python 3." - echo "Because 'python-modernize -f libmodernize.fixes.fix_dict_six' is spammy " - echo "and also changes places where an iterator works fine, this output " - echo "does not display the full context; you can find the diff with context by " - echo "searching through the (unfortunately very spammy) full output below:" - echo - git --no-pager diff - echo - echo "That was a lot of text! Read this output from the top for more readable details." - failed=1 -fi -# Clear the output -git reset --hard >/dev/null - -if git grep -q '\(^\W*import StringIO\|^\W*from StringIO\)'; then - echo "ERROR: StringIO imports not compatible with python 2+3:" - git grep '\(^\W*import StringIO\|^\W*from StringIO\)' - echo "Please use 'from six.moves import cStringIO as StringIO'" - failed=1 -fi - -echo -if [ "$failed" == "0" ]; then - echo "No issues detected!" -else - echo "Python 3 compatibility error(s) detected! See diffs above for what you need to change." - exit 1 -fi diff --git a/tools/test-all b/tools/test-all index 71839057b0..c0be794743 100755 --- a/tools/test-all +++ b/tools/test-all @@ -36,8 +36,6 @@ run ./tools/clean-repo # travis/static-analysis run ./tools/run-mypy -# Not running check-py3 because it demands a clean Git worktree. -# run ./tools/check-py3 # travis/backend run ./tools/lint --pep8 $FORCEARG diff --git a/tools/travis/setup-static-analysis b/tools/travis/setup-static-analysis index 347f100a47..3903dee782 100755 --- a/tools/travis/setup-static-analysis +++ b/tools/travis/setup-static-analysis @@ -2,15 +2,10 @@ set -e set -x -# We only need mypy and the python 3 compatibility checkers in this -# build, so we just install those directly, skipping provision. +# We only need the mypy checker in this build, so we just install that +# directly, skipping provision. if ! pip install --no-deps -r requirements/mypy.txt; then echo "\`pip install --no-deps -r requirements/mypy.txt\`: Failure occured while trying to perform dependancy installation, Retrying..." pip install --no-deps -r requirements/mypy.txt fi - -if ! pip install --no-deps -r requirements/py3k.txt; then - echo "\`pip install --no-deps -r requirements/py3k.txt\`: Failure occured while trying to perform dependancy installation, Retrying..." - pip install --no-deps -r requirements/py3k.txt -fi diff --git a/tools/travis/static-analysis b/tools/travis/static-analysis index 0f64d6b7fb..f5eb579b08 100755 --- a/tools/travis/static-analysis +++ b/tools/travis/static-analysis @@ -18,8 +18,6 @@ else fi set -x -tools/check-py3 - # NB: Everything here should be in `tools/test-all`. If there's a # reason not to run it there, it should be there as a comment # explaining why.