1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00

Update myynh_install_python

This commit is contained in:
ewilly 2022-01-08 16:17:29 +01:00
parent 696fb51a66
commit b9566020a1

View file

@ -89,61 +89,71 @@ myynh_install_python () {
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
# Check python version from APT # Check python version from APT
local PY_APT_VERSION=$(python3 --version | cut -d ' ' -f 2) local py_apt_version=$(python3 --version | cut -d ' ' -f 2)
# Check existing built version of python in /usr/local/bin # Check existing built version of python in /usr/local/bin
if [ -e "/usr/local/bin/python${python:0:3}" ] if [ -e "/usr/local/bin/python${python:0:3}" ]
then then
local PY_BUILT_VERSION=$(/usr/local/bin/python${python:0:3} --version \ local py_built_version=$(/usr/local/bin/python${python:0:3} --version \
| cut -d ' ' -f 2) | cut -d ' ' -f 2)
else else
local PY_BUILT_VERSION=0 local py_built_version=0
fi fi
# Compare version # Compare version
if [ $(myynh_version_compare $PY_APT_VERSION $python) -le 1 ] if [ $(myynh_version_compare $py_apt_version $python) -le 1 ]
then then
# APT >= Required # APT >= Required
ynh_print_info --message="Using provided python3..." ynh_print_info --message="Using provided python3..."
MY_PYTHON="python3" py_app_version="python3"
else else
# Either python already built or to build # Either python already built or to build
if [ $(myynh_version_compare $PY_BUILT_VERSION $python) -le 1 ] if [ $(myynh_version_compare $py_built_version $python) -le 1 ]
then then
# Built >= Required # Built >= Required
ynh_print_info --message="Using already used python3 built version..." ynh_print_info --message="Using already used python3 built version..."
MY_PYTHON="/usr/local/bin/python${PY_BUILT_VERSION:0:3}" py_app_version="/usr/local/bin/python${py_built_version:0:3}"
else else
ynh_print_info --message="Installing additional dependencies to build python..." ynh_print_info --message="Installing additional dependencies to build python..."
pkg_dependencies="${pkg_dependencies} tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libbz2-dev libexpat1-dev liblzma-dev wget tar" pkg_dependencies="${pkg_dependencies} tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libbz2-dev libexpat1-dev liblzma-dev wget tar"
ynh_install_app_dependencies "${pkg_dependencies}" ynh_install_app_dependencies "${pkg_dependencies}"
# APT < Minimal & Actual < Minimal => Build & install Python into /usr/local/bin # APT < Minimal & Actual < Minimal => Build & install Python into /usr/local/bin
ynh_print_info --message="Building python (may take a while)..." ynh_print_info --message="Building python (may take a while)..."
# Store current direcotry # Store current direcotry
local MY_DIR=$(pwd) local MY_DIR=$(pwd)
# Create a temp direcotry
tmpdir="$(mktemp --directory)"
cd "$tmpdir"
# Download # Download
wget -O "/tmp/Python-$python.tar.xz" "https://www.python.org/ftp/python/$python/Python-$python.tar.xz" 2>&1 wget --output-document="Python-$python.tar.xz" \
"https://www.python.org/ftp/python/$python/Python-$python.tar.xz" 2>&1
# Extract # Extract
cd /tmp
tar xf "Python-$python.tar.xz" tar xf "Python-$python.tar.xz"
# Install # Install
cd "Python-$python" cd "Python-$python"
./configure --enable-optimizations ./configure --enable-optimizations
ynh_exec_warn_less make -j4 ynh_exec_warn_less make -j4
ynh_exec_warn_less make altinstall ynh_exec_warn_less make altinstall
# Clean
cd ..
ynh_secure_remove "Python-$python"
ynh_secure_remove "Python-$python.tar.xz"
# Set version
MY_PYTHON="/usr/local/bin/python${python:0:3}"
# Go back to working directory # Go back to working directory
cd $MY_DIR cd "$MY_DIR"
# Clean
ynh_secure_remove "$tmpdir"
# Set version
py_app_version="/usr/local/bin/python${python:0:3}"
fi fi
fi fi
# Save python version in settings # Save python version in settings
@ -154,7 +164,7 @@ myynh_install_python () {
myynh_install_homeassistant () { myynh_install_homeassistant () {
ynh_exec_as $app -H -s /bin/bash -c " \ ynh_exec_as $app -H -s /bin/bash -c " \
echo 'create the virtual environment' \ echo 'create the virtual environment' \
&& $MY_PYTHON -m venv "$final_path" \ && $py_app_version -m venv "$final_path" \
&& echo 'activate the virtual environment' \ && echo 'activate the virtual environment' \
&& source "$final_path/bin/activate" \ && source "$final_path/bin/activate" \
&& echo 'install last version of wheel' \ && echo 'install last version of wheel' \