-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathrun_tox.sh
More file actions
executable file
·79 lines (70 loc) · 2.84 KB
/
run_tox.sh
File metadata and controls
executable file
·79 lines (70 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
#
# This script is a wrapper around tox.
# This is a workaround to the bug related to Nose mentioned in [Beam-5243].
# TODO: [Beam-5243] Remove this wrapper after we migrate from Nose.
###########################################################################
# Usage check.
if [[ $# < 1 ]]; then
printf "Usage: \n$> ./scripts/run_tox.sh <tox_environment> [<sdk_location> [<posargs> ...]]"
printf "\n\ttox_environment: [required] Tox environment to run the test in.\n"
printf "\n\tsdk_location: [optional] SDK tarball artifact location.\n"
printf "\n\tposarg: [optional] Any additional arguments will be passed as posargs to tox.\n"
exit 1
fi
TOX_ENVIRONMENT="$1"
shift
# Check that the script is running in a known directory.
if [[ $PWD != *sdks/python* ]]; then
echo 'Unable to locate Apache Beam Python SDK root directory'
exit 1
fi
# Go to the Apache Beam Python SDK root
if [[ $PWD != *sdks/python ]]; then
cd $(pwd | sed 's/sdks\/python.*/sdks\/python/')
fi
# Used in tox.ini to isolate toxworkdir of each environment.
export ENV_NAME=".tox-$TOX_ENVIRONMENT"
# Force colors in Jenkins jobs.
if [[ "$JENKINS_HOME" != "" ]]; then
export PY_COLORS=1
fi
# Determine if the second argument is SDK_LOCATION or posargs
if [[ -f "$1" ]]; then # Check if the argument corresponds to a file
SDK_LOCATION="$1"
shift
fi
# If SDK_LOCATION is identified and there are still arguments left, those are posargs.
if [[ ! -z "$SDK_LOCATION" ]]; then
if [[ $# -gt 0 ]]; then # There are posargs
tox -c tox.ini run --recreate -e "$TOX_ENVIRONMENT" --installpkg "$SDK_LOCATION" -- "$@"
else
tox -c tox.ini run --recreate -e "$TOX_ENVIRONMENT" --installpkg "$SDK_LOCATION"
fi
else # No SDK_LOCATION; all arguments are posargs
tox -c tox.ini run --recreate -e "$TOX_ENVIRONMENT" -- "$@"
fi
exit_code=$?
# Retry once for the specific exit code 245.
if [[ $exit_code == 245 ]]; then
tox -c tox.ini run --recreate -e "$TOX_ENVIRONMENT"
exit_code=$?
fi
exit $exit_code