Skip to content

Commit 8c0d3aa

Browse files
authored
Remove cwd while running using isolate script (#14014)
* Remove cwd while running using isolate script * Run inplace. * Fix formatting
1 parent 889375b commit 8c0d3aa

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

news/2 Fixes/13942.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix isolate script to only remove current working directory.

pythonFiles/pyvsc-run-isolated.py

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

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

11-
# We "isolate" the script/module (sys.argv[1]) by
12-
# replacing sys.path[0] with a dummy path and then sending the target
13-
# on to runpy.
14-
sys.path[0] = os.path.join(os.path.dirname(__file__), ".does-not-exist")
12+
13+
def normalize(path):
14+
return os.path.normcase(os.path.normpath(path))
15+
16+
17+
# We "isolate" the script/module (sys.argv[1]) by removing current working
18+
# directory or '' in sys.path and then sending the target on to runpy.
19+
cwd = normalize(os.getcwd())
20+
sys.path[:] = (p for p in sys.path if p != "" and normalize(p) != cwd)
1521
del sys.argv[0]
1622
module = sys.argv[0]
1723
if module == "-c":

0 commit comments

Comments
 (0)