github.com/apache/beam/sdks/v2@v2.48.2/python/scripts/run_tox.sh (about)

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