Fix synchronization of variables in wrapper scripts generated by python_generate_wrapper_scripts(). (Patch by Arfrever. Backported from Progress Overlay.) --- python.eclass +++ python.eclass @@ -1593,9 +1593,12 @@ import subprocess import sys -cpython_re = re.compile(r"^python(\d+\.\d+)$") -jython_re = re.compile(r"^jython(\d+\.\d+)$") -pypy_re = re.compile(r"^pypy-c(\d+\.\d+)$") +cpython_ABI_re = re.compile(r"^(\d+\.\d+)$") +jython_ABI_re = re.compile(r"^(\d+\.\d+)-jython$") +pypy_ABI_re = re.compile(r"^\d+\.\d+-pypy-(\d+\.\d+)$") +cpython_interpreter_re = re.compile(r"^python(\d+\.\d+)$") +jython_interpreter_re = re.compile(r"^jython(\d+\.\d+)$") +pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$") cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") @@ -1604,10 +1607,10 @@ "1.5": "2.7" } -def get_PYTHON_ABI(EPYTHON): - cpython_matched = cpython_re.match(EPYTHON) - jython_matched = jython_re.match(EPYTHON) - pypy_matched = pypy_re.match(EPYTHON) +def get_PYTHON_ABI(python_interpreter): + cpython_matched = cpython_interpreter_re.match(python_interpreter) + jython_matched = jython_interpreter_re.match(python_interpreter) + pypy_matched = pypy_interpreter_re.match(python_interpreter) if cpython_matched is not None: PYTHON_ABI = cpython_matched.group(1) elif jython_matched is not None: @@ -1618,17 +1621,31 @@ PYTHON_ABI = None return PYTHON_ABI +def get_python_interpreter(PYTHON_ABI): + cpython_matched = cpython_ABI_re.match(PYTHON_ABI) + jython_matched = jython_ABI_re.match(PYTHON_ABI) + pypy_matched = pypy_ABI_re.match(PYTHON_ABI) + if cpython_matched is not None: + python_interpreter = "python" + cpython_matched.group(1) + elif jython_matched is not None: + python_interpreter = "jython" + jython_matched.group(1) + elif pypy_matched is not None: + python_interpreter = "pypy-c" + pypy_matched.group(1) + else: + python_interpreter = None + return python_interpreter + EOF if [[ "$?" != "0" ]]; then die "${FUNCNAME}(): Generation of '$1' failed" fi if [[ "${respect_EPYTHON}" == "1" ]]; then cat << EOF >> "${file}" -EPYTHON = os.environ.get("EPYTHON") -if EPYTHON: - PYTHON_ABI = get_PYTHON_ABI(EPYTHON) +python_interpreter = os.environ.get("EPYTHON") +if python_interpreter: + PYTHON_ABI = get_PYTHON_ABI(python_interpreter) if PYTHON_ABI is None: - sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) + sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], python_interpreter)) sys.exit(1) else: try: @@ -1641,15 +1658,15 @@ sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0]) sys.exit(1) - EPYTHON = eselect_process.stdout.read() - if not isinstance(EPYTHON, str): + python_interpreter = eselect_process.stdout.read() + if not isinstance(python_interpreter, str): # Python 3 - EPYTHON = EPYTHON.decode() - EPYTHON = EPYTHON.rstrip("\n") + python_interpreter = python_interpreter.decode() + python_interpreter = python_interpreter.rstrip("\n") - PYTHON_ABI = get_PYTHON_ABI(EPYTHON) + PYTHON_ABI = get_PYTHON_ABI(python_interpreter) if PYTHON_ABI is None: - sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) + sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter)) sys.exit(1) wrapper_script_path = os.path.realpath(sys.argv[0]) @@ -1673,15 +1690,15 @@ sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0]) sys.exit(1) -EPYTHON = eselect_process.stdout.read() -if not isinstance(EPYTHON, str): +python_interpreter = eselect_process.stdout.read() +if not isinstance(python_interpreter, str): # Python 3 - EPYTHON = EPYTHON.decode() -EPYTHON = EPYTHON.rstrip("\n") + python_interpreter = python_interpreter.decode() +python_interpreter = python_interpreter.rstrip("\n") -PYTHON_ABI = get_PYTHON_ABI(EPYTHON) +PYTHON_ABI = get_PYTHON_ABI(python_interpreter) if PYTHON_ABI is None: - sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], EPYTHON)) + sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter)) sys.exit(1) wrapper_script_path = os.path.realpath(sys.argv[0]) @@ -1692,6 +1709,11 @@ else: sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path)) sys.exit(1) + +python_interpreter = get_python_interpreter(PYTHON_ABI) +if python_interpreter is None: + sys.stderr.write("%s: Unrecognized Python ABI '%s'\n" % (sys.argv[0], PYTHON_ABI)) + sys.exit(1) EOF if [[ "$?" != "0" ]]; then die "${FUNCNAME}(): Generation of '$1' failed" @@ -1715,7 +1737,7 @@ if cpython_shebang_matched is not None: try: - python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON + python_interpreter_path = "${EPREFIX}/usr/bin/%s" % python_interpreter os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] @@ -1730,7 +1752,7 @@ if not python_verification_output_re.match(python_verification_output): raise ValueError - if cpython_re.match(EPYTHON) is not None: + if cpython_interpreter_re.match(python_interpreter) is not None: os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0]) os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path