Skip to content

gh-127405: Add ABIFLAGS to sysconfig.get_config_vars() on Windows #131799

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

Merged
merged 58 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
31b7eab
Add `ABIFLAGS` to `sysconfig.get_config_vars()` on Windows
XuehaiPan Mar 27, 2025
dc45897
📜🤖 Added by blurb_it.
blurb-it[bot] Mar 27, 2025
9a4586a
Add tests
XuehaiPan Mar 27, 2025
76c85bb
Move `ABIFLAGS` definition to C code
XuehaiPan Mar 28, 2025
b98419b
Revert now unrelated changes
XuehaiPan Mar 28, 2025
4729f76
Fix variable name
XuehaiPan Mar 28, 2025
04cbb1c
Refactor string concatination
XuehaiPan Mar 28, 2025
a6045ea
Set `Py_DEBUG` flag in sysconfig
XuehaiPan Mar 28, 2025
584e0b0
Update comments from code review
XuehaiPan Mar 28, 2025
93257be
Prefer `Py_DEBUG` over `_DEBUG`
XuehaiPan Mar 28, 2025
30c7b56
Add tests
XuehaiPan Mar 28, 2025
97942b2
Add tests
XuehaiPan Mar 28, 2025
917874c
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Mar 28, 2025
f49067e
Update tests
XuehaiPan Mar 28, 2025
8fa952b
Update tests
XuehaiPan Mar 28, 2025
08d92db
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Mar 29, 2025
b667dd9
Remove unnecessary comments
XuehaiPan Mar 30, 2025
30cf6c7
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Mar 30, 2025
5df9540
Update What's New
XuehaiPan Mar 30, 2025
018aae3
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Mar 30, 2025
4f22ff3
Revert `PCbuild/pyproject.props`
XuehaiPan Mar 31, 2025
f918241
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Mar 31, 2025
a4646c5
Revert `_DEBUG` -> `Py_DEBUG`
XuehaiPan Mar 31, 2025
7b21d7d
Revert `_DEBUG` -> `Py_DEBUG`
XuehaiPan Mar 31, 2025
1ee8230
Add underscore prefix to `d` on Windows
XuehaiPan Mar 31, 2025
084deac
Fix key name
XuehaiPan Mar 31, 2025
af50632
Add comments for test for `d` flag in `ABIFLAGS`
XuehaiPan Mar 31, 2025
b397f40
Fix failing test
XuehaiPan Mar 31, 2025
1a82cd1
Update tests
XuehaiPan Mar 31, 2025
7990798
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Mar 31, 2025
0744690
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 3, 2025
518137b
Add a test for `sysconfig.get_config_var('ABIFLAGS')` on Windows
XuehaiPan Apr 3, 2025
486e2a8
Rename test function
XuehaiPan Apr 3, 2025
3bccf1d
Move test location
XuehaiPan Apr 3, 2025
780f340
Move test location
XuehaiPan Apr 3, 2025
98c26f9
Add a note for `test_abiflags`
XuehaiPan Apr 3, 2025
e236bc7
Move definition of ABIFLAGS from C to Python
XuehaiPan Apr 3, 2025
0d8bcdd
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 5, 2025
278556c
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 6, 2025
5689c1f
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 7, 2025
299cec6
Update tests
XuehaiPan Apr 7, 2025
21d2e73
Split 't' flag to another test
XuehaiPan Apr 7, 2025
d265a59
Update tests
XuehaiPan Apr 8, 2025
f3b8570
Update tests
XuehaiPan Apr 8, 2025
fe4ea95
Update tests
XuehaiPan Apr 8, 2025
da2b4ce
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 8, 2025
64f0961
Simplify tests
XuehaiPan Apr 8, 2025
8b16454
Simplify tests
XuehaiPan Apr 8, 2025
1c807f0
Update test comments
XuehaiPan Apr 8, 2025
fbb86f5
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 8, 2025
b702ff9
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 9, 2025
932386c
Simplify test comment
XuehaiPan Apr 9, 2025
23b6e6c
Apply suggestions from code review
XuehaiPan Apr 9, 2025
75b6c51
Make 'd' flag test more platform specific
XuehaiPan Apr 11, 2025
3c91201
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 11, 2025
d55b3e6
Revert non-Windows test changes
XuehaiPan Apr 11, 2025
a084070
Fix Windows platform detection
XuehaiPan Apr 11, 2025
d2255e6
Merge branch 'main' into windows-add-sysconfig-abiflags
XuehaiPan Apr 11, 2025
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
9 changes: 9 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1070,13 +1070,22 @@ sys.monitoring
* Two new events are added: :monitoring-event:`BRANCH_LEFT` and
:monitoring-event:`BRANCH_RIGHT`. The ``BRANCH`` event is deprecated.


sysconfig
---------

* Add ``ABIFLAGS`` key to :func:`sysconfig.get_config_vars` on Windows.
(Contributed by Xuehai Pan in :gh:`131799`.)


threading
---------

* :meth:`threading.Thread.start` now sets the operating system thread name
to :attr:`threading.Thread.name`.
(Contributed by Victor Stinner in :gh:`59705`.)


tkinter
-------

Expand Down
13 changes: 12 additions & 1 deletion Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,20 @@ def _init_non_posix(vars):
vars['BINLIBDEST'] = get_path('platstdlib')
vars['INCLUDEPY'] = get_path('include')

# Add EXT_SUFFIX, SOABI, and Py_GIL_DISABLED
# Add EXT_SUFFIX, SOABI, Py_DEBUG, and Py_GIL_DISABLED
vars.update(_sysconfig.config_vars())

# NOTE: ABIFLAGS is only an emulated value. It is not present during build
# on Windows. sys.abiflags is absent on Windows and vars['abiflags']
# is already widely used to calculate paths, so it should remain an
# empty string.
vars['ABIFLAGS'] = ''.join(
(
't' if vars['Py_GIL_DISABLED'] else '',
'_d' if vars['Py_DEBUG'] else '',
),
)

vars['LIBDIR'] = _safe_realpath(os.path.join(get_config_var('installed_base'), 'libs'))
if hasattr(sys, 'dllhandle'):
dllhandle = _winapi.GetModuleFileName(sys.dllhandle)
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ def test_attributes(self):
self.assertIn(sys.float_repr_style, ('short', 'legacy'))
if not sys.platform.startswith('win'):
self.assertIsInstance(sys.abiflags, str)
else:
self.assertFalse(hasattr(sys, 'abiflags'))

def test_thread_info(self):
info = sys.thread_info
Expand Down
67 changes: 61 additions & 6 deletions Lib/test/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import textwrap
from copy import copy

from test import support
from test.support import (
captured_stdout,
is_android,
Expand Down Expand Up @@ -455,20 +456,19 @@ def test_library(self):
library = sysconfig.get_config_var('LIBRARY')
ldlibrary = sysconfig.get_config_var('LDLIBRARY')
major, minor = sys.version_info[:2]
if sys.platform == 'win32':
self.assertTrue(library.startswith(f'python{major}{minor}'))
self.assertTrue(library.endswith('.dll'))
abiflags = sysconfig.get_config_var('ABIFLAGS')
if sys.platform.startswith('win'):
self.assertEqual(library, f'python{major}{minor}{abiflags}.dll')
self.assertEqual(library, ldlibrary)
elif is_apple_mobile:
framework = sysconfig.get_config_var('PYTHONFRAMEWORK')
self.assertEqual(ldlibrary, f"{framework}.framework/{framework}")
else:
self.assertTrue(library.startswith(f'libpython{major}.{minor}'))
self.assertTrue(library.endswith('.a'))
self.assertEqual(library, f'libpython{major}.{minor}{abiflags}.a')
if sys.platform == 'darwin' and sys._framework:
self.skipTest('gh-110824: skip LDLIBRARY test for framework build')
else:
self.assertTrue(ldlibrary.startswith(f'libpython{major}.{minor}'))
self.assertStartsWith(ldlibrary, f'libpython{major}.{minor}{abiflags}')

@unittest.skipUnless(sys.platform == "darwin", "test only relevant on MacOSX")
@requires_subprocess()
Expand Down Expand Up @@ -592,6 +592,61 @@ def test_osx_ext_suffix(self):
suffix = sysconfig.get_config_var('EXT_SUFFIX')
self.assertTrue(suffix.endswith('-darwin.so'), suffix)

def test_always_set_py_debug(self):
self.assertIn('Py_DEBUG', sysconfig.get_config_vars())
Py_DEBUG = sysconfig.get_config_var('Py_DEBUG')
self.assertIn(Py_DEBUG, (0, 1))
self.assertEqual(Py_DEBUG, support.Py_DEBUG)

def test_always_set_py_gil_disabled(self):
self.assertIn('Py_GIL_DISABLED', sysconfig.get_config_vars())
Py_GIL_DISABLED = sysconfig.get_config_var('Py_GIL_DISABLED')
self.assertIn(Py_GIL_DISABLED, (0, 1))
self.assertEqual(Py_GIL_DISABLED, support.Py_GIL_DISABLED)

def test_abiflags(self):
# If this test fails on some platforms, maintainers should update the
# test to make it pass, rather than changing the definition of ABIFLAGS.
self.assertIn('ABIFLAGS', sysconfig.get_config_vars())
self.assertIn('abiflags', sysconfig.get_config_vars())
abiflags = sysconfig.get_config_var('abiflags')
ABIFLAGS = sysconfig.get_config_var('ABIFLAGS')
self.assertIsInstance(abiflags, str)
self.assertIsInstance(ABIFLAGS, str)
self.assertIn(abiflags, ABIFLAGS)

valid_abiflags = ('', 't', 'd', 'td')
if os.name == 'nt':
self.assertEqual(abiflags, '')
# '_' can only exist if 'd' is present and can only followed by 'd'
self.assertIn(
ABIFLAGS,
tuple(flags.replace('d', '_d') for flags in valid_abiflags),
)
else:
self.assertIn(ABIFLAGS, valid_abiflags)

def test_abi_debug(self):
ABIFLAGS = sysconfig.get_config_var('ABIFLAGS')
if support.Py_DEBUG:
# The 'd' flag should always be the last one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is guaranteed. Yes, we require it for Windows, but it may not be so for all platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition has been held since Python 3.8 to today (3.14dev).

Copy link
Member

@zooba zooba Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't know if it's guaranteed.

Show me the definition of ABIFLAGS that specifies it (trick question - no such definition exists).

Let's not invent a specification in a barely-related PR. Make this a Windows-specific test that checks for _d at the end (or just check 'd' in ABIFLAGS), but don't touch other platforms.

# On Windows, the debug flag is used differently with a underscore prefix.
# For example, `python{X}.{Y}td` on Unix and `python{X}.{Y}t_d.exe` on Windows.
self.assertEndsWith(ABIFLAGS, 'd')
else:
self.assertNotIn('d', ABIFLAGS)

def test_abi_thread(self):
abi_thread = sysconfig.get_config_var('abi_thread')
ABIFLAGS = sysconfig.get_config_var('ABIFLAGS')
self.assertIsInstance(abi_thread, str)
if support.Py_GIL_DISABLED:
self.assertEqual(abi_thread, 't')
self.assertIn('t', ABIFLAGS)
else:
self.assertEqual(abi_thread, '')
self.assertNotIn('t', ABIFLAGS)

@requires_subprocess()
def test_makefile_overwrites_config_vars(self):
script = textwrap.dedent("""
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,7 @@ Todd R. Palmer
Juan David Ibáñez Palomar
Nicola Palumbo
Jan Palus
Xuehai Pan
Yongzhi Pan
Martin Panter
Mathias Panzenböck
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``ABIFLAGS`` to :func:`sysconfig.get_config_vars` on Windows. Patch by Xuehai Pan.
10 changes: 10 additions & 0 deletions Modules/_sysconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ _sysconfig_config_vars_impl(PyObject *module)
return NULL;
}

#ifdef Py_DEBUG
PyObject *py_debug = _PyLong_GetOne();
#else
PyObject *py_debug = _PyLong_GetZero();
#endif
if (PyDict_SetItemString(config, "Py_DEBUG", py_debug) < 0) {
Py_DECREF(config);
return NULL;
}

return config;
}

Expand Down
Loading