<commit_before>#!/usr/bin/env bash
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed 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.
# ==============================================================================
# External `common.sh`

# Keep in sync with tensorflow_estimator and configure.py.
# LINT.IfChange
LATEST_BAZEL_VERSION=2.0.0
# LINT.ThenChange(
#   //tensorflow/opensource_only/configure.py,
#   //tensorflow_estimator/google/kokoro/common.sh,
#   //tensorflow/tools/ci_build/install/install_bazel.sh,
#   //tensorflow/tools/ci_build/install/install_bazel_from_source.sh)

# Run flaky functions with retries.
# run_with_retry cmd
function run_with_retry {
  eval "$1"
  # If the command fails retry again in 60 seconds.
  if [[ $? -ne 0 ]]; then
    sleep 60
    eval "$1"
  fi
}

function die() {
  echo "$@" 1>&2 ; exit 1;
}

# A small utility to run the command and only print logs if the command fails.
# On success, all logs are hidden.
function readable_run {
  # Disable debug mode to avoid printing of variables here.
  set +x
  result=$("$@" 2>&1) || die "$result"
  echo "$@"
  echo "Command completed successfully at $(date)"
  set -x
}

# LINT.IfChange
# Redirect bazel output dir b/73748835
function set_bazel_outdir {
  mkdir -p /tmpfs/bazel_output
  export TEST_TMPDIR=/tmpfs/bazel_output
}

# Downloads bazelisk to ~/bin as `bazel`.
function install_bazelisk {
  date
  case "$(uname -s)" in
    Darwin) local name=bazelisk-darwin-amd64 ;;
    Linux)  local name=bazelisk-linux-amd64  ;;
    *) die "Unknown OS: $(uname -s)" ;;
  esac
  mkdir -p "$HOME/bin"
  wget --no-verbose -O "$HOME/bin/bazel" \
      "https://github.com/bazelbuild/bazelisk/releases/download/v1.3.0/$name"
  chmod u+x "$HOME/bin/bazel"
  if [[ ! ":$PATH:" =~ :"$HOME"/bin/?: ]]; then
    PATH="$HOME/bin:$PATH"
  fi
  set_bazel_outdir
  which bazel
  bazel version
  date
}

# Install the given bazel version on linux
function update_bazel_linux {
  if [[ -z "$1" ]]; then
    BAZEL_VERSION=${LATEST_BAZEL_VERSION}
  else
    BAZEL_VERSION=$1
  fi
  rm -rf ~/bazel
  mkdir ~/bazel

  pushd ~/bazel
  readable_run wget https://github.com/bazelbuild/bazel/releases/download/"${BAZEL_VERSION}"/bazel-"${BAZEL_VERSION}"-installer-linux-x86_64.sh
  chmod +x bazel-*.sh
  ./bazel-"${BAZEL_VERSION}"-installer-linux-x86_64.sh --user
  rm bazel-"${BAZEL_VERSION}"-installer-linux-x86_64.sh
  popd

  PATH="/home/kbuilder/bin:$PATH"
  set_bazel_outdir
  which bazel
  bazel version
}
# LINT.ThenChange(
#   //tensorflow_estimator/google/kokoro/common.sh)

function install_pip2 {
  curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  sudo python2 get-pip.py
}

function install_pip3.5 {
  curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  sudo python3.5 get-pip.py
}

function install_pip_deps {
  SUDO_CMD=""
  PIP_CMD="pip"

  while true; do
    if [[ -z "${1}" ]]; then
      break
    fi
    if [[ "$1" == "sudo" ]]; then
      SUDO_CMD="sudo "
    elif [[ "$1" == "pip"* ]]; then
      PIP_CMD="$1"
    fi
    shift
  done

  # LINT.IfChange(ubuntu_pip_installations)
  # TODO(aselle): Change all these to be --user instead of sudo.
  ${SUDO_CMD} ${PIP_CMD} install astunparse==1.6.3
  ${SUDO_CMD} ${PIP_CMD} install keras_preprocessing==1.1.0 --no-deps
  "${PIP_CMD}" install numpy==1.16.0 --user
  "${PIP_CMD}" install PyYAML==3.12 --user
  ${SUDO_CMD} ${PIP_CMD} install gast==0.3.3
  ${SUDO_CMD} ${PIP_CMD} install h5py==2.10.0
  ${SUDO_CMD} ${PIP_CMD} install six==1.12.0
  ${SUDO_CMD} ${PIP_CMD} install grpcio
  ${SUDO_CMD} ${PIP_CMD} install portpicker
  ${SUDO_CMD} ${PIP_CMD} install scipy
  ${SUDO_CMD} ${PIP_CMD} install scikit-learn
  ${SUDO_CMD} ${PIP_CMD} install --upgrade tb-nightly
  ${PIP_CMD} install --user --upgrade attrs
  ${PIP_CMD} install --user --upgrade tf-estimator-nightly
  ${PIP_CMD} install --user --upgrade "future>=0.17.1"
  # LINT.ThenChange(:ubuntu_16_pip_installations)
}

function install_ubuntu_16_pip_deps {
  PIP_CMD="pip"

  while true; do
    if [[ -z "${1}" ]]; then
      break
    fi
    if [[ "$1" == "pip"* ]]; then
      PIP_CMD="$1"
    fi
    shift
  done

  # LINT.IfChange(ubuntu_16_pip_installations)
  "${PIP_CMD}" install astunparse==1.6.3 --user
  "${PIP_CMD}" install --user --upgrade attrs
  "${PIP_CMD}" install keras_preprocessing==1.1.0 --no-deps --user
  "${PIP_CMD}" install numpy==1.16.0 --user
  "${PIP_CMD}" install --user --upgrade "future>=0.17.1"
  "${PIP_CMD}" install gast==0.3.3 --user
  "${PIP_CMD}" install h5py==2.10.0 --user
  "${PIP_CMD}" install six==1.12.0 --user
  "${PIP_CMD}" install grpcio --user
  "${PIP_CMD}" install portpicker --user
  "${PIP_CMD}" install scipy --user
  "${PIP_CMD}" install scikit-learn --user
  "${PIP_CMD}" install PyYAML==3.12 --user
  "${PIP_CMD}" install --user --upgrade tf-estimator-nightly
  "${PIP_CMD}" install --user --upgrade tb-nightly
  # LINT.ThenChange(:ubuntu_pip_installations)
}

function install_macos_pip_deps {
  SUDO_CMD=""
  PIP_CMD="pip"

  while true; do
    if [[ -z "${1}" ]]; then
      break
    fi
    if [[ "$1" == "sudo" ]]; then
      SUDO_CMD="sudo "
    elif [[ "$1" == "pip3.7" ]]; then
      PIP_CMD="python3.7 -m pip"
      SUDO_CMD="sudo -H "
    elif [[ "$1" == "pip"* ]]; then
      PIP_CMD="$1"
    fi
    shift
  done

   # High Sierra pip for Python2.7 installs don't work as expected.
   if [[ "${PIP_CMD}" == "pip" ]]; then
    PIP_CMD="python -m pip"<commit_msg>Update PyYAML to 3.13 to work with py3.7<commit_after>#!/usr/bin/env bash
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed 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.
# ==============================================================================
# External `common.sh`

# Keep in sync with tensorflow_estimator and configure.py.
# LINT.IfChange
LATEST_BAZEL_VERSION=2.0.0
# LINT.ThenChange(
#   //tensorflow/opensource_only/configure.py,
#   //tensorflow_estimator/google/kokoro/common.sh,
#   //tensorflow/tools/ci_build/install/install_bazel.sh,
#   //tensorflow/tools/ci_build/install/install_bazel_from_source.sh)

# Run flaky functions with retries.
# run_with_retry cmd
function run_with_retry {
  eval "$1"
  # If the command fails retry again in 60 seconds.
  if [[ $? -ne 0 ]]; then
    sleep 60
    eval "$1"
  fi
}

function die() {
  echo "$@" 1>&2 ; exit 1;
}

# A small utility to run the command and only print logs if the command fails.
# On success, all logs are hidden.
function readable_run {
  # Disable debug mode to avoid printing of variables here.
  set +x
  result=$("$@" 2>&1) || die "$result"
  echo "$@"
  echo "Command completed successfully at $(date)"
  set -x
}

# LINT.IfChange
# Redirect bazel output dir b/73748835
function set_bazel_outdir {
  mkdir -p /tmpfs/bazel_output
  export TEST_TMPDIR=/tmpfs/bazel_output
}

# Downloads bazelisk to ~/bin as `bazel`.
function install_bazelisk {
  date
  case "$(uname -s)" in
    Darwin) local name=bazelisk-darwin-amd64 ;;
    Linux)  local name=bazelisk-linux-amd64  ;;
    *) die "Unknown OS: $(uname -s)" ;;
  esac
  mkdir -p "$HOME/bin"
  wget --no-verbose -O "$HOME/bin/bazel" \
      "https://github.com/bazelbuild/bazelisk/releases/download/v1.3.0/$name"
  chmod u+x "$HOME/bin/bazel"
  if [[ ! ":$PATH:" =~ :"$HOME"/bin/?: ]]; then
    PATH="$HOME/bin:$PATH"
  fi
  set_bazel_outdir
  which bazel
  bazel version
  date
}

# Install the given bazel version on linux
function update_bazel_linux {
  if [[ -z "$1" ]]; then
    BAZEL_VERSION=${LATEST_BAZEL_VERSION}
  else
    BAZEL_VERSION=$1
  fi
  rm -rf ~/bazel
  mkdir ~/bazel

  pushd ~/bazel
  readable_run wget https://github.com/bazelbuild/bazel/releases/download/"${BAZEL_VERSION}"/bazel-"${BAZEL_VERSION}"-installer-linux-x86_64.sh
  chmod +x bazel-*.sh
  ./bazel-"${BAZEL_VERSION}"-installer-linux-x86_64.sh --user
  rm bazel-"${BAZEL_VERSION}"-installer-linux-x86_64.sh
  popd

  PATH="/home/kbuilder/bin:$PATH"
  set_bazel_outdir
  which bazel
  bazel version
}
# LINT.ThenChange(
#   //tensorflow_estimator/google/kokoro/common.sh)

function install_pip2 {
  curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  sudo python2 get-pip.py
}

function install_pip3.5 {
  curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  sudo python3.5 get-pip.py
}

function install_pip_deps {
  SUDO_CMD=""
  PIP_CMD="pip"

  while true; do
    if [[ -z "${1}" ]]; then
      break
    fi
    if [[ "$1" == "sudo" ]]; then
      SUDO_CMD="sudo "
    elif [[ "$1" == "pip"* ]]; then
      PIP_CMD="$1"
    fi
    shift
  done

  # LINT.IfChange(ubuntu_pip_installations)
  # TODO(aselle): Change all these to be --user instead of sudo.
  ${SUDO_CMD} ${PIP_CMD} install astunparse==1.6.3
  ${SUDO_CMD} ${PIP_CMD} install keras_preprocessing==1.1.0 --no-deps
  "${PIP_CMD}" install numpy==1.16.0 --user
  "${PIP_CMD}" install PyYAML==3.13 --user
  ${SUDO_CMD} ${PIP_CMD} install gast==0.3.3
  ${SUDO_CMD} ${PIP_CMD} install h5py==2.10.0
  ${SUDO_CMD} ${PIP_CMD} install six==1.12.0
  ${SUDO_CMD} ${PIP_CMD} install grpcio
  ${SUDO_CMD} ${PIP_CMD} install portpicker
  ${SUDO_CMD} ${PIP_CMD} install scipy
  ${SUDO_CMD} ${PIP_CMD} install scikit-learn
  ${SUDO_CMD} ${PIP_CMD} install --upgrade tb-nightly
  ${PIP_CMD} install --user --upgrade attrs
  ${PIP_CMD} install --user --upgrade tf-estimator-nightly
  ${PIP_CMD} install --user --upgrade "future>=0.17.1"
  # LINT.ThenChange(:ubuntu_16_pip_installations)
}

function install_ubuntu_16_pip_deps {
  PIP_CMD="pip"

  while true; do
    if [[ -z "${1}" ]]; then
      break
    fi
    if [[ "$1" == "pip"* ]]; then
      PIP_CMD="$1"
    fi
    shift
  done

  # LINT.IfChange(ubuntu_16_pip_installations)
  "${PIP_CMD}" install astunparse==1.6.3 --user
  "${PIP_CMD}" install --user --upgrade attrs
  "${PIP_CMD}" install keras_preprocessing==1.1.0 --no-deps --user
  "${PIP_CMD}" install numpy==1.16.0 --user
  "${PIP_CMD}" install --user --upgrade "future>=0.17.1"
  "${PIP_CMD}" install gast==0.3.3 --user
  "${PIP_CMD}" install h5py==2.10.0 --user
  "${PIP_CMD}" install six==1.12.0 --user
  "${PIP_CMD}" install grpcio --user
  "${PIP_CMD}" install portpicker --user
  "${PIP_CMD}" install scipy --user
  "${PIP_CMD}" install scikit-learn --user
  "${PIP_CMD}" install PyYAML==3.13 --user
  "${PIP_CMD}" install --user --upgrade tf-estimator-nightly
  "${PIP_CMD}" install --user --upgrade tb-nightly
  # LINT.ThenChange(:ubuntu_pip_installations)
}

function install_macos_pip_deps {
  SUDO_CMD=""
  PIP_CMD="pip"

  while true; do
    if [[ -z "${1}" ]]; then
      break
    fi
    if [[ "$1" == "sudo" ]]; then
      SUDO_CMD="sudo "
    elif [[ "$1" == "pip3.7" ]]; then
      PIP_CMD="python3.7 -m pip"
      SUDO_CMD="sudo -H "
    elif [[ "$1" == "pip"* ]]; then
      PIP_CMD="$1"
    fi
    shift
  done

   # High Sierra pip for Python2.7 installs don't work as expected.
   if [[ "${PIP_CMD}" == "pip" ]]; then
    PIP_CMD="python -m pip"
{'fraction_non_alphanumeric': 0.16474934923167353, 'fraction_numerical': 0.023931480392980098, 'mean_word_length': 3.4308035714285716, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6636381', 'n_tokens_mistral': 4756, 'n_tokens_neox': 4476, 'n_words': 1106}