xbps-src: introduce python_version

This commit is contained in:
Alessio Sergi 2016-11-17 17:37:37 +01:00
parent a28fd5497d
commit 29c37543cf
4 changed files with 13 additions and 1 deletions

View File

@ -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 |

View File

@ -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))')"

View File

@ -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

View File

@ -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