Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2581bdb

Browse files
committed
Issue #16804: Fix 'python -S -m site' failure.
This commit fixes a bug in the 'site' module that was causing an exception to incorrectly be thrown when running 'python -S -m site'. The problem was that 'USER_BASE' and 'USER_SITE' were being accessed before they were properly initialized. The code has been changed to use 'getuserbase' and 'getusersitepackages' instead so that the initialization always happens.
2 parents d949126 + 9a7a811 commit 2581bdb

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

Lib/site.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,16 @@ def _script():
598598
"""
599599
args = sys.argv[1:]
600600
if not args:
601+
user_base = getuserbase()
602+
user_site = getusersitepackages()
601603
print("sys.path = [")
602604
for dir in sys.path:
603605
print(" %r," % (dir,))
604606
print("]")
605-
print("USER_BASE: %r (%s)" % (USER_BASE,
606-
"exists" if os.path.isdir(USER_BASE) else "doesn't exist"))
607-
print("USER_SITE: %r (%s)" % (USER_SITE,
608-
"exists" if os.path.isdir(USER_SITE) else "doesn't exist"))
607+
print("USER_BASE: %r (%s)" % (user_base,
608+
"exists" if os.path.isdir(user_base) else "doesn't exist"))
609+
print("USER_SITE: %r (%s)" % (user_site,
610+
"exists" if os.path.isdir(user_site) else "doesn't exist"))
609611
print("ENABLE_USER_SITE: %r" % ENABLE_USER_SITE)
610612
sys.exit(0)
611613

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ Core and Builtins
4646
Library
4747
-------
4848

49+
- Issue #16804: Fix a bug in the 'site' module that caused running
50+
'python -S -m site' to incorrectly throw an exception.
51+
4952
- Issue #15480: Remove the deprecated and unused TYPE_INT64 code from marshal.
5053
Initial patch by Daniel Riti.
5154

0 commit comments

Comments
 (0)