Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_capi/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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]),
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions Modules/getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ******************************************************************************
Expand Down
3 changes: 3 additions & 0 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
Loading