Skip to content

Commit c95971d

Browse files
author
Eric Snow
authored
In the isolation script use a dummy dir instead of deleting the path entry. (microsoft#13052)
(for microsoft#11875) We found that some tools (like pytest) rely on sys.path[0] and deleting it in the isolation script sometimes causes problems. The solution provided here is to replace sys.path[0] with a directory we know does not exist, rather than deleting it.
1 parent 1381c90 commit c95971d

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

news/2 Fixes/11875.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Some tools (like pytest) rely on the existence of `sys.path[0]`, so
2+
deleting it in the isolation script can sometimes cause problems. The
3+
solution is to point `sys.path[0]` to a bogus directory that we know
4+
does not exist (assuming noone modifies the extension install dir).

pythonFiles/pyvsc-run-isolated.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
if __name__ != "__main__":
55
raise Exception("{} cannot be imported".format(__name__))
66

7+
import os.path
78
import runpy
89
import sys
910

1011
# We "isolate" the script/module (sys.argv[1]) by
11-
# deleting sys.path[0] and then sending the target
12+
# replacing sys.path[0] with a dummy path and then sending the target
1213
# on to runpy.
13-
del sys.path[0]
14+
sys.path[0] = os.path.join(os.path.dirname(__file__), ".does-not-exist")
1415
del sys.argv[0]
1516
module = sys.argv[0]
1617
if module == "-c":

0 commit comments

Comments
 (0)