|
Lines 1032-1055
Link Here
|
| 1032 |
import sys |
1032 |
import sys |
| 1033 |
|
1033 |
|
| 1034 |
EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") |
1034 |
EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") |
|
|
1035 |
PYTHON_V_re = re.compile(r" (\d+\.\d+)") |
| 1035 |
python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") |
1036 |
python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") |
| 1036 |
python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
1037 |
python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
| 1037 |
|
1038 |
|
|
|
1039 |
try: |
| 1040 |
virtual_env = os.environ['VIRTUAL_ENV'] |
| 1041 |
except KeyError: |
| 1042 |
virtual_env = None |
| 1043 |
|
| 1044 |
if virtual_env: |
| 1045 |
python_interpreter_path = os.path.join(virtual_env, 'bin', 'python') |
| 1046 |
try: |
| 1047 |
python_process = subprocess.Popen( |
| 1048 |
[python_interpreter_path, "--version"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 1049 |
if python_process.wait() != 0: |
| 1050 |
raise ValueError |
| 1051 |
except (OSError, ValueError): |
| 1052 |
sys.stderr.write("Execution of '%s --version' failed\n" % python_interpreter_path) |
| 1053 |
sys.exit(1) |
| 1054 |
|
| 1055 |
PYTHON_V = python_process.stdout.read() |
| 1056 |
if not isinstance(PYTHON_V, str): |
| 1057 |
# Python 3 |
| 1058 |
PYTHON_V = PYTHON_V.decode() |
| 1059 |
PYTHON_V = PYTHON_V.rstrip("\n") |
| 1060 |
|
| 1061 |
PYTHON_V_matched = PYTHON_V_re.search(PYTHON_V) |
| 1062 |
if PYTHON_V_matched: |
| 1063 |
PYTHON_ABI = PYTHON_V_matched.group(1) |
| 1064 |
else: |
| 1065 |
sys.stderr.write("'%s --version' printed unrecognized value '%s'\n" % (python_interpreter_path, PYTHON_V)) |
| 1066 |
sys.exit(1) |
| 1067 |
else: |
| 1038 |
EOF |
1068 |
EOF |
| 1039 |
if [[ "$?" != "0" ]]; then |
1069 |
if [[ "$?" != "0" ]]; then |
| 1040 |
die "${FUNCNAME}(): Generation of '$1' failed" |
1070 |
die "${FUNCNAME}(): Generation of '$1' failed" |
| 1041 |
fi |
1071 |
fi |
| 1042 |
if [[ "${respect_EPYTHON}" == "1" ]]; then |
1072 |
if [[ "${respect_EPYTHON}" == "1" ]]; then |
| 1043 |
cat << EOF >> "${file}" |
1073 |
cat << EOF >> "${file}" |
| 1044 |
EPYTHON = os.environ.get("EPYTHON") |
1074 |
EPYTHON = os.environ.get("EPYTHON") |
| 1045 |
if EPYTHON: |
1075 |
if EPYTHON: |
| 1046 |
EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
1076 |
EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
| 1047 |
if EPYTHON_matched: |
1077 |
if EPYTHON_matched: |
| 1048 |
PYTHON_ABI = EPYTHON_matched.group(1) |
1078 |
PYTHON_ABI = EPYTHON_matched.group(1) |
|
|
1079 |
else: |
| 1080 |
sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) |
| 1081 |
sys.exit(1) |
| 1049 |
else: |
1082 |
else: |
| 1050 |
sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) |
1083 |
try: |
| 1051 |
sys.exit(1) |
1084 |
eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) |
| 1052 |
else: |
1085 |
if eselect_process.wait() != 0: |
|
|
1086 |
raise ValueError |
| 1087 |
except (OSError, ValueError): |
| 1088 |
sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") |
| 1089 |
sys.exit(1) |
| 1090 |
|
| 1091 |
EPYTHON = eselect_process.stdout.read() |
| 1092 |
if not isinstance(EPYTHON, str): |
| 1093 |
# Python 3 |
| 1094 |
EPYTHON = EPYTHON.decode() |
| 1095 |
EPYTHON = EPYTHON.rstrip("\n") |
| 1096 |
|
| 1097 |
EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
| 1098 |
if EPYTHON_matched: |
| 1099 |
PYTHON_ABI = EPYTHON_matched.group(1) |
| 1100 |
else: |
| 1101 |
sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) |
| 1102 |
sys.exit(1) |
| 1103 |
EOF |
| 1104 |
if [[ "$?" != "0" ]]; then |
| 1105 |
die "${FUNCNAME}(): Generation of '$1' failed" |
| 1106 |
fi |
| 1107 |
else |
| 1108 |
cat << EOF >> "${file}" |
| 1053 |
try: |
1109 |
try: |
| 1054 |
eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) |
1110 |
eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) |
| 1055 |
if eselect_process.wait() != 0: |
1111 |
if eselect_process.wait() != 0: |
|
Lines 1074-1105
Link Here
|
| 1074 |
if [[ "$?" != "0" ]]; then |
1130 |
if [[ "$?" != "0" ]]; then |
| 1075 |
die "${FUNCNAME}(): Generation of '$1' failed" |
1131 |
die "${FUNCNAME}(): Generation of '$1' failed" |
| 1076 |
fi |
1132 |
fi |
| 1077 |
else |
|
|
| 1078 |
cat << EOF >> "${file}" |
| 1079 |
try: |
| 1080 |
eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) |
| 1081 |
if eselect_process.wait() != 0: |
| 1082 |
raise ValueError |
| 1083 |
except (OSError, ValueError): |
| 1084 |
sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") |
| 1085 |
sys.exit(1) |
| 1086 |
|
| 1087 |
EPYTHON = eselect_process.stdout.read() |
| 1088 |
if not isinstance(EPYTHON, str): |
| 1089 |
# Python 3 |
| 1090 |
EPYTHON = EPYTHON.decode() |
| 1091 |
EPYTHON = EPYTHON.rstrip("\n") |
| 1092 |
|
| 1093 |
EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
| 1094 |
if EPYTHON_matched: |
| 1095 |
PYTHON_ABI = EPYTHON_matched.group(1) |
| 1096 |
else: |
| 1097 |
sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) |
| 1098 |
sys.exit(1) |
| 1099 |
EOF |
| 1100 |
if [[ "$?" != "0" ]]; then |
| 1101 |
die "${FUNCNAME}(): Generation of '$1' failed" |
| 1102 |
fi |
| 1103 |
fi |
1133 |
fi |
| 1104 |
cat << EOF >> "${file}" |
1134 |
cat << EOF >> "${file}" |
| 1105 |
|
1135 |
|
|
Lines 1123-1129
Link Here
|
| 1123 |
|
1153 |
|
| 1124 |
if python_shebang_matched: |
1154 |
if python_shebang_matched: |
| 1125 |
try: |
1155 |
try: |
| 1126 |
python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON |
1156 |
if not virtual_env: |
|
|
1157 |
python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON |
| 1127 |
os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" |
1158 |
os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" |
| 1128 |
python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) |
1159 |
python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) |
| 1129 |
del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |
1160 |
del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |