Skip to content

Commit

Permalink
Revert "pythonGH-126789: fix some sysconfig data on late site initial…
Browse files Browse the repository at this point in the history
…izations"

This reverts commit acbd5c9.

Signed-off-by: Filipe Laíns <[email protected]>
  • Loading branch information
FFY00 committed Nov 19, 2024
1 parent 1380972 commit 9cc5c44
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 154 deletions.
18 changes: 4 additions & 14 deletions Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def joinuser(*args):
_PY_VERSION = sys.version.split()[0]
_PY_VERSION_SHORT = f'{sys.version_info[0]}.{sys.version_info[1]}'
_PY_VERSION_SHORT_NO_DOT = f'{sys.version_info[0]}{sys.version_info[1]}'
_PREFIX = os.path.normpath(sys.prefix)
_BASE_PREFIX = os.path.normpath(sys.base_prefix)
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
_BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
# Mutex guarding initialization of _CONFIG_VARS.
_CONFIG_VARS_LOCK = threading.RLock()
Expand Down Expand Up @@ -465,10 +467,8 @@ def _init_config_vars():
# Normalized versions of prefix and exec_prefix are handy to have;
# in fact, these are the standard versions used most places in the
# Distutils.
_PREFIX = os.path.normpath(sys.prefix)
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
_CONFIG_VARS['prefix'] = _PREFIX # FIXME: This gets overwriten by _init_posix.
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX # FIXME: This gets overwriten by _init_posix.
_CONFIG_VARS['prefix'] = _PREFIX
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX
_CONFIG_VARS['py_version'] = _PY_VERSION
_CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT
_CONFIG_VARS['py_version_nodot'] = _PY_VERSION_SHORT_NO_DOT
Expand Down Expand Up @@ -541,7 +541,6 @@ def get_config_vars(*args):
With arguments, return a list of values that result from looking up
each argument in the configuration variable dictionary.
"""
global _CONFIG_VARS_INITIALIZED

# Avoid claiming the lock once initialization is complete.
if not _CONFIG_VARS_INITIALIZED:
Expand All @@ -552,15 +551,6 @@ def get_config_vars(*args):
# don't re-enter init_config_vars().
if _CONFIG_VARS is None:
_init_config_vars()
else:
# If the site module initialization happened after _CONFIG_VARS was
# initialized, a virtual environment might have been activated, resulting in
# variables like sys.prefix changing their value, so we need to re-init the
# config vars (see GH-126789).
if _CONFIG_VARS['base'] != os.path.normpath(sys.prefix):
with _CONFIG_VARS_LOCK:
_CONFIG_VARS_INITIALIZED = False
_init_config_vars()

if args:
vals = []
Expand Down
70 changes: 0 additions & 70 deletions Lib/test/support/venv.py

This file was deleted.

67 changes: 1 addition & 66 deletions Lib/test/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def venv(self, **venv_create_args):
**venv_create_args,
)


def test_get_path_names(self):
self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)

Expand Down Expand Up @@ -591,71 +592,6 @@ def test_osx_ext_suffix(self):
suffix = sysconfig.get_config_var('EXT_SUFFIX')
self.assertTrue(suffix.endswith('-darwin.so'), suffix)

@requires_subprocess()
def test_config_vars_depend_on_site_initialization(self):
script = textwrap.dedent("""
import sysconfig
config_vars = sysconfig.get_config_vars()
import json
print(json.dumps(config_vars, indent=2))
""")

with self.venv() as venv:
site_config_vars = json.loads(venv.run('-c', script).stdout)
no_site_config_vars = json.loads(venv.run('-S', '-c', script).stdout)

self.assertNotEqual(site_config_vars, no_site_config_vars)
# With the site initialization, the virtual environment should be enabled.
self.assertEqual(site_config_vars['base'], venv.prefix)
self.assertEqual(site_config_vars['platbase'], venv.prefix)
#self.assertEqual(site_config_vars['prefix'], venv.prefix) # # FIXME: prefix gets overwriten by _init_posix
# Without the site initialization, the virtual environment should be disabled.
self.assertEqual(no_site_config_vars['base'], site_config_vars['installed_base'])
self.assertEqual(no_site_config_vars['platbase'], site_config_vars['installed_platbase'])

@requires_subprocess()
def test_config_vars_recalculation_after_site_initialization(self):
script = textwrap.dedent("""
import sysconfig
before = sysconfig.get_config_vars()
import site
site.main()
after = sysconfig.get_config_vars()
import json
print(json.dumps({'before': before, 'after': after}, indent=2))
""")

with self.venv() as venv:
config_vars = json.loads(venv.run('-S', '-c', script).stdout)

self.assertNotEqual(config_vars['before'], config_vars['after'])
self.assertEqual(config_vars['after']['base'], venv.prefix)
#self.assertEqual(config_vars['after']['prefix'], venv.prefix) # FIXME: prefix gets overwriten by _init_posix
#self.assertEqual(config_vars['after']['exec_prefix'], venv.prefix) # FIXME: exec_prefix gets overwriten by _init_posix

@requires_subprocess()
def test_paths_depend_on_site_initialization(self):
script = textwrap.dedent("""
import sysconfig
paths = sysconfig.get_paths()
import json
print(json.dumps(paths, indent=2))
""")

with self.venv() as venv:
site_paths = json.loads(venv.run('-c', script).stdout)
no_site_paths = json.loads(venv.run('-S', '-c', script).stdout)

self.assertNotEqual(site_paths, no_site_paths)

@requires_subprocess()
def test_makefile_overwrites_config_vars(self):
script = textwrap.dedent("""
Expand Down Expand Up @@ -689,7 +625,6 @@ def test_makefile_overwrites_config_vars(self):
self.assertNotEqual(data['prefix'], data['base_prefix'])
self.assertNotEqual(data['exec_prefix'], data['base_exec_prefix'])


class MakefileTests(unittest.TestCase):

@unittest.skipIf(sys.platform.startswith('win'),
Expand Down

This file was deleted.

0 comments on commit 9cc5c44

Please sign in to comment.