summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-01-07 17:09:35 (GMT)
committerGeorg Brandl <georg@python.org>2008-01-07 17:09:35 (GMT)
commit2da0fceba7dd70334aacbab0708a8cbdff92e31d (patch)
treef93838b60f3c3216db03eaa24b32f4dc92389230 /Python
parentb3255ed8c937510076b641db28ab052ddaee1178 (diff)
downloadcpython-2da0fceba7dd70334aacbab0708a8cbdff92e31d.zip
cpython-2da0fceba7dd70334aacbab0708a8cbdff92e31d.tar.gz
cpython-2da0fceba7dd70334aacbab0708a8cbdff92e31d.tar.bz2
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c7
-rw-r--r--Python/pythonrun.c3
-rw-r--r--Python/sysmodule.c3
3 files changed, 11 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c
index e191bd5..8094f7d 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -950,8 +950,11 @@ load_source_module(char *name, char *pathname, FILE *fp)
if (Py_VerboseFlag)
PySys_WriteStderr("import %s # from %s\n",
name, pathname);
- if (cpathname)
- write_compiled_module(co, cpathname, mtime);
+ if (cpathname) {
+ PyObject *ro = PySys_GetObject("dont_write_bytecode");
+ if (ro == NULL || !PyObject_IsTrue(ro))
+ write_compiled_module(co, cpathname, mtime);
+ }
}
m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);
Py_DECREF(co);
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index adae679..4939f54 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -72,6 +72,7 @@ int Py_VerboseFlag; /* Needed by import.c */
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */
int Py_NoSiteFlag; /* Suppress 'import site' */
+int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.py[co]) */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */
int Py_UnicodeFlag = 0; /* Needed by compile.c */
@@ -172,6 +173,8 @@ Py_InitializeEx(int install_sigs)
Py_VerboseFlag = add_flag(Py_VerboseFlag, p);
if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0')
Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p);
+ if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0')
+ Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p);
interp = PyInterpreterState_New();
if (interp == NULL)
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 2a6a8c3..bd551b5 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1128,6 +1128,9 @@ _PySys_Init(void)
v = Py_BuildValue("(ssz)", "CPython", branch, svn_revision);
PyDict_SetItemString(sysdict, "subversion", v);
Py_XDECREF(v);
+ PyDict_SetItemString(sysdict, "dont_write_bytecode",
+ v = PyBool_FromLong(Py_DontWriteBytecodeFlag));
+ Py_XDECREF(v);
/*
* These release level checks are mutually exclusive and cover
* the field, so don't get too fancy with the pre-processor!