forked from spyder-ide/spyder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostimport.py
74 lines (63 loc) · 2.29 KB
/
postimport.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import importlib
import sys
from collections import defaultdict
from tools.aspect import _class_decorator, instrument, decorate_members
from inspect import *
sys.meta_path.insert(0,PostImportFinder())
#def decorate_members(mod):
# Decorate classes
#print(f'importing {mod}')
#for name, member in getmembers(mod, isclass):
# print(f'apply decorator for: {name},{member} ')
# if(member.__module__==mod.__name__):
# print(member.__module__)
# print(mod.__name__)
# setattr(mod, name, _class_decorator(member))
# print('class')
# if mod.__spec__.name =='mainwindow':
# print('skip')
# return
# for name, member in getmembers(mod,isfunction):
# if(member.__module__==mod.__spec__.name):
# mod.__dict__[name] = instrument(member)
# print('func')
#class PostImportFinder:
# def __init__(self):
# self._skip=set()
# def find_module(self, fullname, path = None):
# if fullname in self._skip:
# return None
# self._skip.add(fullname)
# return PostImportLoader(self)
#class PostImportLoader:
# def __init__(self, finder):
# self._finder = finder
# def load_module(self, fullname):
# importlib.import_module(fullname)
# module = sys.modules[fullname]
# if 'spyder' in fullname and 'manager' not in fullname:
# decorate_members(module)
# self._finder._skip.remove(fullname)
# return module
#def when_imported(names):
# def decorate(func):
# for fullname in names:
# print(f'Search for {fullname}')
# if fullname in sys.modules:
# print(f'importing {fullname}')
# func(sys.modules[fullname])
# else:
# _post_import_hooks[fullname].append(func)
# return func
# return decorate
#def on_import():
# def decorate(func):
# for fullname in sys.modules:
# print(f'Search for {fullname}')
# if f'spyder' in fullname and fullname not in sys.builtin_module_names:
# print(f'importing {fullname}')
# func(sys.modules[fullname])
# else:
# _post_import_hooks[fullname].append(func)
# return func
# return decorate