Skip to content

Commit eaa03ca

Browse files
committed
gh-98718: add sys.build_prefix
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent c0f2a5e commit eaa03ca

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

Include/cpython/initconfig.h

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ typedef struct PyConfig {
197197
wchar_t *base_prefix;
198198
wchar_t *exec_prefix;
199199
wchar_t *base_exec_prefix;
200+
wchar_t *build_prefix;
200201

201202
/* --- Parameter only used by Py_Main() ---------- */
202203
int skip_source_first_line;

Lib/sysconfig.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,9 @@ def is_python_build(check_home=None):
226226
import warnings
227227
warnings.warn("check_home argument is deprecated and ignored.",
228228
DeprecationWarning, stacklevel=2)
229-
for fn in ("Setup", "Setup.local"):
230-
if os.path.isfile(os.path.join(_PROJECT_BASE, "Modules", fn)):
231-
return True
232-
return False
229+
return bool(sys.build_prefix)
233230

234-
_PYTHON_BUILD = is_python_build()
231+
_PYTHON_BUILD = bool(sys.build_prefix)
235232

236233
if _PYTHON_BUILD:
237234
for scheme in ('posix_prefix', 'posix_home'):

Modules/getpath.py

+3
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@ def search_up(prefix, *landmarks, test=isfile):
509509
config['_is_python_build'] = 1
510510

511511

512+
config['build_prefix'] = build_prefix
513+
514+
512515
# ******************************************************************************
513516
# CALCULATE prefix AND exec_prefix
514517
# ******************************************************************************

Python/initconfig.c

+5
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ PyConfig_Clear(PyConfig *config)
731731
CLEAR(config->base_prefix);
732732
CLEAR(config->exec_prefix);
733733
CLEAR(config->base_exec_prefix);
734+
CLEAR(config->build_prefix);
734735
CLEAR(config->platlibdir);
735736

736737
CLEAR(config->filesystem_encoding);
@@ -985,6 +986,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
985986
COPY_WSTR_ATTR(base_prefix);
986987
COPY_WSTR_ATTR(exec_prefix);
987988
COPY_WSTR_ATTR(base_exec_prefix);
989+
COPY_WSTR_ATTR(build_prefix);
988990
COPY_WSTR_ATTR(platlibdir);
989991

990992
COPY_ATTR(site_import);
@@ -1094,6 +1096,7 @@ _PyConfig_AsDict(const PyConfig *config)
10941096
SET_ITEM_WSTR(base_prefix);
10951097
SET_ITEM_WSTR(exec_prefix);
10961098
SET_ITEM_WSTR(base_exec_prefix);
1099+
SET_ITEM_WSTR(build_prefix);
10971100
SET_ITEM_WSTR(platlibdir);
10981101
SET_ITEM_INT(site_import);
10991102
SET_ITEM_INT(bytes_warning);
@@ -1407,6 +1410,7 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
14071410
GET_WSTR_OPT(base_prefix);
14081411
GET_WSTR_OPT(exec_prefix);
14091412
GET_WSTR_OPT(base_exec_prefix);
1413+
GET_WSTR_OPT(build_prefix);
14101414

14111415
GET_UINT(skip_source_first_line);
14121416
GET_WSTR_OPT(run_command);
@@ -3172,6 +3176,7 @@ _Py_DumpPathConfig(PyThreadState *tstate)
31723176
DUMP_SYS(_base_executable);
31733177
DUMP_SYS(base_prefix);
31743178
DUMP_SYS(base_exec_prefix);
3179+
DUMP_SYS(build_prefix);
31753180
DUMP_SYS(platlibdir);
31763181
DUMP_SYS(executable);
31773182
DUMP_SYS(prefix);

Python/sysmodule.c

+4
Original file line numberDiff line numberDiff line change
@@ -3306,6 +3306,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
33063306
SET_SYS_FROM_WSTR(SYS_ATTR, WSTR); \
33073307
}
33083308

3309+
#define COPY_BOOL(KEY, VALUE) \
3310+
SET_SYS(KEY, PyBool_FromLong(VALUE));
3311+
33093312
if (config->module_search_paths_set) {
33103313
COPY_LIST("path", config->module_search_paths);
33113314
}
@@ -3317,6 +3320,7 @@ _PySys_UpdateConfig(PyThreadState *tstate)
33173320
COPY_WSTR("exec_prefix", config->exec_prefix);
33183321
COPY_WSTR("base_exec_prefix", config->base_exec_prefix);
33193322
COPY_WSTR("platlibdir", config->platlibdir);
3323+
COPY_WSTR("build_prefix", config->build_prefix);
33203324

33213325
if (config->pycache_prefix != NULL) {
33223326
SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix);

0 commit comments

Comments
 (0)