python / python/cpython

sysconfig variable impermanence in virtual environment when cross-compiling

Open
#150,162 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-sysconfig type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

The solution to issue GH-126789 (found in GH-127729 / 70154855cf69) introduced a side effect when sysconfig variables are fetched in a virtual environment with the _PYTHON_PROJECT_BASE environment variable present (on posix platforms). Specifically, every invocation of sysconfig.get_config_vars() and sysconfig.get_config_var() causes the variable cache to be reset and rebuilt from scratch. This can be confirmed by running Python as follows:

virtualenv -p /usr/bin/python3.14 env  # 3.14 or higher

_PYTHON_PROJECT_BASE=/any/path env/bin/python

And then executing:

import sysconfig
sysconfig.get_config_vars()['LIBDIR'] = '/some/new/path'
assert sysconfig.get_config_var('LIBDIR') != '/some/new/path'

Rebuilding the variable cache every time is fairly inefficient and prevents the possibility of tweaking the values (a sometimes necessary evil).

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-150164

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with sysconfig.get_config_vars() and sysconfig.get_config_var() using the provided virtual-environment reproduction and _PYTHON_PROJECT_BASE setting. Trace why the cache is rebuilt on each call, add regression coverage, and verify that modified values persist across subsequent lookups.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.