def ignore_site_packages_paths():
"""
This function ...
:return:
"""
paths = sys.path[:]
# remove working directory so that all
# local imports fail
if os.getcwd() in sys.path:
sys.path.remove(os.getcwd())
# remove all third-party paths
# so that only stdlib imports will succeed
sys.path = list(set(filter(
None,
filter(lambda i: all(('site-packages' not in i,
'python' in i or 'pypy' in i)),
map(methodcaller('lower'), sys.path))
)))
yield
sys.path = paths
# -----------------------------------------------------------------
评论列表
文章目录