Skip to content

Commit 45be11d

Browse files
committed
Simplify sys.abiflags in site
1 parent 74454ab commit 45be11d

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

Lib/site.py

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

8079
# Prefixes for site-packages; add additional prefixes like /usr/local here
8180
PREFIXES = [sys.prefix, sys.exec_prefix]
@@ -319,15 +318,6 @@ def joinuser(*args):
319318
# Same to sysconfig.get_path('purelib', os.name+'_user')
320319
def _get_path(userbase):
321320
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-
331321
implementation = _get_implementation()
332322
implementation_lower = implementation.lower()
333323
if os.name == 'nt':
@@ -337,6 +327,7 @@ def _get_path(userbase):
337327
if sys.platform == 'darwin' and sys._framework:
338328
return f'{userbase}/lib/{implementation_lower}/site-packages'
339329

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

342333

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

406397
implementation = _get_implementation().lower()
407398
ver = sys.version_info
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 == '/':
399+
if os.name != 'nt':
400+
abi_thread = 't' if 't' in sys.abiflags else ''
417401
libdirs = [sys.platlibdir]
418402
if sys.platlibdir != "lib":
419403
libdirs.append("lib")

Lib/test/test_sys.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ def test_attributes(self):
719719
self.assertIn(sys.float_repr_style, ('short', 'legacy'))
720720
if not sys.platform.startswith('win'):
721721
self.assertIsInstance(sys.abiflags, str)
722+
723+
# test hasattr(sys, 'abiflags') == (os.name != 'nt)
724+
self.assertEqual(os.name, 'posix')
722725
else:
723726
absent = object()
724727
with self.assertWarnsRegex(
@@ -743,6 +746,9 @@ def test_attributes(self):
743746
):
744747
_ = sys.abiflags
745748

749+
# test hasattr(sys, 'abiflags') == (os.name != 'nt)
750+
self.assertEqual(os.name, 'nt')
751+
746752
def test_thread_info(self):
747753
info = sys.thread_info
748754
self.assertEqual(len(info), 3)

0 commit comments

Comments
 (0)