/[gentoo-x86]/eclass/python.eclass
Gentoo

Diff of /eclass/python.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.128 Revision 1.139
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2011 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.128 2011/08/19 10:10:03 lxnay Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.139 2011/10/15 20:58:08 phajdan.jr Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: Eclass for Python packages 8# @BLURB: Eclass for Python packages
9# @DESCRIPTION: 9# @DESCRIPTION:
10# The python eclass contains miscellaneous, useful functions for Python packages. 10# The python eclass contains miscellaneous, useful functions for Python packages.
11 11
12inherit multilib 12inherit multilib
13 13
14if ! has "${EAPI:-0}" 0 1 2 3; then 14if ! has "${EAPI:-0}" 0 1 2 3 4; then
15 die "API of python.eclass in EAPI=\"${EAPI}\" not established" 15 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
16fi 16fi
17 17
18_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) 18_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2 3.3) 19_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2)
20_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) 20_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython)
21_PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.5) 21_PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.5)
22_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) 22_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]})
23 23
24# ================================================================================================ 24# ================================================================================================
398 398
399# @FUNCTION: python_pkg_setup 399# @FUNCTION: python_pkg_setup
400# @DESCRIPTION: 400# @DESCRIPTION:
401# Perform sanity checks and initialize environment. 401# Perform sanity checks and initialize environment.
402# 402#
403# This function is exported in EAPI 2 and 3. Calling of this function is mandatory in EAPI >=4. 403# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
404# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
404python_pkg_setup() { 405python_pkg_setup() {
405 if [[ "${EBUILD_PHASE}" != "setup" ]]; then 406 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
406 die "${FUNCNAME}() can be used only in pkg_setup() phase" 407 die "${FUNCNAME}() can be used only in pkg_setup() phase"
407 fi 408 fi
408 409
416 if _python_package_supporting_installation_for_multiple_python_abis; then 417 if _python_package_supporting_installation_for_multiple_python_abis; then
417 _python_calculate_PYTHON_ABIS 418 _python_calculate_PYTHON_ABIS
418 export EPYTHON="$(PYTHON -f)" 419 export EPYTHON="$(PYTHON -f)"
419 else 420 else
420 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" 421 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
422 fi
423
424 if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
425 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
426 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
427 use ${PYTHON_USE_WITH_OPT#!} && return
428 else
429 use !${PYTHON_USE_WITH_OPT} && return
430 fi
431 fi
432
433 python_pkg_setup_check_USE_flags() {
434 local python_atom USE_flag
435 python_atom="$(python_get_implementational_package)"
436
437 for USE_flag in ${PYTHON_USE_WITH}; do
438 if ! has_version "${python_atom}[${USE_flag}]"; then
439 eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
440 die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
441 fi
442 done
443
444 for USE_flag in ${PYTHON_USE_WITH_OR}; do
445 if has_version "${python_atom}[${USE_flag}]"; then
446 return
447 fi
448 done
449
450 if [[ ${PYTHON_USE_WITH_OR} ]]; then
451 eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
452 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
453 fi
454 }
455
456 if _python_package_supporting_installation_for_multiple_python_abis; then
457 PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
458 else
459 python_pkg_setup_check_USE_flags
460 fi
461
462 unset -f python_pkg_setup_check_USE_flags
421 fi 463 fi
422 464
423 PYTHON_PKG_SETUP_EXECUTED="1" 465 PYTHON_PKG_SETUP_EXECUTED="1"
424} 466}
425 467
1189import os 1231import os
1190import re 1232import re
1191import subprocess 1233import subprocess
1192import sys 1234import sys
1193 1235
1194cpython_re = re.compile(r"^python(\d+\.\d+)$") 1236cpython_ABI_re = re.compile(r"^(\d+\.\d+)$")
1237jython_ABI_re = re.compile(r"^(\d+\.\d+)-jython$")
1238pypy_ABI_re = re.compile(r"^\d+\.\d+-pypy-(\d+\.\d+)$")
1239cpython_interpreter_re = re.compile(r"^python(\d+\.\d+)$")
1195jython_re = re.compile(r"^jython(\d+\.\d+)$") 1240jython_interpreter_re = re.compile(r"^jython(\d+\.\d+)$")
1196pypy_re = re.compile(r"^pypy-c(\d+\.\d+)$") 1241pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$")
1197python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") 1242cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)")
1243python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)")
1198python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") 1244python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1199 1245
1200pypy_versions_mapping = { 1246pypy_versions_mapping = {
1201 "1.5": "2.7" 1247 "1.5": "2.7"
1202} 1248}
1203 1249
1204def get_PYTHON_ABI(EPYTHON): 1250def get_PYTHON_ABI(python_interpreter):
1205 cpython_matched = cpython_re.match(EPYTHON) 1251 cpython_matched = cpython_interpreter_re.match(python_interpreter)
1206 jython_matched = jython_re.match(EPYTHON) 1252 jython_matched = jython_interpreter_re.match(python_interpreter)
1207 pypy_matched = pypy_re.match(EPYTHON) 1253 pypy_matched = pypy_interpreter_re.match(python_interpreter)
1208 if cpython_matched is not None: 1254 if cpython_matched is not None:
1209 PYTHON_ABI = cpython_matched.group(1) 1255 PYTHON_ABI = cpython_matched.group(1)
1210 elif jython_matched is not None: 1256 elif jython_matched is not None:
1211 PYTHON_ABI = jython_matched.group(1) + "-jython" 1257 PYTHON_ABI = jython_matched.group(1) + "-jython"
1212 elif pypy_matched is not None: 1258 elif pypy_matched is not None:
1213 PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1) 1259 PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1)
1214 else: 1260 else:
1215 PYTHON_ABI = None 1261 PYTHON_ABI = None
1216 return PYTHON_ABI 1262 return PYTHON_ABI
1217 1263
1264def get_python_interpreter(PYTHON_ABI):
1265 cpython_matched = cpython_ABI_re.match(PYTHON_ABI)
1266 jython_matched = jython_ABI_re.match(PYTHON_ABI)
1267 pypy_matched = pypy_ABI_re.match(PYTHON_ABI)
1268 if cpython_matched is not None:
1269 python_interpreter = "python" + cpython_matched.group(1)
1270 elif jython_matched is not None:
1271 python_interpreter = "jython" + jython_matched.group(1)
1272 elif pypy_matched is not None:
1273 python_interpreter = "pypy-c" + pypy_matched.group(1)
1274 else:
1275 python_interpreter = None
1276 return python_interpreter
1277
1218EOF 1278EOF
1219 if [[ "$?" != "0" ]]; then 1279 if [[ "$?" != "0" ]]; then
1220 die "${FUNCNAME}(): Generation of '$1' failed" 1280 die "${FUNCNAME}(): Generation of '$1' failed"
1221 fi 1281 fi
1222 if [[ "${respect_EPYTHON}" == "1" ]]; then 1282 if [[ "${respect_EPYTHON}" == "1" ]]; then
1223 cat << EOF >> "${file}" 1283 cat << EOF >> "${file}"
1224EPYTHON = os.environ.get("EPYTHON") 1284python_interpreter = os.environ.get("EPYTHON")
1225if EPYTHON: 1285if python_interpreter:
1226 PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1286 PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1227 if PYTHON_ABI is None: 1287 if PYTHON_ABI is None:
1228 sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) 1288 sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
1229 sys.exit(1) 1289 sys.exit(1)
1230else: 1290else:
1231 try: 1291 try:
1232 environment = os.environ.copy() 1292 environment = os.environ.copy()
1233 environment["ROOT"] = "/" 1293 environment["ROOT"] = "/"
1236 raise ValueError 1296 raise ValueError
1237 except (OSError, ValueError): 1297 except (OSError, ValueError):
1238 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0]) 1298 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
1239 sys.exit(1) 1299 sys.exit(1)
1240 1300
1241 EPYTHON = eselect_process.stdout.read() 1301 python_interpreter = eselect_process.stdout.read()
1242 if not isinstance(EPYTHON, str): 1302 if not isinstance(python_interpreter, str):
1243 # Python 3 1303 # Python 3
1244 EPYTHON = EPYTHON.decode() 1304 python_interpreter = python_interpreter.decode()
1245 EPYTHON = EPYTHON.rstrip("\n") 1305 python_interpreter = python_interpreter.rstrip("\n")
1246 1306
1247 PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1307 PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1248 if PYTHON_ABI is None: 1308 if PYTHON_ABI is None:
1249 sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) 1309 sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
1250 sys.exit(1) 1310 sys.exit(1)
1251 1311
1252wrapper_script_path = os.path.realpath(sys.argv[0]) 1312wrapper_script_path = os.path.realpath(sys.argv[0])
1253target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1313target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1254if not os.path.exists(target_executable_path): 1314if not os.path.exists(target_executable_path):
1268 raise ValueError 1328 raise ValueError
1269except (OSError, ValueError): 1329except (OSError, ValueError):
1270 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0]) 1330 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
1271 sys.exit(1) 1331 sys.exit(1)
1272 1332
1273EPYTHON = eselect_process.stdout.read() 1333python_interpreter = eselect_process.stdout.read()
1274if not isinstance(EPYTHON, str): 1334if not isinstance(python_interpreter, str):
1275 # Python 3 1335 # Python 3
1276 EPYTHON = EPYTHON.decode() 1336 python_interpreter = python_interpreter.decode()
1277EPYTHON = EPYTHON.rstrip("\n") 1337python_interpreter = python_interpreter.rstrip("\n")
1278 1338
1279PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1339PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1280if PYTHON_ABI is None: 1340if PYTHON_ABI is None:
1281 sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) 1341 sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
1282 sys.exit(1) 1342 sys.exit(1)
1283 1343
1284wrapper_script_path = os.path.realpath(sys.argv[0]) 1344wrapper_script_path = os.path.realpath(sys.argv[0])
1285for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]: 1345for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
1286 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1346 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1287 if os.path.exists(target_executable_path): 1347 if os.path.exists(target_executable_path):
1288 break 1348 break
1289else: 1349else:
1290 sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path)) 1350 sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path))
1291 sys.exit(1) 1351 sys.exit(1)
1352
1353python_interpreter = get_python_interpreter(PYTHON_ABI)
1354if python_interpreter is None:
1355 sys.stderr.write("%s: Unrecognized Python ABI '%s'\n" % (sys.argv[0], PYTHON_ABI))
1356 sys.exit(1)
1292EOF 1357EOF
1293 if [[ "$?" != "0" ]]; then 1358 if [[ "$?" != "0" ]]; then
1294 die "${FUNCNAME}(): Generation of '$1' failed" 1359 die "${FUNCNAME}(): Generation of '$1' failed"
1295 fi 1360 fi
1296 fi 1361 fi
1297 cat << EOF >> "${file}" 1362 cat << EOF >> "${file}"
1298 1363
1299target_executable = open(target_executable_path, "rb") 1364target_executable = open(target_executable_path, "rb")
1300target_executable_first_line = target_executable.readline() 1365target_executable_first_line = target_executable.readline()
1366target_executable.close()
1301if not isinstance(target_executable_first_line, str): 1367if not isinstance(target_executable_first_line, str):
1302 # Python 3 1368 # Python 3
1303 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") 1369 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
1304 1370
1371options = []
1372python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line)
1373if python_shebang_options_matched is not None:
1374 options = [python_shebang_options_matched.group(1)]
1375
1305python_shebang_matched = python_shebang_re.match(target_executable_first_line) 1376cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line)
1306target_executable.close()
1307 1377
1308if python_shebang_matched is not None: 1378if cpython_shebang_matched is not None:
1309 try: 1379 try:
1310 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON 1380 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % python_interpreter
1311 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" 1381 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1312 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) 1382 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
1313 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1383 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1314 if python_verification_process.wait() != 0: 1384 if python_verification_process.wait() != 0:
1315 raise ValueError 1385 raise ValueError
1320 python_verification_output = python_verification_output.decode() 1390 python_verification_output = python_verification_output.decode()
1321 1391
1322 if not python_verification_output_re.match(python_verification_output): 1392 if not python_verification_output_re.match(python_verification_output):
1323 raise ValueError 1393 raise ValueError
1324 1394
1325 if cpython_re.match(EPYTHON) is not None: 1395 if cpython_interpreter_re.match(python_interpreter) is not None:
1326 os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0]) 1396 os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
1327 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] 1397 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1328 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path 1398 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1329 1399
1330 if hasattr(os, "execv"): 1400 if hasattr(os, "execv"):
1331 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) 1401 os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv)
1332 else: 1402 else:
1333 sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait()) 1403 sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait())
1334 except (KeyboardInterrupt, SystemExit): 1404 except (KeyboardInterrupt, SystemExit):
1335 raise 1405 raise
1336 except: 1406 except:
1337 pass 1407 pass
1338 for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"): 1408 for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"):
1523 done 1593 done
1524 1594
1525 popd > /dev/null || die "popd failed" 1595 popd > /dev/null || die "popd failed"
1526 1596
1527 if ROOT="/" has_version sys-apps/coreutils; then 1597 if ROOT="/" has_version sys-apps/coreutils; then
1528 cp -fr --preserve=all "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" 1598 cp -fr --preserve=all --no-preserve=context "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
1529 else 1599 else
1530 cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed" 1600 cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
1531 fi 1601 fi
1532 done 1602 done
1533 1603
1551 stdout = sys.stdout.buffer 1621 stdout = sys.stdout.buffer
1552else: 1622else:
1553 # Python 2 1623 # Python 2
1554 stdout = sys.stdout 1624 stdout = sys.stdout
1555 1625
1626python_wrapper_scripts_file = open('${T}/python_wrapper_scripts', 'rb')
1556files = set(open('${T}/python_wrapper_scripts', 'rb').read().rstrip(${b}'\x00').split(${b}'\x00')) 1627files = set(python_wrapper_scripts_file.read().rstrip(${b}'\x00').split(${b}'\x00'))
1628python_wrapper_scripts_file.close()
1557 1629
1558for file in sorted(files): 1630for file in sorted(files):
1559 stdout.write(file) 1631 stdout.write(file)
1560 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts") 1632 stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts")
1561 1633
1626 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1698 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1627 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1699 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
1628} 1700}
1629 1701
1630# @FUNCTION: python_need_rebuild 1702# @FUNCTION: python_need_rebuild
1703# @DESCRIPTION:
1631# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1704# Mark current package for rebuilding by python-updater after
1632# switching of active version of Python. 1705# switching of active version of Python.
1633python_need_rebuild() { 1706python_need_rebuild() {
1634 if _python_package_supporting_installation_for_multiple_python_abis; then 1707 if _python_package_supporting_installation_for_multiple_python_abis; then
1635 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1708 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1636 fi 1709 fi
2335_python_test_hook() { 2408_python_test_hook() {
2336 if [[ "$#" -ne 1 ]]; then 2409 if [[ "$#" -ne 1 ]]; then
2337 die "${FUNCNAME}() requires 1 argument" 2410 die "${FUNCNAME}() requires 1 argument"
2338 fi 2411 fi
2339 2412
2340 if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then 2413 if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${_PYTHON_TEST_FUNCTION}_$1_hook")" == "function" ]]; then
2341 "${FUNCNAME[3]}_$1_hook" 2414 "${_PYTHON_TEST_FUNCTION}_$1_hook"
2342 fi 2415 fi
2343} 2416}
2344 2417
2345# @FUNCTION: python_execute_nosetests 2418# @FUNCTION: python_execute_nosetests
2346# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 2419# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
2380 python_test_function() { 2453 python_test_function() {
2381 local evaluated_PYTHONPATH 2454 local evaluated_PYTHONPATH
2382 2455
2383 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2456 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2384 2457
2385 _python_test_hook pre 2458 _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook pre
2386 2459
2387 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2460 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2388 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2461 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
2389 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" 2462 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
2390 else 2463 else
2391 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2464 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
2392 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" 2465 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
2393 fi 2466 fi
2394 2467
2395 _python_test_hook post 2468 _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook post
2396 } 2469 }
2397 if _python_package_supporting_installation_for_multiple_python_abis; then 2470 if _python_package_supporting_installation_for_multiple_python_abis; then
2398 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2471 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2399 else 2472 else
2400 if [[ -n "${separate_build_dirs}" ]]; then 2473 if [[ -n "${separate_build_dirs}" ]]; then
2444 python_test_function() { 2517 python_test_function() {
2445 local evaluated_PYTHONPATH 2518 local evaluated_PYTHONPATH
2446 2519
2447 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2520 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2448 2521
2449 _python_test_hook pre 2522 _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook pre
2450 2523
2451 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2524 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2452 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} 2525 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
2453 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?" 2526 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?"
2454 else 2527 else
2455 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL} 2528 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL}
2456 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?" 2529 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
2457 fi 2530 fi
2458 2531
2459 _python_test_hook post 2532 _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook post
2460 } 2533 }
2461 if _python_package_supporting_installation_for_multiple_python_abis; then 2534 if _python_package_supporting_installation_for_multiple_python_abis; then
2462 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2535 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2463 else 2536 else
2464 if [[ -n "${separate_build_dirs}" ]]; then 2537 if [[ -n "${separate_build_dirs}" ]]; then
2508 python_test_function() { 2581 python_test_function() {
2509 local evaluated_PYTHONPATH 2582 local evaluated_PYTHONPATH
2510 2583
2511 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2584 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2512 2585
2513 _python_test_hook pre 2586 _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook pre
2514 2587
2515 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2588 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2516 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2589 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
2517 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" 2590 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
2518 else 2591 else
2519 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2592 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
2520 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" 2593 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
2521 fi 2594 fi
2522 2595
2523 _python_test_hook post 2596 _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook post
2524 } 2597 }
2525 if _python_package_supporting_installation_for_multiple_python_abis; then 2598 if _python_package_supporting_installation_for_multiple_python_abis; then
2526 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2599 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2527 else 2600 else
2528 if [[ -n "${separate_build_dirs}" ]]; then 2601 if [[ -n "${separate_build_dirs}" ]]; then
2787 done 2860 done
2788 for dir in "${evaluated_dirs[@]}"; do 2861 for dir in "${evaluated_dirs[@]}"; do
2789 eval "dirs+=(\"\${root}${dir}\")" 2862 eval "dirs+=(\"\${root}${dir}\")"
2790 done 2863 done
2791 stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1" 2864 stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1"
2792 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2865 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2793 "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" 2866 "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2794 fi 2867 fi
2795 _python_clean_compiled_modules "${dirs[@]}" 2868 _python_clean_compiled_modules "${dirs[@]}"
2796 fi 2869 fi
2797 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then 2870 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
2800 done 2873 done
2801 for file in "${evaluated_files[@]}"; do 2874 for file in "${evaluated_files[@]}"; do
2802 eval "files+=(\"\${root}${file}\")" 2875 eval "files+=(\"\${root}${file}\")"
2803 done 2876 done
2804 stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1" 2877 stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1"
2805 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2878 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2806 "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1" 2879 "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1"
2807 fi 2880 fi
2808 _python_clean_compiled_modules "${files[@]}" 2881 _python_clean_compiled_modules "${files[@]}"
2809 fi 2882 fi
2810 eend "${return_code}" 2883 eend "${return_code}"
2831 return_code="0" 2904 return_code="0"
2832 stderr="" 2905 stderr=""
2833 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)" 2906 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)"
2834 if ((${#other_dirs[@]})); then 2907 if ((${#other_dirs[@]})); then
2835 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1" 2908 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1"
2836 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2909 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2837 "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2910 "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
2838 fi 2911 fi
2839 _python_clean_compiled_modules "${other_dirs[@]}" 2912 _python_clean_compiled_modules "${other_dirs[@]}"
2840 fi 2913 fi
2841 if ((${#other_files[@]})); then 2914 if ((${#other_files[@]})); then
2842 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1" 2915 stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1"
2843 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2916 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2844 "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &> /dev/null || return_code="1" 2917 "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &> /dev/null || return_code="1"
2845 fi 2918 fi
2846 _python_clean_compiled_modules "${other_files[@]}" 2919 _python_clean_compiled_modules "${other_files[@]}"
2847 fi 2920 fi
2848 eend "${return_code}" 2921 eend "${return_code}"

Legend:
Removed from v.1.128  
changed lines
  Added in v.1.139

  ViewVC Help
Powered by ViewVC 1.1.20