Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions news/2 Fixes/13942.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix isolate script to only remove current working directory.
14 changes: 10 additions & 4 deletions pythonFiles/pyvsc-run-isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
if __name__ != "__main__":
raise Exception("{} cannot be imported".format(__name__))

import os
import os.path
import runpy
import sys

# We "isolate" the script/module (sys.argv[1]) by
# replacing sys.path[0] with a dummy path and then sending the target
# on to runpy.
sys.path[0] = os.path.join(os.path.dirname(__file__), ".does-not-exist")

def normalize(path):
return os.path.normcase(os.path.normpath(path))


# We "isolate" the script/module (sys.argv[1]) by removing current working
# directory or '' in sys.path and then sending the target on to runpy.
cwd = normalize(os.getcwd())
sys.path[:] = (p for p in sys.path if p != "" and normalize(p) != cwd)
del sys.argv[0]
module = sys.argv[0]
if module == "-c":
Expand Down