mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-40854: Allow overriding sys.platlibdir via PYTHONPLATLIBDIR env-var (GH-20605)
This commit is contained in:
parent
c6b292cdee
commit
8f023a2f66
11 changed files with 82 additions and 24 deletions
|
@ -24,6 +24,10 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef PLATLIBDIR
|
||||
# error "PLATLIBDIR macro must be defined"
|
||||
#endif
|
||||
|
||||
|
||||
/* --- Command line options --------------------------------------- */
|
||||
|
||||
|
@ -110,6 +114,7 @@ PYTHONPATH : '%lc'-separated list of directories prefixed to the\n\
|
|||
static const char usage_5[] =
|
||||
"PYTHONHOME : alternate <prefix> directory (or <prefix>%lc<exec_prefix>).\n"
|
||||
" The default module search path uses %s.\n"
|
||||
"PYTHONPLATLIBDIR : override sys.platlibdir.\n"
|
||||
"PYTHONCASEOK : ignore case in 'import' statements (Windows).\n"
|
||||
"PYTHONUTF8: if set to 1, enable the UTF-8 mode.\n"
|
||||
"PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n"
|
||||
|
@ -588,6 +593,7 @@ PyConfig_Clear(PyConfig *config)
|
|||
CLEAR(config->base_prefix);
|
||||
CLEAR(config->exec_prefix);
|
||||
CLEAR(config->base_exec_prefix);
|
||||
CLEAR(config->platlibdir);
|
||||
|
||||
CLEAR(config->filesystem_encoding);
|
||||
CLEAR(config->filesystem_errors);
|
||||
|
@ -824,6 +830,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
|
|||
COPY_WSTR_ATTR(base_prefix);
|
||||
COPY_WSTR_ATTR(exec_prefix);
|
||||
COPY_WSTR_ATTR(base_exec_prefix);
|
||||
COPY_WSTR_ATTR(platlibdir);
|
||||
|
||||
COPY_ATTR(site_import);
|
||||
COPY_ATTR(bytes_warning);
|
||||
|
@ -926,6 +933,7 @@ config_as_dict(const PyConfig *config)
|
|||
SET_ITEM_WSTR(base_prefix);
|
||||
SET_ITEM_WSTR(exec_prefix);
|
||||
SET_ITEM_WSTR(base_exec_prefix);
|
||||
SET_ITEM_WSTR(platlibdir);
|
||||
SET_ITEM_INT(site_import);
|
||||
SET_ITEM_INT(bytes_warning);
|
||||
SET_ITEM_INT(inspect);
|
||||
|
@ -1336,6 +1344,14 @@ config_read_env_vars(PyConfig *config)
|
|||
}
|
||||
}
|
||||
|
||||
if(config->platlibdir == NULL) {
|
||||
status = CONFIG_GET_ENV_DUP(config, &config->platlibdir,
|
||||
L"PYTHONPLATLIBDIR", "PYTHONPLATLIBDIR");
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
if (config->use_hash_seed < 0) {
|
||||
status = config_init_hash_seed(config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
|
@ -1731,6 +1747,14 @@ config_read(PyConfig *config)
|
|||
}
|
||||
}
|
||||
|
||||
if(config->platlibdir == NULL) {
|
||||
status = CONFIG_SET_BYTES_STR(config, &config->platlibdir, PLATLIBDIR,
|
||||
"PLATLIBDIR macro");
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
if (config->_install_importlib) {
|
||||
status = _PyConfig_InitPathConfig(config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
|
@ -2554,6 +2578,7 @@ PyConfig_Read(PyConfig *config)
|
|||
assert(config->exec_prefix != NULL);
|
||||
assert(config->base_exec_prefix != NULL);
|
||||
}
|
||||
assert(config->platlibdir != NULL);
|
||||
assert(config->filesystem_encoding != NULL);
|
||||
assert(config->filesystem_errors != NULL);
|
||||
assert(config->stdio_encoding != NULL);
|
||||
|
@ -2704,6 +2729,7 @@ _Py_DumpPathConfig(PyThreadState *tstate)
|
|||
DUMP_SYS(_base_executable);
|
||||
DUMP_SYS(base_prefix);
|
||||
DUMP_SYS(base_exec_prefix);
|
||||
DUMP_SYS(platlibdir);
|
||||
DUMP_SYS(executable);
|
||||
DUMP_SYS(prefix);
|
||||
DUMP_SYS(exec_prefix);
|
||||
|
|
|
@ -2922,13 +2922,7 @@ _PySys_InitMain(PyThreadState *tstate)
|
|||
SET_SYS_FROM_WSTR("base_prefix", config->base_prefix);
|
||||
SET_SYS_FROM_WSTR("exec_prefix", config->exec_prefix);
|
||||
SET_SYS_FROM_WSTR("base_exec_prefix", config->base_exec_prefix);
|
||||
{
|
||||
PyObject *str = PyUnicode_FromString(PLATLIBDIR);
|
||||
if (str == NULL) {
|
||||
return -1;
|
||||
}
|
||||
SET_SYS_FROM_STRING("platlibdir", str);
|
||||
}
|
||||
SET_SYS_FROM_WSTR("platlibdir", config->platlibdir);
|
||||
|
||||
if (config->pycache_prefix != NULL) {
|
||||
SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue