| 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.132 2011/09/10 13:48:46 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 | |
| 12 | inherit multilib |
12 | inherit multilib |
| 13 | |
13 | |
| 14 | if ! has "${EAPI:-0}" 0 1 2 3; then |
14 | if ! 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" |
| 16 | fi |
16 | fi |
| 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) |
19 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
| … | |
… | |
| 1231 | import os |
1231 | import os |
| 1232 | import re |
1232 | import re |
| 1233 | import subprocess |
1233 | import subprocess |
| 1234 | import sys |
1234 | import sys |
| 1235 | |
1235 | |
| 1236 | cpython_re = re.compile(r"^python(\d+\.\d+)$") |
1236 | cpython_ABI_re = re.compile(r"^(\d+\.\d+)$") |
|
|
1237 | jython_ABI_re = re.compile(r"^(\d+\.\d+)-jython$") |
|
|
1238 | pypy_ABI_re = re.compile(r"^\d+\.\d+-pypy-(\d+\.\d+)$") |
|
|
1239 | cpython_interpreter_re = re.compile(r"^python(\d+\.\d+)$") |
| 1237 | jython_re = re.compile(r"^jython(\d+\.\d+)$") |
1240 | jython_interpreter_re = re.compile(r"^jython(\d+\.\d+)$") |
| 1238 | pypy_re = re.compile(r"^pypy-c(\d+\.\d+)$") |
1241 | pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$") |
| 1239 | python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") |
1242 | cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") |
|
|
1243 | python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") |
| 1240 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
1244 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
| 1241 | |
1245 | |
| 1242 | pypy_versions_mapping = { |
1246 | pypy_versions_mapping = { |
| 1243 | "1.5": "2.7" |
1247 | "1.5": "2.7" |
| 1244 | } |
1248 | } |
| 1245 | |
1249 | |
| 1246 | def get_PYTHON_ABI(EPYTHON): |
1250 | def 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 | |
|
|
1264 | def 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 | |
| 1260 | EOF |
1278 | EOF |
| 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}" |
| 1266 | EPYTHON = os.environ.get("EPYTHON") |
1284 | python_interpreter = os.environ.get("EPYTHON") |
| 1267 | if EPYTHON: |
1285 | if 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) |
| 1272 | else: |
1290 | else: |
| 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 | |
| 1294 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
1312 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
| 1295 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
1313 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
| 1296 | if not os.path.exists(target_executable_path): |
1314 | if not os.path.exists(target_executable_path): |
| … | |
… | |
| 1310 | raise ValueError |
1328 | raise ValueError |
| 1311 | except (OSError, ValueError): |
1329 | except (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 | |
| 1315 | EPYTHON = eselect_process.stdout.read() |
1333 | python_interpreter = eselect_process.stdout.read() |
| 1316 | if not isinstance(EPYTHON, str): |
1334 | if not isinstance(python_interpreter, str): |
| 1317 | # Python 3 |
1335 | # Python 3 |
| 1318 | EPYTHON = EPYTHON.decode() |
1336 | python_interpreter = python_interpreter.decode() |
| 1319 | EPYTHON = EPYTHON.rstrip("\n") |
1337 | python_interpreter = python_interpreter.rstrip("\n") |
| 1320 | |
1338 | |
| 1321 | PYTHON_ABI = get_PYTHON_ABI(EPYTHON) |
1339 | PYTHON_ABI = get_PYTHON_ABI(python_interpreter) |
| 1322 | if PYTHON_ABI is None: |
1340 | if 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 | |
| 1326 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
1344 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
| 1327 | for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]: |
1345 | for 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 |
| 1331 | else: |
1349 | else: |
| 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 | |
|
|
1353 | python_interpreter = get_python_interpreter(PYTHON_ABI) |
|
|
1354 | if python_interpreter is None: |
|
|
1355 | sys.stderr.write("%s: Unrecognized Python ABI '%s'\n" % (sys.argv[0], PYTHON_ABI)) |
|
|
1356 | sys.exit(1) |
| 1334 | EOF |
1357 | EOF |
| 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 | |
| 1341 | target_executable = open(target_executable_path, "rb") |
1364 | target_executable = open(target_executable_path, "rb") |
| 1342 | target_executable_first_line = target_executable.readline() |
1365 | target_executable_first_line = target_executable.readline() |
|
|
1366 | target_executable.close() |
| 1343 | if not isinstance(target_executable_first_line, str): |
1367 | if 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 | |
|
|
1371 | options = [] |
|
|
1372 | python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line) |
|
|
1373 | if python_shebang_options_matched is not None: |
|
|
1374 | options = [python_shebang_options_matched.group(1)] |
|
|
1375 | |
| 1347 | python_shebang_matched = python_shebang_re.match(target_executable_first_line) |
1376 | cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line) |
| 1348 | target_executable.close() |
|
|
| 1349 | |
1377 | |
| 1350 | if python_shebang_matched is not None: |
1378 | if 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"): |
| … | |
… | |
| 1565 | done |
1593 | done |
| 1566 | |
1594 | |
| 1567 | popd > /dev/null || die "popd failed" |
1595 | popd > /dev/null || die "popd failed" |
| 1568 | |
1596 | |
| 1569 | if ROOT="/" has_version sys-apps/coreutils; then |
1597 | if ROOT="/" has_version sys-apps/coreutils; then |
| 1570 | 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" |
| 1571 | else |
1599 | else |
| 1572 | 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" |
| 1573 | fi |
1601 | fi |
| 1574 | done |
1602 | done |
| 1575 | |
1603 | |
| … | |
… | |
| 1593 | stdout = sys.stdout.buffer |
1621 | stdout = sys.stdout.buffer |
| 1594 | else: |
1622 | else: |
| 1595 | # Python 2 |
1623 | # Python 2 |
| 1596 | stdout = sys.stdout |
1624 | stdout = sys.stdout |
| 1597 | |
1625 | |
|
|
1626 | python_wrapper_scripts_file = open('${T}/python_wrapper_scripts', 'rb') |
| 1598 | files = set(open('${T}/python_wrapper_scripts', 'rb').read().rstrip(${b}'\x00').split(${b}'\x00')) |
1627 | files = set(python_wrapper_scripts_file.read().rstrip(${b}'\x00').split(${b}'\x00')) |
|
|
1628 | python_wrapper_scripts_file.close() |
| 1599 | |
1629 | |
| 1600 | for file in sorted(files): |
1630 | for file in sorted(files): |
| 1601 | stdout.write(file) |
1631 | stdout.write(file) |
| 1602 | 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") |
| 1603 | |
1633 | |
| … | |
… | |
| 2378 | _python_test_hook() { |
2408 | _python_test_hook() { |
| 2379 | if [[ "$#" -ne 1 ]]; then |
2409 | if [[ "$#" -ne 1 ]]; then |
| 2380 | die "${FUNCNAME}() requires 1 argument" |
2410 | die "${FUNCNAME}() requires 1 argument" |
| 2381 | fi |
2411 | fi |
| 2382 | |
2412 | |
| 2383 | 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 |
| 2384 | "${FUNCNAME[3]}_$1_hook" |
2414 | "${_PYTHON_TEST_FUNCTION}_$1_hook" |
| 2385 | fi |
2415 | fi |
| 2386 | } |
2416 | } |
| 2387 | |
2417 | |
| 2388 | # @FUNCTION: python_execute_nosetests |
2418 | # @FUNCTION: python_execute_nosetests |
| 2389 | # @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] |
2419 | # @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] |
| … | |
… | |
| 2423 | python_test_function() { |
2453 | python_test_function() { |
| 2424 | local evaluated_PYTHONPATH |
2454 | local evaluated_PYTHONPATH |
| 2425 | |
2455 | |
| 2426 | eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" |
2456 | eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" |
| 2427 | |
2457 | |
| 2428 | _python_test_hook pre |
2458 | _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook pre |
| 2429 | |
2459 | |
| 2430 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
2460 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
| 2431 | echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} |
2461 | echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} |
| 2432 | PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" |
2462 | PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" |
| 2433 | else |
2463 | else |
| 2434 | echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} |
2464 | echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} |
| 2435 | nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" |
2465 | nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" |
| 2436 | fi |
2466 | fi |
| 2437 | |
2467 | |
| 2438 | _python_test_hook post |
2468 | _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook post |
| 2439 | } |
2469 | } |
| 2440 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2470 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2441 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
2471 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
| 2442 | else |
2472 | else |
| 2443 | if [[ -n "${separate_build_dirs}" ]]; then |
2473 | if [[ -n "${separate_build_dirs}" ]]; then |
| … | |
… | |
| 2487 | python_test_function() { |
2517 | python_test_function() { |
| 2488 | local evaluated_PYTHONPATH |
2518 | local evaluated_PYTHONPATH |
| 2489 | |
2519 | |
| 2490 | eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" |
2520 | eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" |
| 2491 | |
2521 | |
| 2492 | _python_test_hook pre |
2522 | _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook pre |
| 2493 | |
2523 | |
| 2494 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
2524 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
| 2495 | 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} |
| 2496 | 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 "$?" |
| 2497 | else |
2527 | else |
| 2498 | 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} |
| 2499 | py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?" |
2529 | py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?" |
| 2500 | fi |
2530 | fi |
| 2501 | |
2531 | |
| 2502 | _python_test_hook post |
2532 | _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook post |
| 2503 | } |
2533 | } |
| 2504 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2534 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2505 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
2535 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
| 2506 | else |
2536 | else |
| 2507 | if [[ -n "${separate_build_dirs}" ]]; then |
2537 | if [[ -n "${separate_build_dirs}" ]]; then |
| … | |
… | |
| 2551 | python_test_function() { |
2581 | python_test_function() { |
| 2552 | local evaluated_PYTHONPATH |
2582 | local evaluated_PYTHONPATH |
| 2553 | |
2583 | |
| 2554 | eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" |
2584 | eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"" |
| 2555 | |
2585 | |
| 2556 | _python_test_hook pre |
2586 | _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook pre |
| 2557 | |
2587 | |
| 2558 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
2588 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
| 2559 | 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} |
| 2560 | 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 "$?" |
| 2561 | else |
2591 | else |
| 2562 | echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} |
2592 | echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} |
| 2563 | trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" |
2593 | trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" |
| 2564 | fi |
2594 | fi |
| 2565 | |
2595 | |
| 2566 | _python_test_hook post |
2596 | _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook post |
| 2567 | } |
2597 | } |
| 2568 | if _python_package_supporting_installation_for_multiple_python_abis; then |
2598 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 2569 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
2599 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
| 2570 | else |
2600 | else |
| 2571 | if [[ -n "${separate_build_dirs}" ]]; then |
2601 | if [[ -n "${separate_build_dirs}" ]]; then |
| … | |
… | |
| 2830 | done |
2860 | done |
| 2831 | for dir in "${evaluated_dirs[@]}"; do |
2861 | for dir in "${evaluated_dirs[@]}"; do |
| 2832 | eval "dirs+=(\"\${root}${dir}\")" |
2862 | eval "dirs+=(\"\${root}${dir}\")" |
| 2833 | done |
2863 | done |
| 2834 | 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" |
| 2835 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2865 | if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then |
| 2836 | "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" |
2866 | "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1" |
| 2837 | fi |
2867 | fi |
| 2838 | _python_clean_compiled_modules "${dirs[@]}" |
2868 | _python_clean_compiled_modules "${dirs[@]}" |
| 2839 | fi |
2869 | fi |
| 2840 | if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then |
2870 | if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then |
| … | |
… | |
| 2843 | done |
2873 | done |
| 2844 | for file in "${evaluated_files[@]}"; do |
2874 | for file in "${evaluated_files[@]}"; do |
| 2845 | eval "files+=(\"\${root}${file}\")" |
2875 | eval "files+=(\"\${root}${file}\")" |
| 2846 | done |
2876 | done |
| 2847 | 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" |
| 2848 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2878 | if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then |
| 2849 | "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1" |
2879 | "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1" |
| 2850 | fi |
2880 | fi |
| 2851 | _python_clean_compiled_modules "${files[@]}" |
2881 | _python_clean_compiled_modules "${files[@]}" |
| 2852 | fi |
2882 | fi |
| 2853 | eend "${return_code}" |
2883 | eend "${return_code}" |
| … | |
… | |
| 2874 | return_code="0" |
2904 | return_code="0" |
| 2875 | stderr="" |
2905 | stderr="" |
| 2876 | 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)" |
| 2877 | if ((${#other_dirs[@]})); then |
2907 | if ((${#other_dirs[@]})); then |
| 2878 | 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" |
| 2879 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2909 | if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then |
| 2880 | "$(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" |
| 2881 | fi |
2911 | fi |
| 2882 | _python_clean_compiled_modules "${other_dirs[@]}" |
2912 | _python_clean_compiled_modules "${other_dirs[@]}" |
| 2883 | fi |
2913 | fi |
| 2884 | if ((${#other_files[@]})); then |
2914 | if ((${#other_files[@]})); then |
| 2885 | 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" |
| 2886 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2916 | if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then |
| 2887 | "$(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" |
| 2888 | fi |
2918 | fi |
| 2889 | _python_clean_compiled_modules "${other_files[@]}" |
2919 | _python_clean_compiled_modules "${other_files[@]}" |
| 2890 | fi |
2920 | fi |
| 2891 | eend "${return_code}" |
2921 | eend "${return_code}" |