Visitar URL original
gh-91985: Ensure in-tree builds override platstdlib_dir in every path calculation by neonene · Pull Request #93641 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-91985: Ensure in-tree builds override platstdlib_dir in every path…
… calculation
  • Loading branch information
neonene committed Jun 9, 2022
commit 1ae7f8734c1c09ade809e4beb4fea5e8f153caae
3 changes: 2 additions & 1 deletion Modules/getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ def search_up(prefix, *landmarks, test=isfile):

build_prefix = None

if not home_was_set and real_executable_dir and not py_setpath:
if ((not home_was_set and real_executable_dir and not py_setpath)
or config.get('_is_python_build')):
# Detect a build marker and use it to infer prefix, exec_prefix,
# stdlib_dir and the platstdlib_dir directories.
try:
Expand Down
22 changes: 21 additions & 1 deletion Python/pathconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ typedef struct _PyPathConfig {
wchar_t *program_name;
/* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
wchar_t *home;
int _is_python_build;
} _PyPathConfig;

# define _PyPathConfig_INIT \
{.module_search_path = NULL}
{.module_search_path = NULL, ._is_python_build = 0}


_PyPathConfig _Py_path_config = _PyPathConfig_INIT;
Expand Down Expand Up @@ -72,6 +73,7 @@ _PyPathConfig_ClearGlobal(void)
CLEAR(calculated_module_search_path);
CLEAR(program_name);
CLEAR(home);
_Py_path_config._is_python_build = 0;

#undef CLEAR

Expand Down Expand Up @@ -99,15 +101,24 @@ _PyPathConfig_ReadGlobal(PyConfig *config)
} \
} while (0)

#define COPY_INT(ATTR) \
do { \
if ((_Py_path_config.ATTR > 0) && (config->ATTR <= 0)) { \
config->ATTR = _Py_path_config.ATTR; \
} \
} while (0)

COPY(prefix);
COPY(exec_prefix);
COPY(stdlib_dir);
COPY(program_name);
COPY(home);
COPY2(executable, program_full_path);
COPY_INT(_is_python_build);
// module_search_path must be initialised - not read
#undef COPY
#undef COPY2
#undef COPY_INT

done:
return status;
Expand Down Expand Up @@ -137,14 +148,23 @@ _PyPathConfig_UpdateGlobal(const PyConfig *config)
} \
} while (0)

#define COPY_INT(ATTR) \
do { \
if (config->ATTR > 0) { \
_Py_path_config.ATTR = config->ATTR; \
} \
} while (0)

COPY(prefix);
COPY(exec_prefix);
COPY(stdlib_dir);
COPY(program_name);
COPY(home);
COPY2(program_full_path, executable);
COPY_INT(_is_python_build);
#undef COPY
#undef COPY2
#undef COPY_INT

PyMem_RawFree(_Py_path_config.module_search_path);
_Py_path_config.module_search_path = NULL;
Expand Down