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(){
|
||||
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}"
|
||||
status_msg "Initializing firmware build ..."
|
||||
dep=(build-essential dpkg-dev make)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
make clean && make menuconfig
|
||||
|
||||
status_msg "Building firmware ..."
|
||||
make && ok_msg "Firmware built!"
|
||||
else
|
||||
print_error "Klipper was not found!\n Can not build firmware without Klipper!"
|
||||
return 1
|
||||
python_version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1)
|
||||
[ "${python_version}" == "3" ] && make PYTHON=python3
|
||||
[ "${python_version}" == "2" ] && make
|
||||
ok_msg "Firmware built!"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ function klipper_exists() {
|
||||
}
|
||||
|
||||
function klipper_setup_dialog(){
|
||||
local python_version="${1}"
|
||||
status_msg "Initializing Klipper installation ..."
|
||||
|
||||
### return early if klipper already exists
|
||||
@@ -44,7 +45,7 @@ function klipper_setup_dialog(){
|
||||
if [ -n "${klipper_services}" ]; then
|
||||
local error="At least one Klipper service is already installed:"
|
||||
for s in ${klipper_services}; do
|
||||
log "Found Klipper service: ${s}"
|
||||
log_info "Found Klipper service: ${s}"
|
||||
error="${error}\n ➔ ${s}"
|
||||
done
|
||||
print_error "${error}" && return
|
||||
@@ -74,7 +75,7 @@ function klipper_setup_dialog(){
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
status_msg "Installing ${count} Klipper instance(s) ... \n"
|
||||
klipper_setup "${count}"
|
||||
klipper_setup "${count}" "${python_version}"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
@@ -89,12 +90,14 @@ function klipper_setup_dialog(){
|
||||
}
|
||||
|
||||
function install_klipper_packages(){
|
||||
local packages
|
||||
local packages python_version="${1}"
|
||||
local install_script="${HOME}/klipper/scripts/install-octopi.sh"
|
||||
|
||||
status_msg "Reading dependencies..."
|
||||
# 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
|
||||
[ -e "/boot/dietpi/.version" ] && packages+=" dbus"
|
||||
|
||||
@@ -111,15 +114,27 @@ function install_klipper_packages(){
|
||||
}
|
||||
|
||||
function create_klipper_virtualenv(){
|
||||
status_msg "Installing python virtual environment..."
|
||||
### always create a clean virtualenv
|
||||
[ -d "${KLIPPY_ENV}" ] && rm -rf "${KLIPPY_ENV}"
|
||||
virtualenv -p python2 "${KLIPPY_ENV}"
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
||||
local python_version="${1}" py2_ver py3_ver
|
||||
if [ "${python_version}" == "python2" ]; then
|
||||
py2_ver=$(python2 -V)
|
||||
status_msg "Installing ${py2_ver} virtual environment..."
|
||||
[ -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(){
|
||||
local instances=${1}
|
||||
local instances=${1} python_version=${2}
|
||||
### checking dependencies
|
||||
local dep=(git)
|
||||
dependency_check "${dep[@]}"
|
||||
@@ -131,8 +146,8 @@ function klipper_setup(){
|
||||
cd "${HOME}" && git clone "${KLIPPER_REPO}"
|
||||
|
||||
### step 2: install klipper dependencies and create python virtualenv
|
||||
install_klipper_packages
|
||||
create_klipper_virtualenv
|
||||
install_klipper_packages "${python_version}"
|
||||
create_klipper_virtualenv "${python_version}"
|
||||
|
||||
### step 3: create gcode_files and logs folder
|
||||
[ ! -d "${HOME}/gcode_files" ] && mkdir -p "${HOME}/gcode_files"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
install_ui(){
|
||||
function install_ui(){
|
||||
top_border
|
||||
echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} | "
|
||||
hr
|
||||
@@ -32,13 +32,16 @@ install_ui(){
|
||||
back_footer
|
||||
}
|
||||
|
||||
install_menu(){
|
||||
do_action "" "install_ui"
|
||||
function install_menu(){
|
||||
clear && print_header
|
||||
install_ui
|
||||
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${white} " action; echo
|
||||
case "$action" in
|
||||
1)
|
||||
do_action "klipper_setup_dialog" "install_ui";;
|
||||
case "${action}" in
|
||||
1)clear && print_header
|
||||
select_klipper_python_version
|
||||
install_ui;;
|
||||
2)
|
||||
do_action "moonraker_setup_dialog" "install_ui";;
|
||||
3)
|
||||
@@ -63,3 +66,33 @@ install_menu(){
|
||||
done
|
||||
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