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

Skip to content

Commit 9a7a811

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.
1 parent 0bfd6ac commit 9a7a811

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
@@ -620,14 +620,16 @@ def _script():
620620
"""
621621
args = sys.argv[1:]
622622
if not args:
623+
user_base = getuserbase()
624+
user_site = getusersitepackages()
623625
print("sys.path = [")
624626
for dir in sys.path:
625627
print(" %r," % (dir,))
626628
print("]")
627-
print("USER_BASE: %r (%s)" % (USER_BASE,
628-
"exists" if os.path.isdir(USER_BASE) else "doesn't exist"))
629-
print("USER_SITE: %r (%s)" % (USER_SITE,
630-
"exists" if os.path.isdir(USER_SITE) else "doesn't exist"))
629+
print("USER_BASE: %r (%s)" % (user_base,
630+
"exists" if os.path.isdir(user_base) else "doesn't exist"))
631+
print("USER_SITE: %r (%s)" % (user_site,
632+
"exists" if os.path.isdir(user_site) else "doesn't exist"))
631633
print("ENABLE_USER_SITE: %r" % ENABLE_USER_SITE)
632634
sys.exit(0)
633635

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Core and Builtins
2929
Library
3030
-------
3131

32+
- Issue #16804: Fix a bug in the 'site' module that caused running
33+
'python -S -m site' to incorrectly throw an exception.
34+
3235
- Issue #17016: Get rid of possible pointer wraparounds and integer overflows
3336
in the re module. Patch by Nickolai Zeldovich.
3437

0 commit comments

Comments
 (0)