Skip to content

gh-98718: re-use already calculated is_python_build from getpath #98719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -197,6 +197,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.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,9 @@ def is_python_build(check_home=None):
import warnings
warnings.warn("check_home argument is deprecated and ignored.",
DeprecationWarning, stacklevel=2)
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
3 changes: 3 additions & 0 deletions Modules/getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,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
5 changes: 5 additions & 0 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,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->filesystem_encoding);
Expand Down Expand Up @@ -985,6 +986,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(build_prefix);
COPY_WSTR_ATTR(platlibdir);

COPY_ATTR(site_import);
Expand Down Expand Up @@ -1094,6 +1096,7 @@ _PyConfig_AsDict(const PyConfig *config)
SET_ITEM_WSTR(base_prefix);
SET_ITEM_WSTR(exec_prefix);
SET_ITEM_WSTR(base_exec_prefix);
SET_ITEM_WSTR(build_prefix);
SET_ITEM_WSTR(platlibdir);
SET_ITEM_INT(site_import);
SET_ITEM_INT(bytes_warning);
Expand Down Expand Up @@ -1407,6 +1410,7 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
GET_WSTR_OPT(base_prefix);
GET_WSTR_OPT(exec_prefix);
GET_WSTR_OPT(base_exec_prefix);
GET_WSTR_OPT(build_prefix);

GET_UINT(skip_source_first_line);
GET_WSTR_OPT(run_command);
Expand Down Expand Up @@ -3172,6 +3176,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 @@ -3306,6 +3306,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 @@ -3317,6 +3320,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