forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyvsc-run-isolated.py
More file actions
26 lines (23 loc) · 776 Bytes
/
pyvsc-run-isolated.py
File metadata and controls
26 lines (23 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
if __name__ != "__main__":
raise Exception("{} cannot be imported".format(__name__))
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")
del sys.argv[0]
module = sys.argv[0]
if module == "-c":
ns = {}
for code in sys.argv[1:]:
exec(code, ns, ns)
elif module.startswith("-"):
raise NotImplementedError(sys.argv)
elif module.endswith(".py"):
runpy.run_path(module, run_name="__main__")
else:
runpy.run_module(module, run_name="__main__", alter_sys=True)