Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0824f63

Browse files
committed
When -O is given, use ".pyo" instead of ".pyc".
1 parent 80eb3c0 commit 0824f63

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Python/import.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ initimport()
8181
fatal("duplicate initimport() call");
8282
if ((import_modules = newdictobject()) == NULL)
8383
fatal("no mem for dictionary of modules");
84+
if (Py_OptimizeFlag) {
85+
/* Replace ".pyc" with ".pyo" in import_filetab */
86+
struct filedescr *p;
87+
for (p = import_filetab; p->suffix != NULL; p++) {
88+
if (strcmp(p->suffix, ".pyc") == 0)
89+
p->suffix = ".pyo";
90+
}
91+
}
8492
}
8593

8694

@@ -202,7 +210,7 @@ make_compiled_pathname(pathname, buf, buflen)
202210
if (len+2 > buflen)
203211
return NULL;
204212
strcpy(buf, pathname);
205-
strcpy(buf+len, "c");
213+
strcpy(buf+len, Py_OptimizeFlag ? "o" : "c");
206214

207215
return buf;
208216
}

0 commit comments

Comments
 (0)