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

Diff of /eclass/python.eclass

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

Revision 1.126 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.126 2011/07/08 07:48:38 djc 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# ================================================================================================
1231import os 1231import os
1232import re 1232import re
1233import subprocess 1233import subprocess
1234import sys 1234import sys
1235 1235
1236cpython_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+)$")
1237jython_re = re.compile(r"^jython(\d+\.\d+)$") 1240jython_interpreter_re = re.compile(r"^jython(\d+\.\d+)$")
1238pypy_re = re.compile(r"^pypy-c(\d+\.\d+)$") 1241pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$")
1239python_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)")
1240python_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$")
1241 1245
1242pypy_versions_mapping = { 1246pypy_versions_mapping = {
1243 "1.5": "2.7" 1247 "1.5": "2.7"
1244} 1248}
1245 1249
1246def get_PYTHON_ABI(EPYTHON): 1250def get_PYTHON_ABI(python_interpreter):
1247 cpython_matched = cpython_re.match(EPYTHON) 1251 cpython_matched = cpython_interpreter_re.match(python_interpreter)
1248 jython_matched = jython_re.match(EPYTHON) 1252 jython_matched = jython_interpreter_re.match(python_interpreter)
1249 pypy_matched = pypy_re.match(EPYTHON) 1253 pypy_matched = pypy_interpreter_re.match(python_interpreter)
1250 if cpython_matched is not None: 1254 if cpython_matched is not None:
1251 PYTHON_ABI = cpython_matched.group(1) 1255 PYTHON_ABI = cpython_matched.group(1)
1252 elif jython_matched is not None: 1256 elif jython_matched is not None:
1253 PYTHON_ABI = jython_matched.group(1) + "-jython" 1257 PYTHON_ABI = jython_matched.group(1) + "-jython"
1254 elif pypy_matched is not None: 1258 elif pypy_matched is not None:
1255 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)
1256 else: 1260 else:
1257 PYTHON_ABI = None 1261 PYTHON_ABI = None
1258 return PYTHON_ABI 1262 return PYTHON_ABI
1259 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
1260EOF 1278EOF
1261 if [[ "$?" != "0" ]]; then 1279 if [[ "$?" != "0" ]]; then
1262 die "${FUNCNAME}(): Generation of '$1' failed" 1280 die "${FUNCNAME}(): Generation of '$1' failed"
1263 fi 1281 fi
1264 if [[ "${respect_EPYTHON}" == "1" ]]; then 1282 if [[ "${respect_EPYTHON}" == "1" ]]; then
1265 cat << EOF >> "${file}" 1283 cat << EOF >> "${file}"
1266EPYTHON = os.environ.get("EPYTHON") 1284python_interpreter = os.environ.get("EPYTHON")
1267if EPYTHON: 1285if python_interpreter:
1268 PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1286 PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1269 if PYTHON_ABI is None: 1287 if PYTHON_ABI is None:
1270 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))
1271 sys.exit(1) 1289 sys.exit(1)
1272else: 1290else:
1273 try: 1291 try:
1274 environment = os.environ.copy() 1292 environment = os.environ.copy()
1275 environment["ROOT"] = "/" 1293 environment["ROOT"] = "/"
1278 raise ValueError 1296 raise ValueError
1279 except (OSError, ValueError): 1297 except (OSError, ValueError):
1280 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])
1281 sys.exit(1) 1299 sys.exit(1)
1282 1300
1283 EPYTHON = eselect_process.stdout.read() 1301 python_interpreter = eselect_process.stdout.read()
1284 if not isinstance(EPYTHON, str): 1302 if not isinstance(python_interpreter, str):
1285 # Python 3 1303 # Python 3
1286 EPYTHON = EPYTHON.decode() 1304 python_interpreter = python_interpreter.decode()
1287 EPYTHON = EPYTHON.rstrip("\n") 1305 python_interpreter = python_interpreter.rstrip("\n")
1288 1306
1289 PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1307 PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1290 if PYTHON_ABI is None: 1308 if PYTHON_ABI is None:
1291 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))
1292 sys.exit(1) 1310 sys.exit(1)
1293 1311
1294wrapper_script_path = os.path.realpath(sys.argv[0]) 1312wrapper_script_path = os.path.realpath(sys.argv[0])
1295target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1313target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1296if not os.path.exists(target_executable_path): 1314if not os.path.exists(target_executable_path):
1310 raise ValueError 1328 raise ValueError
1311except (OSError, ValueError): 1329except (OSError, ValueError):
1312 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])
1313 sys.exit(1) 1331 sys.exit(1)
1314 1332
1315EPYTHON = eselect_process.stdout.read() 1333python_interpreter = eselect_process.stdout.read()
1316if not isinstance(EPYTHON, str): 1334if not isinstance(python_interpreter, str):
1317 # Python 3 1335 # Python 3
1318 EPYTHON = EPYTHON.decode() 1336 python_interpreter = python_interpreter.decode()
1319EPYTHON = EPYTHON.rstrip("\n") 1337python_interpreter = python_interpreter.rstrip("\n")
1320 1338
1321PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1339PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1322if PYTHON_ABI is None: 1340if PYTHON_ABI is None:
1323 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))
1324 sys.exit(1) 1342 sys.exit(1)
1325 1343
1326wrapper_script_path = os.path.realpath(sys.argv[0]) 1344wrapper_script_path = os.path.realpath(sys.argv[0])
1327for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]: 1345for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
1328 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1346 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1329 if os.path.exists(target_executable_path): 1347 if os.path.exists(target_executable_path):
1330 break 1348 break
1331else: 1349else:
1332 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))
1333 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)
1334EOF 1357EOF
1335 if [[ "$?" != "0" ]]; then 1358 if [[ "$?" != "0" ]]; then
1336 die "${FUNCNAME}(): Generation of '$1' failed" 1359 die "${FUNCNAME}(): Generation of '$1' failed"
1337 fi 1360 fi
1338 fi 1361 fi
1339 cat << EOF >> "${file}" 1362 cat << EOF >> "${file}"
1340 1363
1341target_executable = open(target_executable_path, "rb") 1364target_executable = open(target_executable_path, "rb")
1342target_executable_first_line = target_executable.readline() 1365target_executable_first_line = target_executable.readline()
1366target_executable.close()
1343if not isinstance(target_executable_first_line, str): 1367if not isinstance(target_executable_first_line, str):
1344 # Python 3 1368 # Python 3
1345 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")
1346 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
1347python_shebang_matched = python_shebang_re.match(target_executable_first_line) 1376cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line)
1348target_executable.close()
1349 1377
1350if python_shebang_matched is not None: 1378if cpython_shebang_matched is not None:
1351 try: 1379 try:
1352 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON 1380 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % python_interpreter
1353 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" 1381 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1354 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)
1355 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1383 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1356 if python_verification_process.wait() != 0: 1384 if python_verification_process.wait() != 0:
1357 raise ValueError 1385 raise ValueError
1362 python_verification_output = python_verification_output.decode() 1390 python_verification_output = python_verification_output.decode()
1363 1391
1364 if not python_verification_output_re.match(python_verification_output): 1392 if not python_verification_output_re.match(python_verification_output):
1365 raise ValueError 1393 raise ValueError
1366 1394
1367 if cpython_re.match(EPYTHON) is not None: 1395 if cpython_interpreter_re.match(python_interpreter) is not None:
1368 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])
1369 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] 1397 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1370 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path 1398 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1371 1399
1372 if hasattr(os, "execv"): 1400 if hasattr(os, "execv"):
1373 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) 1401 os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv)
1374 else: 1402 else:
1375 sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait()) 1403 sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait())
1376 except (KeyboardInterrupt, SystemExit): 1404 except (KeyboardInterrupt, SystemExit):
1377 raise 1405 raise
1378 except: 1406 except:
1379 pass 1407 pass
1380 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"):
1422 fi 1450 fi
1423 1451
1424 _python_check_python_pkg_setup_execution 1452 _python_check_python_pkg_setup_execution
1425 _python_initialize_prefix_variables 1453 _python_initialize_prefix_variables
1426 1454
1427 local b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=() 1455 local absolute_file b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=()
1428 1456
1429 while (($#)); do 1457 while (($#)); do
1430 case "$1" in 1458 case "$1" in
1431 -q|--quiet) 1459 -q|--quiet)
1432 quiet="1" 1460 quiet="1"
1514 break 1542 break
1515 fi 1543 fi
1516 done 1544 done
1517 fi 1545 fi
1518 1546
1519 [[ "${version_executable}" == "0" || ! -x "${file}" ]] && continue 1547 [[ "${version_executable}" == "0" ]] && continue
1520 1548
1549 if [[ -L "${file}" ]]; then
1550 absolute_file="$(readlink "${file}")"
1551 if [[ "${absolute_file}" == /* ]]; then
1552 absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file##/}"
1553 else
1554 if [[ "${file}" == */* ]]; then
1555 absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file%/*}/${absolute_file}"
1556 else
1557 absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file}"
1558 fi
1559 fi
1560 else
1561 absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file}"
1562 fi
1563
1564 [[ ! -x "${absolute_file}" ]] && continue
1565
1521 shebang="$(head -n1 "${file}")" || die "Extraction of shebang from '${file}' failed" 1566 shebang="$(head -n1 "${absolute_file}")" || die "Extraction of shebang from '${absolute_file}' failed"
1522 1567
1523 if [[ "${version_executable}" == "2" ]]; then 1568 if [[ "${version_executable}" == "2" ]]; then
1524 wrapper_scripts+=("${ED}${file}") 1569 wrapper_scripts+=("${ED}${file}")
1525 elif [[ "${version_executable}" == "1" ]]; then 1570 elif [[ "${version_executable}" == "1" ]]; then
1526 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then 1571 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
1537 fi 1582 fi
1538 1583
1539 mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed" 1584 mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
1540 1585
1541 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then 1586 if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
1587 if [[ -L "${file}-${PYTHON_ABI}" ]]; then
1588 python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${absolute_file}"
1589 else
1542 python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}" 1590 python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}"
1591 fi
1543 fi 1592 fi
1544 done 1593 done
1545 1594
1546 popd > /dev/null || die "popd failed" 1595 popd > /dev/null || die "popd failed"
1547 1596
1548 if ROOT="/" has_version sys-apps/coreutils; then 1597 if ROOT="/" has_version sys-apps/coreutils; then
1549 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"
1550 else 1599 else
1551 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"
1552 fi 1601 fi
1553 done 1602 done
1554 1603
1572 stdout = sys.stdout.buffer 1621 stdout = sys.stdout.buffer
1573else: 1622else:
1574 # Python 2 1623 # Python 2
1575 stdout = sys.stdout 1624 stdout = sys.stdout
1576 1625
1626python_wrapper_scripts_file = open('${T}/python_wrapper_scripts', 'rb')
1577files = 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()
1578 1629
1579for file in sorted(files): 1630for file in sorted(files):
1580 stdout.write(file) 1631 stdout.write(file)
1581 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")
1582 1633
1647 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. 1698 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1648 PYTHON_REQUESTED_ACTIVE_VERSION="$1" 1699 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
1649} 1700}
1650 1701
1651# @FUNCTION: python_need_rebuild 1702# @FUNCTION: python_need_rebuild
1703# @DESCRIPTION:
1652# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1704# Mark current package for rebuilding by python-updater after
1653# switching of active version of Python. 1705# switching of active version of Python.
1654python_need_rebuild() { 1706python_need_rebuild() {
1655 if _python_package_supporting_installation_for_multiple_python_abis; then 1707 if _python_package_supporting_installation_for_multiple_python_abis; then
1656 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"
1657 fi 1709 fi
2356_python_test_hook() { 2408_python_test_hook() {
2357 if [[ "$#" -ne 1 ]]; then 2409 if [[ "$#" -ne 1 ]]; then
2358 die "${FUNCNAME}() requires 1 argument" 2410 die "${FUNCNAME}() requires 1 argument"
2359 fi 2411 fi
2360 2412
2361 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
2362 "${FUNCNAME[3]}_$1_hook" 2414 "${_PYTHON_TEST_FUNCTION}_$1_hook"
2363 fi 2415 fi
2364} 2416}
2365 2417
2366# @FUNCTION: python_execute_nosetests 2418# @FUNCTION: python_execute_nosetests
2367# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] 2419# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
2401 python_test_function() { 2453 python_test_function() {
2402 local evaluated_PYTHONPATH 2454 local evaluated_PYTHONPATH
2403 2455
2404 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2456 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2405 2457
2406 _python_test_hook pre 2458 _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook pre
2407 2459
2408 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2460 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2409 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2461 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
2410 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" 2462 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
2411 else 2463 else
2412 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} 2464 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
2413 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" 2465 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
2414 fi 2466 fi
2415 2467
2416 _python_test_hook post 2468 _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook post
2417 } 2469 }
2418 if _python_package_supporting_installation_for_multiple_python_abis; then 2470 if _python_package_supporting_installation_for_multiple_python_abis; then
2419 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2471 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2420 else 2472 else
2421 if [[ -n "${separate_build_dirs}" ]]; then 2473 if [[ -n "${separate_build_dirs}" ]]; then
2465 python_test_function() { 2517 python_test_function() {
2466 local evaluated_PYTHONPATH 2518 local evaluated_PYTHONPATH
2467 2519
2468 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2520 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2469 2521
2470 _python_test_hook pre 2522 _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook pre
2471 2523
2472 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2524 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2473 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}
2474 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 "$?"
2475 else 2527 else
2476 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}
2477 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?" 2529 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
2478 fi 2530 fi
2479 2531
2480 _python_test_hook post 2532 _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook post
2481 } 2533 }
2482 if _python_package_supporting_installation_for_multiple_python_abis; then 2534 if _python_package_supporting_installation_for_multiple_python_abis; then
2483 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2535 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2484 else 2536 else
2485 if [[ -n "${separate_build_dirs}" ]]; then 2537 if [[ -n "${separate_build_dirs}" ]]; then
2529 python_test_function() { 2581 python_test_function() {
2530 local evaluated_PYTHONPATH 2582 local evaluated_PYTHONPATH
2531 2583
2532 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" 2584 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2533 2585
2534 _python_test_hook pre 2586 _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook pre
2535 2587
2536 if [[ -n "${evaluated_PYTHONPATH}" ]]; then 2588 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2537 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}
2538 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 "$?"
2539 else 2591 else
2540 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} 2592 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
2541 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" 2593 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
2542 fi 2594 fi
2543 2595
2544 _python_test_hook post 2596 _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook post
2545 } 2597 }
2546 if _python_package_supporting_installation_for_multiple_python_abis; then 2598 if _python_package_supporting_installation_for_multiple_python_abis; then
2547 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" 2599 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2548 else 2600 else
2549 if [[ -n "${separate_build_dirs}" ]]; then 2601 if [[ -n "${separate_build_dirs}" ]]; then
2808 done 2860 done
2809 for dir in "${evaluated_dirs[@]}"; do 2861 for dir in "${evaluated_dirs[@]}"; do
2810 eval "dirs+=(\"\${root}${dir}\")" 2862 eval "dirs+=(\"\${root}${dir}\")"
2811 done 2863 done
2812 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"
2813 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2865 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2814 "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" 2866 "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
2815 fi 2867 fi
2816 _python_clean_compiled_modules "${dirs[@]}" 2868 _python_clean_compiled_modules "${dirs[@]}"
2817 fi 2869 fi
2818 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then 2870 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
2821 done 2873 done
2822 for file in "${evaluated_files[@]}"; do 2874 for file in "${evaluated_files[@]}"; do
2823 eval "files+=(\"\${root}${file}\")" 2875 eval "files+=(\"\${root}${file}\")"
2824 done 2876 done
2825 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"
2826 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2878 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2827 "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1" 2879 "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1"
2828 fi 2880 fi
2829 _python_clean_compiled_modules "${files[@]}" 2881 _python_clean_compiled_modules "${files[@]}"
2830 fi 2882 fi
2831 eend "${return_code}" 2883 eend "${return_code}"
2852 return_code="0" 2904 return_code="0"
2853 stderr="" 2905 stderr=""
2854 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)"
2855 if ((${#other_dirs[@]})); then 2907 if ((${#other_dirs[@]})); then
2856 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"
2857 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2909 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2858 "$(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"
2859 fi 2911 fi
2860 _python_clean_compiled_modules "${other_dirs[@]}" 2912 _python_clean_compiled_modules "${other_dirs[@]}"
2861 fi 2913 fi
2862 if ((${#other_files[@]})); then 2914 if ((${#other_files[@]})); then
2863 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"
2864 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then 2916 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
2865 "$(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"
2866 fi 2918 fi
2867 _python_clean_compiled_modules "${other_files[@]}" 2919 _python_clean_compiled_modules "${other_files[@]}"
2868 fi 2920 fi
2869 eend "${return_code}" 2921 eend "${return_code}"

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

  ViewVC Help
Powered by ViewVC 1.1.20