Respect options from shebangs of target scripts in wrapper scripts generated by python_generate_wrapper_scripts(). (Patch by Arfrever. Backported from Progress Overlay.) --- python.eclass +++ python.eclass @@ -1346,7 +1346,8 @@ 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+)$") -python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") +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$") pypy_versions_mapping = { @@ -1450,14 +1451,19 @@ target_executable = open(target_executable_path, "rb") target_executable_first_line = target_executable.readline() +target_executable.close() if not isinstance(target_executable_first_line, str): # Python 3 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") -python_shebang_matched = python_shebang_re.match(target_executable_first_line) -target_executable.close() +options = [] +python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line) +if python_shebang_options_matched is not None: + options = [python_shebang_options_matched.group(1)] + +cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line) -if python_shebang_matched is not None: +if cpython_shebang_matched is not None: try: python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" @@ -1480,9 +1486,9 @@ os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path if hasattr(os, "execv"): - os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) + os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv) else: - sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait()) + sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait()) except (KeyboardInterrupt, SystemExit): raise except: