summaryrefslogtreecommitdiff
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2018-06-15 22:40:56 -0600
committerNick Coghlan <ncoghlan@gmail.com>2018-06-16 14:40:56 +1000
commitb193fa996a746111252156f11fb14c12fd6267e6 (patch)
tree1995957ce580ba762a19f64e41db2db32aec096a /Python/sysmodule.c
parent68680035143a3a6398faa88f067f244c74691d19 (diff)
downloadcpython-git-b193fa996a746111252156f11fb14c12fd6267e6.tar.gz
bpo-33499: Add PYTHONPYCACHEPREFIX env var for alt bytecode cache location. (GH-6834)
In some development setups it is inconvenient or impossible to write bytecode caches to the code tree, but the bytecode caches are still useful. The PYTHONPYCACHEPREFIX environment variable allows specifying an alternate location for cached bytecode files, within which a directory tree mirroring the code tree will be created. This cache tree is then used (for both reading and writing) instead of the local `__pycache__` subdirectory within each source directory. Exposed at runtime as sys.pycache_prefix (defaulting to None), and can be set from the CLI as "-X pycache_prefix=path". Patch by Carl Meyer.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 3fab81aa50..786f2b1a0a 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -2458,6 +2458,12 @@ _PySys_EndInit(PyObject *sysdict, _PyMainInterpreterConfig *config)
SET_SYS_FROM_STRING_BORROW("exec_prefix", config->exec_prefix);
SET_SYS_FROM_STRING_BORROW("base_exec_prefix", config->base_exec_prefix);
+ if (config->pycache_prefix != NULL) {
+ SET_SYS_FROM_STRING_BORROW("pycache_prefix", config->pycache_prefix);
+ } else {
+ PyDict_SetItemString(sysdict, "pycache_prefix", Py_None);
+ }
+
if (config->argv != NULL) {
SET_SYS_FROM_STRING_BORROW("argv", config->argv);
}