diff --git a/Manual.md b/Manual.md index 46a994c582e..b18000aff78 100644 --- a/Manual.md +++ b/Manual.md @@ -1107,6 +1107,11 @@ By default it's set to `2.7` for `python 2.x` packages. > NOTE: you need to define it *only* for non-Python modules. +- `python_version`: this variable expects the supported Python major version. +By default it's set to `2`. This variable is needed for multi-language +applications (e.g., the application is written in C while the command is +written in Python) or just single Python file ones that live in `/usr/bin`. + Also, a set of useful variables are defined to use in the templates: | Variable | Value | diff --git a/common/environment/setup/python.sh b/common/environment/setup/python.sh index 5f3209aa0c4..9b712a7baed 100644 --- a/common/environment/setup/python.sh +++ b/common/environment/setup/python.sh @@ -4,6 +4,9 @@ __python2="/usr/bin/python2" __python3="/usr/bin/python3" +# set version 2 as the default Python +python_version="2" + if [ -x ${__python2} ]; then py2_ver="$(${__python2} -c 'import sys; print(sys.version[:3])')" py2_lib="$(${__python2} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib(0, 1))')" diff --git a/common/environment/setup/sourcepkg.sh b/common/environment/setup/sourcepkg.sh index 435e1438c6a..ab57f0fd208 100644 --- a/common/environment/setup/sourcepkg.sh +++ b/common/environment/setup/sourcepkg.sh @@ -5,7 +5,7 @@ unset -v pkgname version revision short_desc homepage license maintainer unset -v only_for_archs distfiles checksum build_style nocross broken unset -v configure_script configure_args wrksrc build_wrksrc create_wrksrc -unset -v make_cmd make_build_args make_install_args make_build_target make_install_target stackage +unset -v make_cmd make_build_args make_install_args make_build_target make_install_target python_version stackage unset -v patch_args disable_parallel_build keep_libtool_archives unset -v reverts subpackages makedepends hostmakedepends depends restricted unset -v nopie build_options build_options_default bootstrap repository reverts diff --git a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh index ebd8d55db97..40487d73a7c 100644 --- a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh +++ b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh @@ -14,6 +14,10 @@ hook() { pyver="$pycompile_version" fi + if [ "$python_version" = "3" ]; then + pyver="$python_version" + fi + shebang="#!/usr/bin/python${pyver%.*}" find ${PKGDESTDIR} -type f -print0 | \ xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]*\|$\)" -- | while IFS=: read -r f off _; do