Skip to content

Commit 74454ab

Browse files
committed
Revert "Simplify sys.abiflags in sysconfig and site"
This reverts commit 7884a62.
1 parent 21ae49d commit 74454ab

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Lib/site.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import _sitebuiltins
7676
import io
7777
import stat
78+
import warnings
7879

7980
# Prefixes for site-packages; add additional prefixes like /usr/local here
8081
PREFIXES = [sys.prefix, sys.exec_prefix]
@@ -318,6 +319,15 @@ def joinuser(*args):
318319
# Same to sysconfig.get_path('purelib', os.name+'_user')
319320
def _get_path(userbase):
320321
version = sys.version_info
322+
with warnings.catch_warnings():
323+
# ignore DeprecationWarning on sys.abiflags change on Windows
324+
warnings.simplefilter('ignore', DeprecationWarning)
325+
abiflags = getattr(sys, 'abiflags', '')
326+
if 't' in abiflags:
327+
abi_thread = 't'
328+
else:
329+
abi_thread = ''
330+
321331
implementation = _get_implementation()
322332
implementation_lower = implementation.lower()
323333
if os.name == 'nt':
@@ -327,7 +337,6 @@ def _get_path(userbase):
327337
if sys.platform == 'darwin' and sys._framework:
328338
return f'{userbase}/lib/{implementation_lower}/site-packages'
329339

330-
abi_thread = 't' if 't' in sys.abiflags else ''
331340
return f'{userbase}/lib/python{version[0]}.{version[1]}{abi_thread}/site-packages'
332341

333342

@@ -396,8 +405,15 @@ def getsitepackages(prefixes=None):
396405

397406
implementation = _get_implementation().lower()
398407
ver = sys.version_info
399-
if os.name != 'nt':
400-
abi_thread = 't' if 't' in sys.abiflags else ''
408+
with warnings.catch_warnings():
409+
# ignore DeprecationWarning on sys.abiflags change on Windows
410+
warnings.simplefilter('ignore', DeprecationWarning)
411+
abiflags = getattr(sys, 'abiflags', '')
412+
if 't' in abiflags:
413+
abi_thread = 't'
414+
else:
415+
abi_thread = ''
416+
if os.sep == '/':
401417
libdirs = [sys.platlibdir]
402418
if sys.platlibdir != "lib":
403419
libdirs.append("lib")

Lib/sysconfig/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def get_default_scheme():
325325

326326
def get_makefile_filename():
327327
"""Return the path of the Makefile."""
328+
import warnings
328329

329330
# GH-127429: When cross-compiling, use the Makefile from the target, instead of the host Python.
330331
if cross_base := os.environ.get('_PYTHON_PROJECT_BASE'):
@@ -333,7 +334,12 @@ def get_makefile_filename():
333334
if _PYTHON_BUILD:
334335
return os.path.join(_PROJECT_BASE, "Makefile")
335336

336-
if os.name == 'nt':
337+
with warnings.catch_warnings():
338+
# ignore DeprecationWarning on sys.abiflags change on Windows
339+
warnings.simplefilter('ignore', DeprecationWarning)
340+
has_abiflags = hasattr(sys, 'abiflags')
341+
342+
if has_abiflags:
337343
config_dir_name = f'config-{_PY_VERSION_SHORT}{sys.abiflags}'
338344
else:
339345
config_dir_name = 'config'

0 commit comments

Comments
 (0)