From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1NqRfe-0004cm-9o for garchives@archives.gentoo.org; Sat, 13 Mar 2010 13:46:26 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5E977E0907; Sat, 13 Mar 2010 13:46:22 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 01BBFE0907 for ; Sat, 13 Mar 2010 13:46:22 +0000 (UTC) Received: from stork.gentoo.org (stork.gentoo.org [64.127.104.133]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id 85B891B4089 for ; Sat, 13 Mar 2010 13:46:21 +0000 (UTC) Received: from arfrever by stork.gentoo.org with local (Exim 4.69) (envelope-from ) id 1NqRfY-0005mH-WA for gentoo-commits@lists.gentoo.org; Sat, 13 Mar 2010 13:46:21 +0000 From: "Arfrever Frehtes Taifersar Arahesis (arfrever)" To: gentoo-commits@lists.gentoo.org Reply-To: gentoo-dev@lists.gentoo.org, arfrever@gentoo.org Subject: [gentoo-commits] gentoo-x86 commit in eclass: python.eclass X-VCS-Repository: gentoo-x86 X-VCS-Files: python.eclass X-VCS-Directories: eclass X-VCS-Committer: arfrever X-VCS-Committer-Name: Arfrever Frehtes Taifersar Arahesis Content-Type: text/plain; charset=utf8 Message-Id: Sender: Arfrever Frehtes Taifersar Arahesis Date: Sat, 13 Mar 2010 13:46:20 +0000 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 428ceddd-d518-4e82-91e6-9aff0fb1d5c2 X-Archives-Hash: c4ae680f4d2c683b57e119960143baa7 arfrever 10/03/13 13:46:20 Modified: python.eclass Log: Improve phase functions. Simplify and improve validate_PYTHON_ABIS(). Fix handling of ${S} ending in '/' in python_copy_sources() (bug #30794= 3). Improve python_generate_wrapper_scripts(). Improve python_convert_shebangs(). Add python_clean_sitedirs(). Simplify python_mod_cleanup(). Improve deprecation warnings in python_version(), python_mod_exists() a= nd python_tkinter_exists(). Revision Changes Path 1.94 eclass/python.eclass file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.ecla= ss?rev=3D1.94&view=3Dmarkup plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.ecla= ss?rev=3D1.94&content-type=3Dtext/plain diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.ecla= ss?r1=3D1.93&r2=3D1.94 Index: python.eclass =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /var/cvsroot/gentoo-x86/eclass/python.eclass,v retrieving revision 1.93 retrieving revision 1.94 diff -u -r1.93 -r1.94 --- python.eclass 12 Mar 2010 18:27:01 -0000 1.93 +++ python.eclass 13 Mar 2010 13:46:20 -0000 1.94 @@ -1,6 +1,6 @@ # Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.93 2010/03/1= 2 18:27:01 betelgeuse Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.94 2010/03/1= 3 13:46:20 arfrever Exp $ =20 # @ECLASS: python.eclass # @MAINTAINER: @@ -273,13 +273,15 @@ # @DESCRIPTION: # Set this to export phase functions for the following ebuild phases: # src_prepare, src_configure, src_compile, src_test, src_install. -if ! has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then +if ! has "${EAPI:-0}" 0 1; then python_src_prepare() { python_copy_sources } =20 for python_default_function in src_configure src_compile src_test src_i= nstall; do - eval "python_${python_default_function}() { python_execute_function -d= -s; }" + eval "python_${python_default_function}() { + python_execute_function -d -s \"\$@\" + }" done unset python_default_function =20 @@ -308,7 +310,7 @@ PYTHON_ABI_SUPPORTED_VALUES=3D"${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTH= ON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" =20 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" =3D=3D "declare -x USE_P= YTHON=3D"* ]]; then - local python2_enabled=3D"0" python3_enabled=3D"0" + local cpython_enabled=3D"0" =20 if [[ -z "${USE_PYTHON}" ]]; then die "USE_PYTHON variable is empty" @@ -319,11 +321,8 @@ die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" fi =20 - if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}"; then - python2_enabled=3D"1" - fi - if has "${PYTHON_ABI}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then - python3_enabled=3D"1" + if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3= _SUPPORTED_ABIS[@]}"; then + cpython_enabled=3D"1" fi =20 support_ABI=3D"1" @@ -340,13 +339,7 @@ die "USE_PYTHON variable does not enable any version of Python suppo= rted by ${CATEGORY}/${PF}" fi =20 - if [[ "${python2_enabled}" =3D=3D "0" ]]; then - ewarn "USE_PYTHON variable does not enable any version of Python 2. = This configuration is unsupported." - fi - if [[ "${python3_enabled}" =3D=3D "0" ]]; then - ewarn "USE_PYTHON variable does not enable any version of Python 3. = This configuration is unsupported." - fi - if [[ "${python2_enabled}" =3D=3D "0" && "${python3_enabled}" =3D=3D = "0" ]]; then + if [[ "${cpython_enabled}" =3D=3D "0" ]]; then die "USE_PYTHON variable does not enable any version of CPython" fi else @@ -496,9 +489,6 @@ die "${FUNCNAME}(): '${function}' function is not defined" fi else - if [[ "$#" -ne 0 ]]; then - die "${FUNCNAME}(): '--default-function' option and function name can= not be specified simultaneously" - fi if has "${EAPI:-0}" 0 1; then die "${FUNCNAME}(): '--default-function' option cannot be used in thi= s EAPI" fi @@ -506,28 +496,28 @@ if [[ "${EBUILD_PHASE}" =3D=3D "configure" ]]; then if has "${EAPI}" 2 3; then python_default_function() { - econf + econf "$@" } else python_default_function() { - nonfatal econf + nonfatal econf "$@" } fi elif [[ "${EBUILD_PHASE}" =3D=3D "compile" ]]; then python_default_function() { - emake + emake "$@" } elif [[ "${EBUILD_PHASE}" =3D=3D "test" ]]; then python_default_function() { if emake -j1 -n check &> /dev/null; then - emake -j1 check + emake -j1 check "$@" elif emake -j1 -n test &> /dev/null; then - emake -j1 test + emake -j1 test "$@" fi } elif [[ "${EBUILD_PHASE}" =3D=3D "install" ]]; then python_default_function() { - emake DESTDIR=3D"${D}" install + emake DESTDIR=3D"${D}" install "$@" } else die "${FUNCNAME}(): '--default-function' option cannot be used in thi= s ebuild phase" @@ -665,7 +655,7 @@ if [[ "${WORKDIR}" =3D=3D "${S}" ]]; then die "${FUNCNAME}() cannot be used" fi - dirs=3D("${S}") + dirs=3D("${S%/}") else dirs=3D("$@") fi @@ -761,12 +751,12 @@ fi =20 if [[ "${quiet}" =3D=3D "0" ]]; then - einfo "Generating '${file#${D%/}}' wrapper script" + einfo "Generating '${file#${ED%/}}' wrapper script" fi =20 cat << EOF > "${file}" #!/usr/bin/env python -# Gentoo '${file##*/}' wrapper script +# Gentoo '${file##*/}' wrapper script generated by python_generate_wrapp= er_scripts() =20 import os import re @@ -774,6 +764,8 @@ import sys =20 EPYTHON_re =3D re.compile(r"^python(\d+\.\d+)$") +python_shebang_re =3D re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EP= REFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") +python_verification_output_re =3D re.compile("^GENTOO_PYTHON_TARGET_SCRI= PT_PATH supported\n$") =20 EOF if [[ "$?" !=3D "0" ]]; then @@ -798,16 +790,16 @@ sys.stderr.write("Execution of 'eselect python show${eselect_python_op= tion:+ }${eselect_python_option}' failed\n") sys.exit(1) =20 - eselect_output =3D eselect_process.stdout.read() - if not isinstance(eselect_output, str): + EPYTHON =3D eselect_process.stdout.read().rstrip("\n") + if not isinstance(EPYTHON, str): # Python 3 - eselect_output =3D eselect_output.decode() + EPYTHON =3D EPYTHON.decode() =20 - EPYTHON_matched =3D EPYTHON_re.match(eselect_output) + EPYTHON_matched =3D EPYTHON_re.match(EPYTHON) if EPYTHON_matched: PYTHON_ABI =3D EPYTHON_matched.group(1) else: - sys.stderr.write("'eselect python show${eselect_python_option:+ }${ese= lect_python_option}' printed unrecognized value '%s" % eselect_output) + sys.stderr.write("'eselect python show${eselect_python_option:+ }${ese= lect_python_option}' printed unrecognized value '%s" % EPYTHON) sys.exit(1) EOF if [[ "$?" !=3D "0" ]]; then @@ -823,16 +815,16 @@ sys.stderr.write("Execution of 'eselect python show${eselect_python_opt= ion:+ }${eselect_python_option}' failed\n") sys.exit(1) =20 -eselect_output =3D eselect_process.stdout.read() -if not isinstance(eselect_output, str): +EPYTHON =3D eselect_process.stdout.read().rstrip("\n") +if not isinstance(EPYTHON, str): # Python 3 - eselect_output =3D eselect_output.decode() + EPYTHON =3D EPYTHON.decode() =20 -EPYTHON_matched =3D EPYTHON_re.match(eselect_output) +EPYTHON_matched =3D EPYTHON_re.match(EPYTHON) if EPYTHON_matched: PYTHON_ABI =3D EPYTHON_matched.group(1) else: - sys.stderr.write("'eselect python show${eselect_python_option:+ }${esel= ect_python_option}' printed unrecognized value '%s" % eselect_output) + sys.stderr.write("'eselect python show${eselect_python_option:+ }${esel= ect_python_option}' printed unrecognized value '%s" % EPYTHON) sys.exit(1) EOF if [[ "$?" !=3D "0" ]]; then @@ -841,13 +833,47 @@ fi cat << EOF >> "${file}" =20 -os.environ["PYTHON_SCRIPT_NAME"] =3D sys.argv[0] -target_executable =3D "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_A= BI) -if not os.path.exists(target_executable): - sys.stderr.write("'%s' does not exist\n" % target_executable) +wrapper_script_path =3D os.path.realpath(sys.argv[0]) +target_executable_path =3D "%s-%s" % (wrapper_script_path, PYTHON_ABI) +os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] =3D sys.argv[0] +os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] =3D target_executable_pat= h +if not os.path.exists(target_executable_path): + sys.stderr.write("'%s' does not exist\n" % target_executable_path) sys.exit(1) =20 -os.execv(target_executable, sys.argv) +target_executable =3D open(target_executable_path, "rb") +target_executable_first_line =3D target_executable.readline() +if not isinstance(target_executable_first_line, str): + # Python 3 + target_executable_first_line =3D target_executable_first_line.decode("u= tf_8", "replace") + +python_shebang_matched =3D python_shebang_re.match(target_executable_fir= st_line) +target_executable.close() + +if python_shebang_matched: + try: + python_interpreter_path =3D "${EPREFIX}/usr/bin/%s" % EPYTHON + os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] =3D "1" + python_verification_process =3D subprocess.Popen([python_interpreter_p= ath, "-c", "pass"], stdout=3Dsubprocess.PIPE) + del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] + if python_verification_process.wait() !=3D 0: + raise ValueError + + python_verification_output =3D python_verification_process.stdout.read= () + if not isinstance(python_verification_output, str): + # Python 3 + python_verification_output =3D python_verification_output.decode() + + if not python_verification_output_re.match(python_verification_output)= : + raise ValueError + + os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv= ) + except: + pass + if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ: + del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] + +os.execv(target_executable_path, sys.argv) EOF if [[ "$?" !=3D "0" ]]; then die "${FUNCNAME}(): Generation of '$1' failed" @@ -1019,7 +1045,7 @@ elif [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then PYTHON_ABI=3D"$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACT= ION_COMMAND}")" elif [[ -z "${PYTHON_ABI}" ]]; then - die "${FUNCNAME}(): Invalid usage: Python ABI not specified" + die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in AB= I-specific local scope" fi elif [[ "$#" -eq 1 ]]; then if [[ "${final_ABI}" =3D=3D "1" ]]; then @@ -1487,9 +1513,12 @@ [[ "${only_executables}" =3D=3D "1" && ! -x "${file}" ]] && continue =20 if [[ "$(head -n1 "${file}")" =3D~ ^'#!'.*python ]]; then + [[ "$(sed -ne "2p" "${file}")" =3D~ ^"# Gentoo '".*"' wrapper script = generated by python_generate_wrapper_scripts()"$ ]] && continue + if [[ "${quiet}" =3D=3D "0" ]]; then einfo "Converting shebang in '${file}'" fi + sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${pyt= hon_version}/" -i "${file}" || die "Conversion of shebang in '${file}' fa= iled" =20 # Delete potential whitespace after "#!". @@ -1498,6 +1527,15 @@ done } =20 +# @FUNCTION: python_clean_sitedirs +# @DESCRIPTION: +# Delete needless files in site-packages directories in ${ED}. +python_clean_sitedirs() { + _python_initialize_prefix_variables + + find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o = -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f +} + # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D FUNCTIONS FOR RUNNING OF TESTS =3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -1984,27 +2022,27 @@ if [[ "${REPLY}" =3D=3D *[co] ]]; then py_file=3D"${REPLY%[co]}" [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]]= && continue - einfo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" + echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" rm -f "${py_file}"[co] elif [[ "${REPLY}" =3D=3D *\$py.class ]]; then py_file=3D"${REPLY%\$py.class}.py" [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continu= e - einfo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" + echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" rm -f "${py_file%.py}\$py.class" fi done =20 # Attempt to delete directories, which may be empty. find "${path}" -type d | sort -r | while read -r dir; do - rmdir "${dir}" 2>/dev/null && einfo "${_CYAN}<<< ${dir}${_NORMAL}" + rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" done elif [[ "${path}" =3D=3D *.py && ! -f "${path}" ]]; then if [[ (-f "${path}c" || -f "${path}o") ]]; then - einfo "${_BLUE}<<< ${path}[co]${_NORMAL}" + echo "${_BLUE}<<< ${path}[co]${_NORMAL}" rm -f "${path}"[co] fi if [[ -f "${path%.py}\$py.class" ]]; then - einfo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" + echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" rm -f "${path%.py}\$py.class" fi fi @@ -2029,6 +2067,7 @@ einfo einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be ba= nned on 2010-07-01." einfo "Use PYTHON() instead of python variable. Use python_get_*() ins= tead of PYVER* variables." + einfo "The ebuild needs to be fixed. Please report a bug, if it has no= t been already reported." einfo fi =20 @@ -2066,6 +2105,7 @@ einfo einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be ban= ned on 2010-07-01." einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}= ()." + einfo "The ebuild needs to be fixed. Please report a bug, if it has not= been already reported." einfo =20 if [[ "$#" -ne 1 ]]; then @@ -2088,6 +2128,7 @@ einfo einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be ba= nned on 2010-07-01." einfo "Use PYTHON_USE_WITH=3D\"xml\" and python_pkg_setup() instead of= ${FUNCNAME}()." + einfo "The ebuild needs to be fixed. Please report a bug, if it has no= t been already reported." einfo fi =20