feat: allow klipper installation with python3
Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
@@ -226,17 +226,23 @@ function flash_mcu_sd(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function build_fw(){
|
function build_fw(){
|
||||||
if [ -d "${KLIPPER_DIR}" ]; then
|
local python_version
|
||||||
|
if [ ! -d "${KLIPPER_DIR}" ] || [ ! -d "${KLIPPY_ENV}" ]; then
|
||||||
|
print_error "Klipper not found!\n Cannot build firmware without Klipper!"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
cd "${KLIPPER_DIR}"
|
cd "${KLIPPER_DIR}"
|
||||||
status_msg "Initializing firmware build ..."
|
status_msg "Initializing firmware build ..."
|
||||||
dep=(build-essential dpkg-dev make)
|
dep=(build-essential dpkg-dev make)
|
||||||
dependency_check "${dep[@]}"
|
dependency_check "${dep[@]}"
|
||||||
|
|
||||||
make clean && make menuconfig
|
make clean && make menuconfig
|
||||||
|
|
||||||
status_msg "Building firmware ..."
|
status_msg "Building firmware ..."
|
||||||
make && ok_msg "Firmware built!"
|
python_version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1)
|
||||||
else
|
[ "${python_version}" == "3" ] && make PYTHON=python3
|
||||||
print_error "Klipper was not found!\n Can not build firmware without Klipper!"
|
[ "${python_version}" == "2" ] && make
|
||||||
return 1
|
ok_msg "Firmware built!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ function klipper_exists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function klipper_setup_dialog(){
|
function klipper_setup_dialog(){
|
||||||
|
local python_version="${1}"
|
||||||
status_msg "Initializing Klipper installation ..."
|
status_msg "Initializing Klipper installation ..."
|
||||||
|
|
||||||
### return early if klipper already exists
|
### return early if klipper already exists
|
||||||
@@ -44,7 +45,7 @@ function klipper_setup_dialog(){
|
|||||||
if [ -n "${klipper_services}" ]; then
|
if [ -n "${klipper_services}" ]; then
|
||||||
local error="At least one Klipper service is already installed:"
|
local error="At least one Klipper service is already installed:"
|
||||||
for s in ${klipper_services}; do
|
for s in ${klipper_services}; do
|
||||||
log "Found Klipper service: ${s}"
|
log_info "Found Klipper service: ${s}"
|
||||||
error="${error}\n ➔ ${s}"
|
error="${error}\n ➔ ${s}"
|
||||||
done
|
done
|
||||||
print_error "${error}" && return
|
print_error "${error}" && return
|
||||||
@@ -74,7 +75,7 @@ function klipper_setup_dialog(){
|
|||||||
Y|y|Yes|yes|"")
|
Y|y|Yes|yes|"")
|
||||||
select_msg "Yes"
|
select_msg "Yes"
|
||||||
status_msg "Installing ${count} Klipper instance(s) ... \n"
|
status_msg "Installing ${count} Klipper instance(s) ... \n"
|
||||||
klipper_setup "${count}"
|
klipper_setup "${count}" "${python_version}"
|
||||||
break;;
|
break;;
|
||||||
N|n|No|no)
|
N|n|No|no)
|
||||||
select_msg "No"
|
select_msg "No"
|
||||||
@@ -89,12 +90,14 @@ function klipper_setup_dialog(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function install_klipper_packages(){
|
function install_klipper_packages(){
|
||||||
local packages
|
local packages python_version="${1}"
|
||||||
local install_script="${HOME}/klipper/scripts/install-octopi.sh"
|
local install_script="${HOME}/klipper/scripts/install-octopi.sh"
|
||||||
|
|
||||||
status_msg "Reading dependencies..."
|
status_msg "Reading dependencies..."
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')"
|
packages=$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')
|
||||||
|
### replace python-dev with python3-dev if python3 was selected
|
||||||
|
[ "${python_version}" == "python3" ] && packages="${packages//python-dev/python3-dev}"
|
||||||
### add dbus requirement for DietPi distro
|
### add dbus requirement for DietPi distro
|
||||||
[ -e "/boot/dietpi/.version" ] && packages+=" dbus"
|
[ -e "/boot/dietpi/.version" ] && packages+=" dbus"
|
||||||
|
|
||||||
@@ -111,15 +114,27 @@ function install_klipper_packages(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function create_klipper_virtualenv(){
|
function create_klipper_virtualenv(){
|
||||||
status_msg "Installing python virtual environment..."
|
local python_version="${1}" py2_ver py3_ver
|
||||||
### always create a clean virtualenv
|
if [ "${python_version}" == "python2" ]; then
|
||||||
[ -d "${KLIPPY_ENV}" ] && rm -rf "${KLIPPY_ENV}"
|
py2_ver=$(python2 -V)
|
||||||
virtualenv -p python2 "${KLIPPY_ENV}"
|
status_msg "Installing ${py2_ver} virtual environment..."
|
||||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
[ -d "${KLIPPY_ENV}" ] && rm -rf "${KLIPPY_ENV}"
|
||||||
|
virtualenv -p python2 "${KLIPPY_ENV}"
|
||||||
|
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
||||||
|
fi
|
||||||
|
if [ "${python_version}" == "python3" ]; then
|
||||||
|
py3_ver=$(python3 -V)
|
||||||
|
status_msg "Installing ${py3_ver} virtual environment..."
|
||||||
|
virtualenv -p python3 "${KLIPPY_ENV}"
|
||||||
|
### upgrade pip
|
||||||
|
"${KLIPPY_ENV}"/bin/pip install -U pip
|
||||||
|
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
||||||
|
fi
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
function klipper_setup(){
|
function klipper_setup(){
|
||||||
local instances=${1}
|
local instances=${1} python_version=${2}
|
||||||
### checking dependencies
|
### checking dependencies
|
||||||
local dep=(git)
|
local dep=(git)
|
||||||
dependency_check "${dep[@]}"
|
dependency_check "${dep[@]}"
|
||||||
@@ -131,8 +146,8 @@ function klipper_setup(){
|
|||||||
cd "${HOME}" && git clone "${KLIPPER_REPO}"
|
cd "${HOME}" && git clone "${KLIPPER_REPO}"
|
||||||
|
|
||||||
### step 2: install klipper dependencies and create python virtualenv
|
### step 2: install klipper dependencies and create python virtualenv
|
||||||
install_klipper_packages
|
install_klipper_packages "${python_version}"
|
||||||
create_klipper_virtualenv
|
create_klipper_virtualenv "${python_version}"
|
||||||
|
|
||||||
### step 3: create gcode_files and logs folder
|
### step 3: create gcode_files and logs folder
|
||||||
[ ! -d "${HOME}/gcode_files" ] && mkdir -p "${HOME}/gcode_files"
|
[ ! -d "${HOME}/gcode_files" ] && mkdir -p "${HOME}/gcode_files"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
install_ui(){
|
function install_ui(){
|
||||||
top_border
|
top_border
|
||||||
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} | "
|
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} | "
|
||||||
hr
|
hr
|
||||||
@@ -32,13 +32,16 @@ install_ui(){
|
|||||||
back_footer
|
back_footer
|
||||||
}
|
}
|
||||||
|
|
||||||
install_menu(){
|
function install_menu(){
|
||||||
do_action "" "install_ui"
|
clear && print_header
|
||||||
|
install_ui
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
read -p "${cyan}Perform action:${white} " action; echo
|
read -p "${cyan}Perform action:${white} " action; echo
|
||||||
case "$action" in
|
case "${action}" in
|
||||||
1)
|
1)clear && print_header
|
||||||
do_action "klipper_setup_dialog" "install_ui";;
|
select_klipper_python_version
|
||||||
|
install_ui;;
|
||||||
2)
|
2)
|
||||||
do_action "moonraker_setup_dialog" "install_ui";;
|
do_action "moonraker_setup_dialog" "install_ui";;
|
||||||
3)
|
3)
|
||||||
@@ -63,3 +66,33 @@ install_menu(){
|
|||||||
done
|
done
|
||||||
install_menu
|
install_menu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function select_klipper_python_version(){
|
||||||
|
top_border
|
||||||
|
echo -e "| Please select the preferred Python version. | "
|
||||||
|
echo -e "| The recommended version is Python 2.7. | "
|
||||||
|
blank_line
|
||||||
|
echo -e "| Installing Klipper with Python 3 is officially not | "
|
||||||
|
echo -e "| recommended and should be considered as experimental. | "
|
||||||
|
hr
|
||||||
|
echo -e "| 1) [Python 2.7] (recommended) | "
|
||||||
|
echo -e "| 2) [Python 3.x] ${yellow}(experimental)${white} | "
|
||||||
|
back_footer
|
||||||
|
while true; do
|
||||||
|
read -p "${cyan}###### Select Python version:${white} " action; echo
|
||||||
|
case "${action}" in
|
||||||
|
1)
|
||||||
|
select_msg "Python 2.7"
|
||||||
|
klipper_setup_dialog "python2"
|
||||||
|
break;;
|
||||||
|
2)
|
||||||
|
select_msg "Python 3.x"
|
||||||
|
klipper_setup_dialog "python3"
|
||||||
|
break;;
|
||||||
|
B|b)
|
||||||
|
clear; install_menu; break;;
|
||||||
|
*)
|
||||||
|
error_msg "Invalid Input!\n";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user