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

Diff of /eclass/python.eclass

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

Revision 1.132 Revision 1.133
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.133 2011/10/07 10:48:24 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
1234import sys 1234import sys
1235 1235
1236cpython_re = re.compile(r"^python(\d+\.\d+)$") 1236cpython_re = re.compile(r"^python(\d+\.\d+)$")
1237jython_re = re.compile(r"^jython(\d+\.\d+)$") 1237jython_re = re.compile(r"^jython(\d+\.\d+)$")
1238pypy_re = re.compile(r"^pypy-c(\d+\.\d+)$") 1238pypy_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)") 1239cpython_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)")
1240python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") 1241python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1241 1242
1242pypy_versions_mapping = { 1243pypy_versions_mapping = {
1243 "1.5": "2.7" 1244 "1.5": "2.7"
1244} 1245}
1338 fi 1339 fi
1339 cat << EOF >> "${file}" 1340 cat << EOF >> "${file}"
1340 1341
1341target_executable = open(target_executable_path, "rb") 1342target_executable = open(target_executable_path, "rb")
1342target_executable_first_line = target_executable.readline() 1343target_executable_first_line = target_executable.readline()
1344target_executable.close()
1343if not isinstance(target_executable_first_line, str): 1345if not isinstance(target_executable_first_line, str):
1344 # Python 3 1346 # Python 3
1345 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") 1347 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
1346 1348
1349options = []
1350python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line)
1351if python_shebang_options_matched is not None:
1352 options = [python_shebang_options_matched.group(1)]
1353
1347python_shebang_matched = python_shebang_re.match(target_executable_first_line) 1354cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line)
1348target_executable.close()
1349 1355
1350if python_shebang_matched is not None: 1356if cpython_shebang_matched is not None:
1351 try: 1357 try:
1352 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON 1358 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
1353 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" 1359 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1354 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) 1360 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
1355 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] 1361 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1368 os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0]) 1374 os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
1369 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] 1375 os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1370 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path 1376 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
1371 1377
1372 if hasattr(os, "execv"): 1378 if hasattr(os, "execv"):
1373 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) 1379 os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv)
1374 else: 1380 else:
1375 sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait()) 1381 sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait())
1376 except (KeyboardInterrupt, SystemExit): 1382 except (KeyboardInterrupt, SystemExit):
1377 raise 1383 raise
1378 except: 1384 except:
1379 pass 1385 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"): 1386 for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"):

Legend:
Removed from v.1.132  
changed lines
  Added in v.1.133

  ViewVC Help
Powered by ViewVC 1.1.20