Skip to content

Commit 04e99c1

Browse files
committed
[SPARK-29672][PYSPARK] update spark testing framework to use python3
### What changes were proposed in this pull request? remove python2.7 tests and test infra for 3.0+ ### Why are the changes needed? because python2.7 is finally going the way of the dodo. ### Does this PR introduce any user-facing change? newp. ### How was this patch tested? the build system will test this Closes apache#26330 from shaneknapp/remove-py27-tests. Lead-authored-by: shane knapp <[email protected]> Co-authored-by: shane <[email protected]> Signed-off-by: shane knapp <[email protected]>
1 parent e46e487 commit 04e99c1

File tree

12 files changed

+43
-46
lines changed

12 files changed

+43
-46
lines changed

dev/pip-sanity-check.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# limitations under the License.
1616
#
1717

18-
from __future__ import print_function
19-
2018
from pyspark.sql import SparkSession
2119
from pyspark.mllib.linalg import *
2220
import sys

dev/run-pip-tests

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,16 @@ PYTHON_EXECS=()
3939
# Some systems don't have pip or virtualenv - in those cases our tests won't work.
4040
if hash virtualenv 2>/dev/null && [ ! -n "$USE_CONDA" ]; then
4141
echo "virtualenv installed - using. Note if this is a conda virtual env you may wish to set USE_CONDA"
42-
# Figure out which Python execs we should test pip installation with
43-
if hash python2 2>/dev/null; then
44-
# We do this since we are testing with virtualenv and the default virtual env python
45-
# is in /usr/bin/python
46-
PYTHON_EXECS+=('python2')
47-
elif hash python 2>/dev/null; then
48-
# If python2 isn't installed fallback to python if available
49-
PYTHON_EXECS+=('python')
50-
fi
42+
# test only against python3
5143
if hash python3 2>/dev/null; then
52-
PYTHON_EXECS+=('python3')
44+
PYTHON_EXECS=('python3')
45+
else
46+
echo "Python3 not installed on system, skipping pip installability tests"
47+
exit 0
5348
fi
5449
elif hash conda 2>/dev/null; then
5550
echo "Using conda virtual environments"
56-
PYTHON_EXECS=('3.5')
51+
PYTHON_EXECS=('3.6')
5752
USE_CONDA=1
5853
else
5954
echo "Missing virtualenv & conda, skipping pip installability tests"
@@ -97,7 +92,7 @@ for python in "${PYTHON_EXECS[@]}"; do
9792
cd "$FWDIR"/python
9893
# Delete the egg info file if it exists, this can cache the setup file.
9994
rm -rf pyspark.egg-info || echo "No existing egg info file, skipping deletion"
100-
python setup.py sdist
95+
python3 setup.py sdist
10196

10297

10398
echo "Installing dist into virtual env"
@@ -117,9 +112,9 @@ for python in "${PYTHON_EXECS[@]}"; do
117112
echo "Run basic sanity check on pip installed version with spark-submit"
118113
spark-submit "$FWDIR"/dev/pip-sanity-check.py
119114
echo "Run basic sanity check with import based"
120-
python "$FWDIR"/dev/pip-sanity-check.py
115+
python3 "$FWDIR"/dev/pip-sanity-check.py
121116
echo "Run the tests for context.py"
122-
python "$FWDIR"/python/pyspark/context.py
117+
python3 "$FWDIR"/python/pyspark/context.py
123118

124119
cd "$FWDIR"
125120

dev/run-tests

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
FWDIR="$(cd "`dirname $0`"/..; pwd)"
2121
cd "$FWDIR"
2222

23-
PYTHON_VERSION_CHECK=$(python -c 'import sys; print(sys.version_info < (2, 7, 0))')
23+
PYTHON_VERSION_CHECK=$(python3 -c 'import sys; print(sys.version_info < (3, 6, 0))')
2424
if [[ "$PYTHON_VERSION_CHECK" == "True" ]]; then
25-
echo "Python versions prior to 2.7 are not supported."
25+
echo "Python versions prior to 3.6 are not supported."
2626
exit -1
2727
fi
2828

29-
exec python -u ./dev/run-tests.py "$@"
29+
exec python3 -u ./dev/run-tests.py "$@"

dev/run-tests-jenkins

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
FWDIR="$( cd "$( dirname "$0" )/.." && pwd )"
2626
cd "$FWDIR"
2727

28-
PYTHON_VERSION_CHECK=$(python -c 'import sys; print(sys.version_info < (2, 7, 0))')
28+
export PATH=/home/anaconda/envs/py36/bin:$PATH
29+
30+
PYTHON_VERSION_CHECK=$(python3 -c 'import sys; print(sys.version_info < (3, 6, 0))')
2931
if [[ "$PYTHON_VERSION_CHECK" == "True" ]]; then
30-
echo "Python versions prior to 2.7 are not supported."
32+
echo "Python versions prior to 3.6 are not supported."
3133
exit -1
3234
fi
3335

34-
exec python -u ./dev/run-tests-jenkins.py "$@"
36+
exec python3 -u ./dev/run-tests-jenkins.py "$@"

dev/run-tests-jenkins.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
#
44
# Licensed to the Apache Software Foundation (ASF) under one or more
@@ -17,7 +17,6 @@
1717
# limitations under the License.
1818
#
1919

20-
from __future__ import print_function
2120
import os
2221
import sys
2322
import json

dev/run-tests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
#
44
# Licensed to the Apache Software Foundation (ASF) under one or more
@@ -17,7 +17,6 @@
1717
# limitations under the License.
1818
#
1919

20-
from __future__ import print_function
2120
import itertools
2221
from argparse import ArgumentParser
2322
import os
@@ -265,7 +264,7 @@ def exec_sbt(sbt_args=()):
265264
echo_proc.wait()
266265
for line in iter(sbt_proc.stdout.readline, b''):
267266
if not sbt_output_filter.match(line):
268-
print(line, end='')
267+
print(line.decode('utf-8'), end='')
269268
retcode = sbt_proc.wait()
270269

271270
if retcode != 0:

dev/sparktestsupport/shellutils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
# limitations under the License.
1616
#
1717

18-
from __future__ import print_function
1918
import os
2019
import shutil
2120
import subprocess
2221
import sys
2322

2423
subprocess_check_output = subprocess.check_output
25-
subprocess_check_call = subprocess.check_call
2624

2725

2826
def exit_from_command_with_retcode(cmd, retcode):
@@ -55,9 +53,9 @@ def run_cmd(cmd, return_output=False):
5553
cmd = cmd.split()
5654
try:
5755
if return_output:
58-
return subprocess_check_output(cmd).decode(sys.getdefaultencoding())
56+
return subprocess_check_output(cmd).decode('utf-8')
5957
else:
60-
return subprocess_check_call(cmd)
58+
return subprocess.run(cmd, universal_newlines=True, check=True)
6159
except subprocess.CalledProcessError as e:
6260
exit_from_command_with_retcode(e.cmd, e.returncode)
6361

python/pyspark/context.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# limitations under the License.
1616
#
1717

18-
from __future__ import print_function
19-
2018
import os
2119
import shutil
2220
import signal

python/pyspark/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
#
44
# Licensed to the Apache Software Foundation (ASF) under one or more

python/run-tests

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@
2121
FWDIR="$(cd "`dirname $0`"/..; pwd)"
2222
cd "$FWDIR"
2323

24-
exec python -u ./python/run-tests.py "$@"
24+
PYTHON_VERSION_CHECK=$(python3 -c 'import sys; print(sys.version_info < (3, 6, 0))')
25+
if [[ "$PYTHON_VERSION_CHECK" == "True" ]]; then
26+
echo "Python versions prior to 3.6 are not supported."
27+
exit -1
28+
fi
29+
30+
exec python3 -u ./python/run-tests.py "$@"

0 commit comments

Comments
 (0)