-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-12621] - Add Python 3.x installation script. #16457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tvalentyn
merged 2 commits into
apache:master
from
dannymartinm:beam-12621-jenkins-ubuntu
Jan 14, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <!-- | ||
| 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. | ||
| --> | ||
|
|
||
| > **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. This tool installs pyenv and the different | ||
| versions of python only for the user running the script. | ||
|
|
||
| #### 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_versions_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") | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 versions installer via pyenv. | ||
| # | ||
| set -euo pipefail | ||
|
|
||
| # Variable containing the python versions to install | ||
| python_versions_arr=("3.8.9" "3.6.13" "3.7.10" "3.9.4" "3.10.1") | ||
|
|
||
| # 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 | ||
| python_installer(){ | ||
| pyenv_dep | ||
| pyenv_install | ||
| pyenv_post_install | ||
| pyenv_versions_install "${python_versions_arr[@]}" | ||
| python_versions_setglobally "${python_versions_arr[@]}" | ||
| clean | ||
| } | ||
|
|
||
| python_installer |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
Let's advertise this script on https://s.apache.org/beam-python-dev-wiki and/or Jenkins portion of the Wiki once this is merged and document what would it take to install a new Python version using this script.