Skip to content

sysconfig.get_config_vars() values always get overwritten with the values from Makefile #126920

Closed
@FFY00

Description

@FFY00

Bug report

Bug description:

When fixing GH-126789, I noticed the exec and exec_prefix keys from sysconfig.get_config_vars() always get set to the value from Makefile, instead of following sys.prefix and sys.exec_prefix.

This happens because, after we set the values from sys.prefix and sys.exec_prefix in sysconfig._init_config_vars(), sysconfig._init_posix() updates the dictionary with the values from the Makefile, overwriting any values we set previously,

_CONFIG_VARS['prefix'] = _PREFIX # FIXME: This gets overwriten by _init_posix.
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX # FIXME: This gets overwriten by _init_posix.

vars.update(build_time_vars)

From my testing, exec and exec_prefix seem to be only the only keys currently affected, and fortunately they aren't used to calculate any of the sysconfig.get_paths() paths, which is probably why we didn't notice earlier.
I should also note that since the sys values only differ from the ones in the Makefile on virtual environments, this bug only happens inside virtual environments.

That said, the current code makes things super fragile. Just creating a variable name base in the Makefile, for eg., would majorly break sysconfig.get_paths() in virtual environments.

The fix is pretty simple, the values from the Makefile should not overwrite any of the values we previously set.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions