-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsource-me.py
29 lines (23 loc) · 961 Bytes
/
source-me.py
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
27
28
29
def import_this_dir():
import importlib.machinery
import importlib.util
import pathlib
import sys
filepath = pathlib.Path(__file__).expanduser().resolve().with_name("__init__.py")
assert filepath.exists()
name = "tvm_gdb_extensions"
# Re-sourcing the file should reload the extensions, even if
# changes have been made. Therefore, remove python's cache.
to_remove = [mod_name for mod_name in sys.modules if mod_name.startswith(name)]
for mod_name in to_remove:
del sys.modules[mod_name]
loader = importlib.machinery.SourceFileLoader(name, str(filepath))
spec = importlib.util.spec_from_loader(name, loader)
mod = importlib.util.module_from_spec(spec)
sys.modules[name] = mod
spec.loader.exec_module(mod)
return mod
import_this_dir().main()
# Anything defined here remains in the namespace used by gdb.
# Therefore, cleanup to avoid polluting that namespace.
del import_this_dir