Ignore OSError in is_virtual_environment check

This works around a faulty virtual environment on my machine that makes
os.access throw "OSError: too many level of symlinks". If a virtual
environment is faulty, we can just ignore it.
This commit is contained in:
Tzu-ping Chung
2018-07-30 15:37:10 +08:00
parent ca7d5ac4de
commit 236a6c4522
+6 -2
View File
@@ -1350,8 +1350,12 @@ def is_virtual_environment(path):
if not path.is_dir():
return False
for bindir_name in ('bin', 'Scripts'):
for python_like in path.joinpath(bindir_name).glob('python*'):
if python_like.is_file() and os.access(str(python_like), os.X_OK):
for python in path.joinpath(bindir_name).glob('python*'):
try:
exeness = python.is_file() and os.access(str(python), os.X_OK)
except OSError:
exeness = False
if exeness:
return True
return False