diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h index 846e05fb26a4d83..920ea3eb95da796 100644 --- a/Include/cpython/initconfig.h +++ b/Include/cpython/initconfig.h @@ -210,6 +210,7 @@ typedef struct PyConfig { wchar_t *base_prefix; wchar_t *exec_prefix; wchar_t *base_exec_prefix; + wchar_t *build_prefix; /* --- Parameter only used by Py_Main() ---------- */ int skip_source_first_line; diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py index 0657e458806e9b6..fd56edd060cc5fe 100644 --- a/Lib/sysconfig/__init__.py +++ b/Lib/sysconfig/__init__.py @@ -222,12 +222,9 @@ def _safe_realpath(path): _PROJECT_BASE = _safe_realpath(os.environ["_PYTHON_PROJECT_BASE"]) def is_python_build(): - for fn in ("Setup", "Setup.local"): - if os.path.isfile(os.path.join(_PROJECT_BASE, "Modules", fn)): - return True - return False + return bool(sys.build_prefix) -_PYTHON_BUILD = is_python_build() +_PYTHON_BUILD = bool(sys.build_prefix) if _PYTHON_BUILD: for scheme in ('posix_prefix', 'posix_home'): diff --git a/Lib/test/test_capi/test_config.py b/Lib/test/test_capi/test_config.py index 789f652b004bffb..da270780764c920 100644 --- a/Lib/test/test_capi/test_config.py +++ b/Lib/test/test_capi/test_config.py @@ -37,6 +37,7 @@ def test_config_get(self): ("base_executable", str | None, "_base_executable"), ("base_prefix", str | None, "base_prefix"), ("buffered_stdio", bool, None), + ("build_prefix", str | None, "build_prefix"), ("bytes_warning", int, None), ("check_hash_pycs_mode", str, None), ("code_debug_ranges", bool, None), @@ -254,6 +255,7 @@ def test_config_set_sys_attr(self): ('base_exec_prefix', 'base_exec_prefix', str | None), ('base_executable', '_base_executable', str | None), ('base_prefix', 'base_prefix', str | None), + ('build_prefix', 'build_prefix', str | None), ('exec_prefix', 'exec_prefix', str | None), ('executable', 'executable', str | None), ('module_search_paths', 'path', list[str]), diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 8ef2bcc3249b8b5..7ccfb11d5a925ec 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -799,6 +799,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'base_prefix': GET_DEFAULT_CONFIG, 'exec_prefix': GET_DEFAULT_CONFIG, 'base_exec_prefix': GET_DEFAULT_CONFIG, + 'build_prefix': IGNORE_CONFIG, 'module_search_paths': GET_DEFAULT_CONFIG, 'module_search_paths_set': True, 'platlibdir': sys.platlibdir, diff --git a/Modules/getpath.py b/Modules/getpath.py index 2ffb1d964c0fb63..92c15b11ca729c1 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -555,6 +555,9 @@ def search_up(prefix, *landmarks, test=isfile): config['_is_python_build'] = 1 +config['build_prefix'] = build_prefix + + # ****************************************************************************** # CALCULATE prefix AND exec_prefix # ****************************************************************************** diff --git a/Python/initconfig.c b/Python/initconfig.c index 225ee0a3fe5ff2a..ed357f8a654a4b5 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -114,6 +114,7 @@ static const PyConfigSpec PYCONFIG_SPEC[] = { SPEC(base_exec_prefix, WSTR_OPT, PUBLIC, SYS_ATTR("base_exec_prefix")), SPEC(base_executable, WSTR_OPT, PUBLIC, SYS_ATTR("_base_executable")), SPEC(base_prefix, WSTR_OPT, PUBLIC, SYS_ATTR("base_prefix")), + SPEC(build_prefix, WSTR_OPT, PUBLIC, SYS_ATTR("build_prefix")), SPEC(bytes_warning, UINT, PUBLIC, SYS_FLAG(9)), SPEC(cpu_count, INT, PUBLIC, NO_SYS), SPEC(lazy_imports, INT, PUBLIC, NO_SYS), @@ -1088,6 +1089,7 @@ PyConfig_Clear(PyConfig *config) CLEAR(config->base_prefix); CLEAR(config->exec_prefix); CLEAR(config->base_exec_prefix); + CLEAR(config->build_prefix); CLEAR(config->platlibdir); CLEAR(config->sys_path_0); @@ -3965,6 +3967,7 @@ _Py_DumpPathConfig(PyThreadState *tstate) DUMP_SYS(_base_executable); DUMP_SYS(base_prefix); DUMP_SYS(base_exec_prefix); + DUMP_SYS(build_prefix); DUMP_SYS(platlibdir); DUMP_SYS(executable); DUMP_SYS(prefix); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ce75027f67e9f4f..3bc596bf8adcf64 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -4191,6 +4191,9 @@ _PySys_UpdateConfig(PyThreadState *tstate) SET_SYS_FROM_WSTR(SYS_ATTR, WSTR); \ } +#define COPY_BOOL(KEY, VALUE) \ + SET_SYS(KEY, PyBool_FromLong(VALUE)); + if (config->module_search_paths_set) { COPY_LIST("path", config->module_search_paths); } @@ -4202,6 +4205,7 @@ _PySys_UpdateConfig(PyThreadState *tstate) COPY_WSTR("exec_prefix", config->exec_prefix); COPY_WSTR("base_exec_prefix", config->base_exec_prefix); COPY_WSTR("platlibdir", config->platlibdir); + COPY_WSTR("build_prefix", config->build_prefix); if (config->pycache_prefix != NULL) { SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix);