Skip to content

Commit

Permalink
Remove cwd while running using isolate script (#14014)
Browse files Browse the repository at this point in the history
* Remove cwd while running using isolate script

* Run inplace.

* Fix formatting
  • Loading branch information
karthiknadig authored Sep 22, 2020
1 parent 889375b commit 8c0d3aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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

0 comments on commit 8c0d3aa

Please sign in to comment.