summaryrefslogtreecommitdiff
path: root/Lib/site.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-12-27 12:46:59 -0500
committerJason R. Coombs <jaraco@jaraco.com>2020-12-27 12:46:59 -0500
commita78f0158a28734f965218b834ea8c0b166b7353f (patch)
treedca70268e2a41d49658e7eed783c6fc243d119cd /Lib/site.py
parentec8e6895a3ce9cd69b6ceb75a15fcc74d4a522dc (diff)
parentbf64d9064ab641b1ef9a0c4bda097ebf1204faf4 (diff)
downloadcpython-git-revert-23107-revert-13893-fix-issue-37193.tar.gz
Merge branch 'master' into revert-23107-revert-13893-fix-issue-37193revert-23107-revert-13893-fix-issue-37193
Diffstat (limited to 'Lib/site.py')
-rw-r--r--Lib/site.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/Lib/site.py b/Lib/site.py
index 4d3b869fff..5f1b31e73d 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -105,8 +105,15 @@ def makepath(*paths):
def abs_paths():
"""Set all module __file__ and __cached__ attributes to an absolute path"""
for m in set(sys.modules.values()):
- if (getattr(getattr(m, '__loader__', None), '__module__', None) not in
- ('_frozen_importlib', '_frozen_importlib_external')):
+ loader_module = None
+ try:
+ loader_module = m.__loader__.__module__
+ except AttributeError:
+ try:
+ loader_module = m.__spec__.loader.__module__
+ except AttributeError:
+ pass
+ if loader_module not in {'_frozen_importlib', '_frozen_importlib_external'}:
continue # don't mess with a PEP 302-supplied __file__
try:
m.__file__ = os.path.abspath(m.__file__)
@@ -257,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))
@@ -304,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
@@ -623,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 = []