Skip to content

Commit 2742509

Browse files
committed
Fix extension for compiled python files for start.c (.pyo/.pyc)
Because as of Python 3.5, the .pyo filename extension is no longer used See also: `PEP 488 -- Elimination of PYO files` (https://www.python.org/dev/peps/pep-0488/)
1 parent aea70b7 commit 2742509

File tree

1 file changed

+12
-3
lines changed
  • pythonforandroid/bootstraps/common/build/jni/application/src

1 file changed

+12
-3
lines changed

pythonforandroid/bootstraps/common/build/jni/application/src/start.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ int main(int argc, char *argv[]) {
263263
/* Get the entrypoint, search the .pyo then .py
264264
*/
265265
char *dot = strrchr(env_entrypoint, '.');
266+
#if PY_MAJOR_VERSION > 2
267+
char *ext = ".pyc";
268+
#else
269+
char *ext = ".pyo";
270+
#endif
266271
if (dot <= 0) {
267272
LOGP("Invalid entrypoint, abort.");
268273
return -1;
@@ -271,14 +276,14 @@ int main(int argc, char *argv[]) {
271276
LOGP("Entrypoint path is too long, try increasing ENTRYPOINT_MAXLEN.");
272277
return -1;
273278
}
274-
if (!strcmp(dot, ".pyo")) {
279+
if (!strcmp(dot, ext)) {
275280
if (!file_exists(env_entrypoint)) {
276281
/* fallback on .py */
277282
strcpy(entrypoint, env_entrypoint);
278283
entrypoint[strlen(env_entrypoint) - 1] = '\0';
279284
LOGP(entrypoint);
280285
if (!file_exists(entrypoint)) {
281-
LOGP("Entrypoint not found (.pyo, fallback on .py), abort");
286+
LOGP("Entrypoint not found (.pyc/.pyo, fallback on .py), abort");
282287
return -1;
283288
}
284289
} else {
@@ -288,7 +293,11 @@ int main(int argc, char *argv[]) {
288293
/* if .py is passed, check the pyo version first */
289294
strcpy(entrypoint, env_entrypoint);
290295
entrypoint[strlen(env_entrypoint) + 1] = '\0';
296+
#if PY_MAJOR_VERSION > 2
297+
entrypoint[strlen(env_entrypoint)] = 'c';
298+
#else
291299
entrypoint[strlen(env_entrypoint)] = 'o';
300+
#endif
292301
if (!file_exists(entrypoint)) {
293302
/* fallback on pure python version */
294303
if (!file_exists(env_entrypoint)) {
@@ -298,7 +307,7 @@ int main(int argc, char *argv[]) {
298307
strcpy(entrypoint, env_entrypoint);
299308
}
300309
} else {
301-
LOGP("Entrypoint have an invalid extension (must be .py or .pyo), abort.");
310+
LOGP("Entrypoint have an invalid extension (must be .py or .pyc/.pyo), abort.");
302311
return -1;
303312
}
304313
// LOGP("Entrypoint is:");

0 commit comments

Comments
 (0)