Skip to content
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

Allow manual specification of python executable during build #1602

Merged
merged 5 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Version 1.4.2-dev (development of upcoming release)
* Build: Use PyLint in unit testing to catch E1101 (no-member) errors.
* Build: Activate PyLint warning W1401 (anomalous-backslash-in-string).
* Build: Add codespell config.
* Build: Allow manual specification of python executable (--python=PYTHON_PATH) in common/configure and qt/configure
* Translation: Minor modifications in source strings and updating language files.
* Improved: qtsystrayicon.py, qt5_probing.py, usercallbackplugin.py and all parts of app.py
do now also use "backintime" as logging namespace in the syslog to ensure complete log output with `journalctl | grep -i backintime`
Expand Down
35 changes: 21 additions & 14 deletions common/configure
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ UNINSTALL_FILES="$(mktemp)"
UNINSTALL_DIRS="$(mktemp)"

#set default options
PYTHON="--python3"
PYTHON="python3"

USR_BIN_FILES="backintime backintime-askpass"

usage () {
echo "Usage:"
echo "$0 [--python | --python3]"
echo "$0 [--python | --python3 | --python=PYTHON_BINARY]"
echo ""
echo "--python"
echo "\tuse 'python' to start Python3"
echo "--python3"
echo "\tuse 'python3' to start Python3"
echo "--python=PYTHON_BINARY"
echo "\tuse PYTHON_BINARY to start Python3"
}

addInstallFiles () {
Expand Down Expand Up @@ -113,7 +115,15 @@ onTravis () {
unknown_args=""
for arg in $*; do
case $arg in
--python | --python3) PYTHON=$arg;;
--python=*)
PYTHON=$(echo $arg | cut -f2 -d'=')
;;
--python3)
PYTHON="/usr/bin/python3"
;;
--python)
PYTHON="/usr/bin/python"
;;
--help | -h) usage; exit 0;;
*) unknown_args="$unknown_args $arg";;
esac
Expand All @@ -123,15 +133,12 @@ if [ -n "$unknown_args" ]; then
echo "Unknown Arguments: $unknown_args"
fi

#patch python command
#use 'python' or 'python3' to start Python Version 3.x
case $PYTHON in
--python) PYVERSION="" ;;
--python3) PYVERSION="3";;
esac
sed -e "s/^python3\? /python${PYVERSION} /g" \
-e "s/^ssh-agent python3\? /ssh-agent python${PYVERSION} /g" \
-i $USR_BIN_FILES
if [ -n "$(sed -e "s#^python3\? #${PYTHON} #gw /dev/stdout" -i $USR_BIN_FILES)" ]
then
echo "Replacement of python path with \"${PYTHON}\" successful."
else
echo "WARNING: Replacement of python path with \"${PYTHON}\" FAILED. Maybe you ran configure more than once?"
fi

#check languages
mos=""
Expand Down Expand Up @@ -276,7 +283,7 @@ COVERAGE=$(which coverage 2>/dev/null)
if onTravis && [ -n "${COVERAGE}" ]; then
CMD="coverage run -p"
else
CMD="python${PYVERSION}"
CMD="${PYTHON}"
fi

printf "test:\tunittest\n\n" >> ${MAKEFILE}
Expand Down Expand Up @@ -324,7 +331,7 @@ done

# check python version
PYTHON_VERSION_REQUIRED="3.8"
PYTHON_VERSION_CURRENT=$(python${PYVERSION} --version | tr --delete 'Python ')
PYTHON_VERSION_CURRENT=$(${PYTHON} --version | tr --delete 'Python ')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful code now, well done 😃


# Credits: https://unix.stackexchange.com/a/285928/136851
if [ "$(printf '%s\n' "$PYTHON_VERSION_REQUIRED" "$PYTHON_VERSION_CURRENT" | sort -V | head -n1)" != "$PYTHON_VERSION_REQUIRED" ]; then
Expand Down
38 changes: 23 additions & 15 deletions qt/configure
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ UNINSTALL_FILES="$(mktemp)"
UNINSTALL_DIRS="$(mktemp)"

#set default options
PYTHON="--python3"
PYTHON="python3"

USR_BIN_FILES="backintime-qt backintime-qt_polkit"
DBUS_SERVICE_FILES="net.launchpad.backintime.serviceHelper.service"

usage () {
echo "Usage:"
echo "$0 [--python | --python3]"
echo "$0 [--python | --python3 | --python=PYTHON_BINARY]"
echo ""
echo "--python"
echo "\tuse 'python' to start Python3"
echo "--python3"
echo "\tuse 'python3' to start Python3"
echo "--python=PYTHON_BINARY"
echo "\tuse PYTHON_BINARY to start Python3"
}

addInstallFiles () {
Expand Down Expand Up @@ -98,9 +100,17 @@ addNewline () {
unknown_args=""
for arg in $*; do
case $arg in
--python | --python3) PYTHON=$arg;;
--help | -h) usage; exit 0;;
*) unknown_args="$unknown_args $arg";;
--python=*)
PYTHON=$(echo $arg | cut -f2 -d'=')
;;
--python3)
PYTHON="/usr/bin/python3"
;;
--python)
PYTHON="/usr/bin/python"
;;
--help | -h) usage; exit 0;;
*) unknown_args="$unknown_args $arg";;
esac
done

Expand All @@ -110,15 +120,13 @@ fi

#patch python command
#use 'python' or 'python3' to start Python Version 3.x
case $PYTHON in
--python) PYVERSION="" ;;
--python3) PYVERSION="3";;
esac
sed -e "s#^python3\? #python${PYVERSION} #g" \
-e "s#^ssh-agent python3\? #ssh-agent python${PYVERSION} #g" \
-i $USR_BIN_FILES
sed -e "s#^Exec=/usr/bin/python3\? #Exec=/usr/bin/python${PYVERSION} #g" \
-i $DBUS_SERVICE_FILES
if [ -n "$(sed -e "s#^python3\? #${PYTHON} #gw /dev/stdout" -i $USR_BIN_FILES)" ] \
&& [ -n "$(sed -e "s#^Exec=/usr/bin/python3\? #Exec=${PYTHON} #gw /dev/stdout" -i $DBUS_SERVICE_FILES)" ]
then
echo "Replacement of python path with \"${PYTHON}\" successful."
else
echo "WARNING: Replacement of python path with \"${PYTHON}\" FAILED. Maybe you ran configure more than once?"
fi

#start Makefile
printf "PREFIX=/usr\n" >> ${MAKEFILE}
Expand Down Expand Up @@ -233,7 +241,7 @@ done

# check python version
PYTHON_VERSION_REQUIRED="3.8"
PYTHON_VERSION_CURRENT=$(python${PYVERSION} --version | tr --delete 'Python ')
PYTHON_VERSION_CURRENT=$(${PYTHON} --version | tr --delete 'Python ')

# Credits: https://unix.stackexchange.com/a/285928/136851
if [ "$(printf '%s\n' "$PYTHON_VERSION_REQUIRED" "$PYTHON_VERSION_CURRENT" | sort -V | head -n1)" != "$PYTHON_VERSION_REQUIRED" ]; then
Expand Down