Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Call abs_paths() only if removeduppaths() changed sys.path
  • Loading branch information
methane committed Feb 19, 2017
commit 3632140fa2d2c8dc89d3cc7cea2b3a75212f83fb
22 changes: 22 additions & 0 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ def makepath(*paths):
return dir, os.path.normcase(dir)


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')):
continue # don't mess with a PEP 302-supplied __file__
try:
m.__file__ = os.path.abspath(m.__file__)
except (AttributeError, OSError):
pass
try:
m.__cached__ = os.path.abspath(m.__cached__)
except (AttributeError, OSError):
pass


def removeduppaths():
""" Remove duplicate entries from sys.path along with making them
absolute"""
Expand Down Expand Up @@ -506,7 +522,13 @@ def main():
"""
global ENABLE_USER_SITE

orig_path = sys.path[:]
known_paths = removeduppaths()
if orig_path != sys.path:
# removeduppaths() might make sys.path absolute.
# fix __file__ and __cached__ of already imported modules too.
abs_paths()

known_paths = venv(known_paths)
if ENABLE_USER_SITE is None:
ENABLE_USER_SITE = check_enableusersite()
Expand Down