From 15ee15c9cef4a115e027135921353d8e93d4c7dc Mon Sep 17 00:00:00 2001 From: Giomar Osorio <95301399+GiomarWize@users.noreply.github.com> Date: Fri, 7 Jan 2022 13:45:47 -0500 Subject: [PATCH 1/2] [BEAM-12621] Add python installer tool and documentation (#8) * [BEAM-12621] Add python installer tool and documentation --- .test-infra/tools/README.md | 61 ++++++++++++++++++ .test-infra/tools/python_installer.sh | 92 +++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 .test-infra/tools/README.md create mode 100644 .test-infra/tools/python_installer.sh diff --git a/.test-infra/tools/README.md b/.test-infra/tools/README.md new file mode 100644 index 000000000000..434910f45d1f --- /dev/null +++ b/.test-infra/tools/README.md @@ -0,0 +1,61 @@ + + +> **PLEASE update this file if you add a new tool or update an existing one** + +## Tools + +- [Python installer](#python-installer) + +### Python installer + +It is a tool that installs pyenv and its dependencies, as well as different +versions of python through pyenv. It was developed during the Ubuntu update +of the Jenkins image. + +**Warning:** This tool was conceived to install pyenv and python versions in a clean +environment. If you want to use this install in other cases, we recommend +that you make the required modifications manually and then run the tool. + +#### Use + +To use the tool, they only have to download the script and execute it with the +following command. + +```bash +bash ./python_installer.sh +``` + +#### Modification + +If you want to modify the python versions to install, you must add/remove the +versions within that are defined within the `python_versiones_arr` variable. +Example: + +- Original + +```bash +python_versions_arr=("3.6.13" "3.7.10" "3.8.9" "3.9.4") +``` + +- Change + +```bash +python_versions_arr=("3.6.13" "3.7.10" "3.9.0" "3.10.2") +``` diff --git a/.test-infra/tools/python_installer.sh b/.test-infra/tools/python_installer.sh new file mode 100644 index 000000000000..59e3cb12b883 --- /dev/null +++ b/.test-infra/tools/python_installer.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env 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 spefic language governing permissions and +# limitations under the License. +# +# Python version 3.6.13-3.7.10-3.8.9-3.9.4 installer via pyenv. +# +set -euo pipefail + +# Variable containing the python versions to install +python_versions_arr=("3.6.13" "3.7.10" "3.8.9" "3.9.4") + +# Install pyenv dependencies. +pyenv_dep(){ + sudo apt-get update -y + sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \ +libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ +libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev +} + +# Install pyenv, delete previous version if needed. +pyenv_install(){ + if [[ -d "$HOME"/.pyenv/ ]]; then + sudo rm -r "$HOME"/.pyenv + fi + if [[ -e "$HOME"/pyenv_installer.sh ]]; then + sudo rm "$HOME"/pyenv_installer.sh + fi + curl https://pyenv.run > "$HOME"/pyenv_installer.sh + chmod +x "$HOME"/pyenv_installer.sh + "$HOME"/pyenv_installer.sh +} + +# Setting pyenv in User environment, PATH. +pyenv_post_install(){ + if ! < "$HOME"/.bashrc grep -q "# pyenv Config" ; then + { + echo '# pyenv Config' + echo 'export PYENV_ROOT="$HOME/.pyenv"' + echo 'export PATH="$PYENV_ROOT/bin:$PATH"' + echo 'if which pyenv > /dev/null; then' + echo ' eval "$(pyenv init -)"' + echo ' eval "$(pyenv init --path)"' + echo ' eval "$(pyenv virtualenv-init -)"' + echo 'fi' + } >> "$HOME"/.bashrc + fi +} + +# Install python versions with pyenv +pyenv_versions_install(){ + arr=("$@") + for version in "${arr[@]}"; do + "$HOME"/.pyenv/bin/pyenv install "$version" + done +} + +# Setting python versions globally +python_versions_setglobally(){ + "$HOME"/.pyenv/bin/pyenv global "$@" +} + +# Remove pyenv script installer +clean(){ + sudo rm "$HOME"/pyenv_installer.sh + echo -e "\nRestart your shell so the path changes take effect" + echo " 'exec $SHELL'" +} + +# Install pyenv environment with python versions +pyenv(){ + pyenv_dep + pyenv_install + pyenv_post_install + pyenv_versions_install "${python_versions_arr[@]}" + python_versions_setglobally "${python_versions_arr[@]}" + clean +} + +pyenv From f20dfe7bed1015ed14052e7941d5f97e069f630e Mon Sep 17 00:00:00 2001 From: Giomar Osorio <95301399+GiomarWize@users.noreply.github.com> Date: Fri, 14 Jan 2022 18:14:57 -0500 Subject: [PATCH 2/2] Added changes commented in Github Pull Request #16457 (#13) * add changes comment in Github Pull Request #16457 --- .test-infra/tools/README.md | 10 +++------- .test-infra/tools/python_installer.sh | 8 ++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.test-infra/tools/README.md b/.test-infra/tools/README.md index 434910f45d1f..1c7addfd3941 100644 --- a/.test-infra/tools/README.md +++ b/.test-infra/tools/README.md @@ -26,12 +26,8 @@ ### Python installer It is a tool that installs pyenv and its dependencies, as well as different -versions of python through pyenv. It was developed during the Ubuntu update -of the Jenkins image. - -**Warning:** This tool was conceived to install pyenv and python versions in a clean -environment. If you want to use this install in other cases, we recommend -that you make the required modifications manually and then run the tool. +versions of python through pyenv. This tool installs pyenv and the different +versions of python only for the user running the script. #### Use @@ -45,7 +41,7 @@ bash ./python_installer.sh #### Modification If you want to modify the python versions to install, you must add/remove the -versions within that are defined within the `python_versiones_arr` variable. +versions within that are defined within the `python_versions_arr` variable. Example: - Original diff --git a/.test-infra/tools/python_installer.sh b/.test-infra/tools/python_installer.sh index 59e3cb12b883..0fe73e7fabdd 100644 --- a/.test-infra/tools/python_installer.sh +++ b/.test-infra/tools/python_installer.sh @@ -15,12 +15,12 @@ # See the License for the spefic language governing permissions and # limitations under the License. # -# Python version 3.6.13-3.7.10-3.8.9-3.9.4 installer via pyenv. +# Python versions installer via pyenv. # set -euo pipefail # Variable containing the python versions to install -python_versions_arr=("3.6.13" "3.7.10" "3.8.9" "3.9.4") +python_versions_arr=("3.8.9" "3.6.13" "3.7.10" "3.9.4" "3.10.1") # Install pyenv dependencies. pyenv_dep(){ @@ -80,7 +80,7 @@ clean(){ } # Install pyenv environment with python versions -pyenv(){ +python_installer(){ pyenv_dep pyenv_install pyenv_post_install @@ -89,4 +89,4 @@ pyenv(){ clean } -pyenv +python_installer