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

Diff of /eclass/python.eclass

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

Revision 1.134 Revision 1.135
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.134 2011/10/07 10:49:26 djc Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.135 2011/10/07 10:52:31 djc 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
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+)$")
1239cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") 1242cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)")
1240python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") 1243python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)")
1241python_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$")
1242 1245
1243pypy_versions_mapping = { 1246pypy_versions_mapping = {
1244 "1.5": "2.7" 1247 "1.5": "2.7"
1245} 1248}
1246 1249
1247def get_PYTHON_ABI(EPYTHON): 1250def get_PYTHON_ABI(python_interpreter):
1248 cpython_matched = cpython_re.match(EPYTHON) 1251 cpython_matched = cpython_interpreter_re.match(python_interpreter)
1249 jython_matched = jython_re.match(EPYTHON) 1252 jython_matched = jython_interpreter_re.match(python_interpreter)
1250 pypy_matched = pypy_re.match(EPYTHON) 1253 pypy_matched = pypy_interpreter_re.match(python_interpreter)
1251 if cpython_matched is not None: 1254 if cpython_matched is not None:
1252 PYTHON_ABI = cpython_matched.group(1) 1255 PYTHON_ABI = cpython_matched.group(1)
1253 elif jython_matched is not None: 1256 elif jython_matched is not None:
1254 PYTHON_ABI = jython_matched.group(1) + "-jython" 1257 PYTHON_ABI = jython_matched.group(1) + "-jython"
1255 elif pypy_matched is not None: 1258 elif pypy_matched is not None:
1256 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)
1257 else: 1260 else:
1258 PYTHON_ABI = None 1261 PYTHON_ABI = None
1259 return PYTHON_ABI 1262 return PYTHON_ABI
1260 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
1261EOF 1278EOF
1262 if [[ "$?" != "0" ]]; then 1279 if [[ "$?" != "0" ]]; then
1263 die "${FUNCNAME}(): Generation of '$1' failed" 1280 die "${FUNCNAME}(): Generation of '$1' failed"
1264 fi 1281 fi
1265 if [[ "${respect_EPYTHON}" == "1" ]]; then 1282 if [[ "${respect_EPYTHON}" == "1" ]]; then
1266 cat << EOF >> "${file}" 1283 cat << EOF >> "${file}"
1267EPYTHON = os.environ.get("EPYTHON") 1284python_interpreter = os.environ.get("EPYTHON")
1268if EPYTHON: 1285if python_interpreter:
1269 PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1286 PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1270 if PYTHON_ABI is None: 1287 if PYTHON_ABI is None:
1271 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))
1272 sys.exit(1) 1289 sys.exit(1)
1273else: 1290else:
1274 try: 1291 try:
1275 environment = os.environ.copy() 1292 environment = os.environ.copy()
1276 environment["ROOT"] = "/" 1293 environment["ROOT"] = "/"
1279 raise ValueError 1296 raise ValueError
1280 except (OSError, ValueError): 1297 except (OSError, ValueError):
1281 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])
1282 sys.exit(1) 1299 sys.exit(1)
1283 1300
1284 EPYTHON = eselect_process.stdout.read() 1301 python_interpreter = eselect_process.stdout.read()
1285 if not isinstance(EPYTHON, str): 1302 if not isinstance(python_interpreter, str):
1286 # Python 3 1303 # Python 3
1287 EPYTHON = EPYTHON.decode() 1304 python_interpreter = python_interpreter.decode()
1288 EPYTHON = EPYTHON.rstrip("\n") 1305 python_interpreter = python_interpreter.rstrip("\n")
1289 1306
1290 PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1307 PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1291 if PYTHON_ABI is None: 1308 if PYTHON_ABI is None:
1292 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))
1293 sys.exit(1) 1310 sys.exit(1)
1294 1311
1295wrapper_script_path = os.path.realpath(sys.argv[0]) 1312wrapper_script_path = os.path.realpath(sys.argv[0])
1296target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1313target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1297if not os.path.exists(target_executable_path): 1314if not os.path.exists(target_executable_path):
1311 raise ValueError 1328 raise ValueError
1312except (OSError, ValueError): 1329except (OSError, ValueError):
1313 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])
1314 sys.exit(1) 1331 sys.exit(1)
1315 1332
1316EPYTHON = eselect_process.stdout.read() 1333python_interpreter = eselect_process.stdout.read()
1317if not isinstance(EPYTHON, str): 1334if not isinstance(python_interpreter, str):
1318 # Python 3 1335 # Python 3
1319 EPYTHON = EPYTHON.decode() 1336 python_interpreter = python_interpreter.decode()
1320EPYTHON = EPYTHON.rstrip("\n") 1337python_interpreter = python_interpreter.rstrip("\n")
1321 1338
1322PYTHON_ABI = get_PYTHON_ABI(EPYTHON) 1339PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1323if PYTHON_ABI is None: 1340if PYTHON_ABI is None:
1324 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))
1325 sys.exit(1) 1342 sys.exit(1)
1326 1343
1327wrapper_script_path = os.path.realpath(sys.argv[0]) 1344wrapper_script_path = os.path.realpath(sys.argv[0])
1328for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]: 1345for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
1329 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) 1346 target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1330 if os.path.exists(target_executable_path): 1347 if os.path.exists(target_executable_path):
1331 break 1348 break
1332else: 1349else:
1333 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))
1334 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)
1335EOF 1357EOF
1336 if [[ "$?" != "0" ]]; then 1358 if [[ "$?" != "0" ]]; then
1337 die "${FUNCNAME}(): Generation of '$1' failed" 1359 die "${FUNCNAME}(): Generation of '$1' failed"
1338 fi 1360 fi
1339 fi 1361 fi
1353 1375
1354cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line) 1376cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line)
1355 1377
1356if cpython_shebang_matched is not None: 1378if cpython_shebang_matched is not None:
1357 try: 1379 try:
1358 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON 1380 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % python_interpreter
1359 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" 1381 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1360 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)
1361 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1383 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1362 if python_verification_process.wait() != 0: 1384 if python_verification_process.wait() != 0:
1363 raise ValueError 1385 raise ValueError
1368 python_verification_output = python_verification_output.decode() 1390 python_verification_output = python_verification_output.decode()
1369 1391
1370 if not python_verification_output_re.match(python_verification_output): 1392 if not python_verification_output_re.match(python_verification_output):
1371 raise ValueError 1393 raise ValueError
1372 1394
1373 if cpython_re.match(EPYTHON) is not None: 1395 if cpython_interpreter_re.match(python_interpreter) is not None:
1374 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])
1375 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] 1397 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1376 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path 1398 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1377 1399
1378 if hasattr(os, "execv"): 1400 if hasattr(os, "execv"):

Legend:
Removed from v.1.134  
changed lines
  Added in v.1.135

  ViewVC Help
Powered by ViewVC 1.1.20