From 1aca7a6adf643afde027778f1acbde7226dcea72 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 14 Aug 2010 00:28:36 +0200 Subject: Ensure that all Python processes use the same version of Python. --- bin/ebuild-helpers/dohtml | 8 +++----- bin/ebuild-helpers/portageq | 8 +++----- bin/ebuild-ipc | 6 ++---- bin/ebuild.sh | 22 ++++++++-------------- bin/misc-functions.sh | 8 ++++---- pym/portage/__init__.py | 2 ++ pym/portage/tests/ebuild/test_ipc_daemon.py | 2 ++ 7 files changed, 24 insertions(+), 32 deletions(-) diff --git a/bin/ebuild-helpers/dohtml b/bin/ebuild-helpers/dohtml index e1ab7d970..6de730c6d 100755 --- a/bin/ebuild-helpers/dohtml +++ b/bin/ebuild-helpers/dohtml @@ -1,15 +1,13 @@ #!/bin/bash -# Copyright 2009 Gentoo Foundation +# Copyright 2009-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH:-/usr/lib/portage/bin} PORTAGE_PYM_PATH=${PORTAGE_PYM_PATH:-/usr/lib/portage/pym} -# Set EPYTHON variable as empty so that dohtml.py doesn't try -# to use potentially unsupported version of Python. -EPYTHON= PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ - "$PORTAGE_BIN_PATH/dohtml.py" "$@" +PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ + "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH/dohtml.py" "$@" ret=$? [[ $ret -ne 0 ]] && helpers_die "$0 failed" diff --git a/bin/ebuild-helpers/portageq b/bin/ebuild-helpers/portageq index 3a06fdd68..8dee54c32 100755 --- a/bin/ebuild-helpers/portageq +++ b/bin/ebuild-helpers/portageq @@ -1,10 +1,8 @@ #!/bin/bash -# Copyright 2009 Gentoo Foundation +# Copyright 2009-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH:-/usr/lib/portage/bin} PORTAGE_PYM_PATH=${PORTAGE_PYM_PATH:-/usr/lib/portage/pym} -# Set EPYTHON variable as empty so that portageq doesn't try -# to use potentially unsupported version of Python. -EPYTHON= PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ - exec "$PORTAGE_BIN_PATH/portageq" "$@" +PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ + exec "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH/portageq" "$@" diff --git a/bin/ebuild-ipc b/bin/ebuild-ipc index b828a35cd..45d0f15b8 100755 --- a/bin/ebuild-ipc +++ b/bin/ebuild-ipc @@ -4,7 +4,5 @@ PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH:-/usr/lib/portage/bin} PORTAGE_PYM_PATH=${PORTAGE_PYM_PATH:-/usr/lib/portage/pym} -# Set EPYTHON variable as empty so that ebuild-ipc.py doesn't try -# to use potentially unsupported version of Python. -EPYTHON= PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ - exec "$PORTAGE_BIN_PATH/ebuild-ipc.py" "$@" +PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ + exec "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH/ebuild-ipc.py" "$@" diff --git a/bin/ebuild.sh b/bin/ebuild.sh index 9af7e3867..6a2eeb1e6 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 1999-2009 Gentoo Foundation +# Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 PORTAGE_BIN_PATH="${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}" @@ -164,10 +164,8 @@ has_version() { return $? fi - # Set EPYTHON variable as empty so that portageq doesn't try - # to use potentially unsupported version of Python. - EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "${PORTAGE_BIN_PATH}"/portageq has_version "${ROOT}" "$1" + PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ + "$PORTAGE_PYTHON" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1" local retval=$? case "${retval}" in 0) @@ -187,10 +185,8 @@ portageq() { die "portageq calls are not allowed in the global scope" fi - # Set EPYTHON variable as empty so that portageq doesn't try - # to use potentially unsupported version of Python. - EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "${PORTAGE_BIN_PATH}/portageq" "$@" + PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ + "$PORTAGE_PYTHON" "${PORTAGE_BIN_PATH}/portageq" "$@" } @@ -211,10 +207,8 @@ best_version() { return $? fi - # Set EPYTHON variable as empty so that portageq doesn't try - # to use potentially unsupported version of Python. - EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1" + PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ + "$PORTAGE_PYTHON" "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1" local retval=$? case "${retval}" in 0) @@ -1734,7 +1728,7 @@ filter_readonly_variables() { " fi - EPYTHON= "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed" + "$PORTAGE_PYTHON" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed" } # @FUNCTION: preprocess_ebuild_env diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh index c965495b6..8207006ed 100755 --- a/bin/misc-functions.sh +++ b/bin/misc-functions.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 1999-2009 Gentoo Foundation +# Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # # Miscellaneous shell functions that make use of the ebuild env but don't need @@ -489,7 +489,7 @@ install_qa_check() { done [[ $reset_debug = 1 ]] && set -x f=$(cat "${PORTAGE_LOG_FILE}" | \ - EPYTHON= "$PORTAGE_BIN_PATH"/check-implicit-pointer-usage.py || die "check-implicit-pointer-usage.py failed") + "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH"/check-implicit-pointer-usage.py || die "check-implicit-pointer-usage.py failed") if [[ -n ${f} ]] ; then # In the future this will be a forced "die". In preparation, @@ -778,8 +778,8 @@ dyn_package() { tar $tar_options -cf - $PORTAGE_BINPKG_TAR_OPTS -C "${D}" . | \ bzip2 -cf > "$PORTAGE_BINPKG_TMPFILE" assert "failed to pack binary package: '$PORTAGE_BINPKG_TMPFILE'" - EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "$PORTAGE_BIN_PATH"/xpak-helper.py recompose \ + PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ + "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH"/xpak-helper.py recompose \ "$PORTAGE_BINPKG_TMPFILE" "$PORTAGE_BUILDDIR/build-info" if [ $? -ne 0 ]; then rm -f "${PORTAGE_BINPKG_TMPFILE}" diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index a6760b245..fb4c66cb1 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -325,6 +325,8 @@ except (ImportError, OSError) as e: # END OF IMPORTS -- END OF IMPORTS -- END OF IMPORTS -- END OF IMPORTS -- END # =========================================================================== +os.environ['PORTAGE_PYTHON'] = sys.executable + def _ensure_default_encoding(): default_encoding = sys.getdefaultencoding().lower().replace('-', '_') diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py b/pym/portage/tests/ebuild/test_ipc_daemon.py index de548c6f1..4b7406deb 100644 --- a/pym/portage/tests/ebuild/test_ipc_daemon.py +++ b/pym/portage/tests/ebuild/test_ipc_daemon.py @@ -1,6 +1,7 @@ # Copyright 2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +import os import shutil import tempfile from portage import os @@ -19,6 +20,7 @@ class IpcDaemonTestCase(TestCase): tmpdir = tempfile.mkdtemp() try: env = {} + env['PORTAGE_PYTHON'] = os.environ['PORTAGE_PYTHON'] env['PORTAGE_BIN_PATH'] = PORTAGE_BIN_PATH env['PORTAGE_PYM_PATH'] = PORTAGE_PYM_PATH env['PORTAGE_BUILDDIR'] = tmpdir -- cgit v1.2.3-1-g7c22 From 760da1a0666762b23804e76c2b4376c23a7824b8 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 14 Aug 2010 00:41:28 +0200 Subject: Add a script, which simplifies testing with multiple versions of Python. --- runtests.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 runtests.sh diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 000000000..1afbfb3f4 --- /dev/null +++ b/runtests.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +PYTHON_VERSIONS="2.6 2.7 3.1 3.2" + +exit_status="0" +for version in ${PYTHON_VERSIONS}; do + if [[ -x /usr/bin/python${version} ]]; then + echo -e "\e[1;32mTesting with Python ${version}...\e[0m" + if ! PYTHONPATH="pym${PYTHONPATH:+:}${PYTHONPATH}" /usr/bin/python${version} pym/portage/tests/runTests; then + echo -e "\e[1;31mTesting with Python ${version} failed\e[0m" + exit_status="1" + fi + echo + fi +done + +exit ${exit_status} -- cgit v1.2.3-1-g7c22 From 247a541be25a9f4cd73287bf3c6443e1e32b9047 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 14 Aug 2010 00:45:51 +0200 Subject: portage.os is apparently imported, so os doesn't need to be imported. --- pym/portage/tests/ebuild/test_ipc_daemon.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py b/pym/portage/tests/ebuild/test_ipc_daemon.py index 4b7406deb..b03409d0f 100644 --- a/pym/portage/tests/ebuild/test_ipc_daemon.py +++ b/pym/portage/tests/ebuild/test_ipc_daemon.py @@ -1,7 +1,6 @@ # Copyright 2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -import os import shutil import tempfile from portage import os -- cgit v1.2.3-1-g7c22 From 216aeb7ab4854b278c809f07528534aefd44174d Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 14 Aug 2010 02:15:08 +0200 Subject: Set PORTAGE_PYTHON in processes executed by portage.process._exec(). --- pym/portage/process.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pym/portage/process.py b/pym/portage/process.py index 9f6ec0e56..331e88059 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -355,7 +355,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, # Then assign them to what they should be. for fd in my_fds: os.dup2(my_fds[fd], fd) - # Then close _all_ fds that haven't been explictly + # Then close _all_ fds that haven't been explicitly # requested to be kept open. for fd in get_open_fds(): if fd not in my_fds: @@ -375,6 +375,9 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, os.umask(umask) if pre_exec: pre_exec() + + # Set requested Python interpreter for Portage helpers. + env['PORTAGE_PYTHON'] = sys.executable # And switch to the new process. os.execve(binary, myargs, env) -- cgit v1.2.3-1-g7c22 From 2d8eaedb61bdbe4a47d6b27c8a3e67754078773d Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 14 Aug 2010 03:11:41 +0200 Subject: Use /usr/bin/python when PORTAGE_PYTHON variable is empty. It avoids some errors during upgrade from older Portage versions. --- bin/ebuild-helpers/dohtml | 2 +- bin/ebuild-helpers/portageq | 2 +- bin/ebuild-ipc | 2 +- bin/ebuild.sh | 8 ++++---- bin/misc-functions.sh | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/ebuild-helpers/dohtml b/bin/ebuild-helpers/dohtml index 6de730c6d..cb29dc3f3 100755 --- a/bin/ebuild-helpers/dohtml +++ b/bin/ebuild-helpers/dohtml @@ -7,7 +7,7 @@ source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH:-/usr/lib/portage/bin} PORTAGE_PYM_PATH=${PORTAGE_PYM_PATH:-/usr/lib/portage/pym} PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ - "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH/dohtml.py" "$@" + "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/dohtml.py" "$@" ret=$? [[ $ret -ne 0 ]] && helpers_die "$0 failed" diff --git a/bin/ebuild-helpers/portageq b/bin/ebuild-helpers/portageq index 8dee54c32..ec30b66cb 100755 --- a/bin/ebuild-helpers/portageq +++ b/bin/ebuild-helpers/portageq @@ -5,4 +5,4 @@ PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH:-/usr/lib/portage/bin} PORTAGE_PYM_PATH=${PORTAGE_PYM_PATH:-/usr/lib/portage/pym} PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ - exec "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH/portageq" "$@" + exec "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/portageq" "$@" diff --git a/bin/ebuild-ipc b/bin/ebuild-ipc index 45d0f15b8..43e4a02ae 100755 --- a/bin/ebuild-ipc +++ b/bin/ebuild-ipc @@ -5,4 +5,4 @@ PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH:-/usr/lib/portage/bin} PORTAGE_PYM_PATH=${PORTAGE_PYM_PATH:-/usr/lib/portage/pym} PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \ - exec "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH/ebuild-ipc.py" "$@" + exec "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/ebuild-ipc.py" "$@" diff --git a/bin/ebuild.sh b/bin/ebuild.sh index 6a2eeb1e6..e9f4b96cb 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -165,7 +165,7 @@ has_version() { fi PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "$PORTAGE_PYTHON" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1" + "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1" local retval=$? case "${retval}" in 0) @@ -186,7 +186,7 @@ portageq() { fi PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "$PORTAGE_PYTHON" "${PORTAGE_BIN_PATH}/portageq" "$@" + "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@" } @@ -208,7 +208,7 @@ best_version() { fi PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "$PORTAGE_PYTHON" "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1" + "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1" local retval=$? case "${retval}" in 0) @@ -1728,7 +1728,7 @@ filter_readonly_variables() { " fi - "$PORTAGE_PYTHON" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed" + "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed" } # @FUNCTION: preprocess_ebuild_env diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh index 8207006ed..0108b001f 100755 --- a/bin/misc-functions.sh +++ b/bin/misc-functions.sh @@ -489,7 +489,7 @@ install_qa_check() { done [[ $reset_debug = 1 ]] && set -x f=$(cat "${PORTAGE_LOG_FILE}" | \ - "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH"/check-implicit-pointer-usage.py || die "check-implicit-pointer-usage.py failed") + "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH"/check-implicit-pointer-usage.py || die "check-implicit-pointer-usage.py failed") if [[ -n ${f} ]] ; then # In the future this will be a forced "die". In preparation, @@ -779,7 +779,7 @@ dyn_package() { bzip2 -cf > "$PORTAGE_BINPKG_TMPFILE" assert "failed to pack binary package: '$PORTAGE_BINPKG_TMPFILE'" PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "$PORTAGE_PYTHON" "$PORTAGE_BIN_PATH"/xpak-helper.py recompose \ + "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH"/xpak-helper.py recompose \ "$PORTAGE_BINPKG_TMPFILE" "$PORTAGE_BUILDDIR/build-info" if [ $? -ne 0 ]; then rm -f "${PORTAGE_BINPKG_TMPFILE}" -- cgit v1.2.3-1-g7c22