bpo-31904: Fix site and sysconfig modules for VxWorks RTOS (GH-21821)
diff --git a/Lib/site.py b/Lib/site.py
index 3a0f619..5f1b31e 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -264,6 +264,10 @@ def _getuserbase():
if env_base:
return env_base
+ # VxWorks has no home directories
+ if sys.platform == "vxworks":
+ return None
+
def joinuser(*args):
return os.path.expanduser(os.path.join(*args))
@@ -311,11 +315,14 @@ def getusersitepackages():
If the global variable ``USER_SITE`` is not initialized yet, this
function will also set it.
"""
- global USER_SITE
+ global USER_SITE, ENABLE_USER_SITE
userbase = getuserbase() # this will also set USER_BASE
if USER_SITE is None:
- USER_SITE = _get_path(userbase)
+ if userbase is None:
+ ENABLE_USER_SITE = False # disable user site and return None
+ else:
+ USER_SITE = _get_path(userbase)
return USER_SITE
@@ -630,11 +637,14 @@ def _script():
for dir in sys.path:
print(" %r," % (dir,))
print("]")
- print("USER_BASE: %r (%s)" % (user_base,
- "exists" if os.path.isdir(user_base) else "doesn't exist"))
- print("USER_SITE: %r (%s)" % (user_site,
- "exists" if os.path.isdir(user_site) else "doesn't exist"))
- print("ENABLE_USER_SITE: %r" % ENABLE_USER_SITE)
+ def exists(path):
+ if path is not None and os.path.isdir(path):
+ return "exists"
+ else:
+ return "doesn't exist"
+ print(f"USER_BASE: {user_base!r} ({exists(user_base)})")
+ print(f"USER_SITE: {user_site!r} ({exists(user_site)})")
+ print(f"ENABLE_USER_SITE: {ENABLE_USER_SITE!r}")
sys.exit(0)
buffer = []