-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcollect_module.py
35 lines (23 loc) · 1.07 KB
/
collect_module.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
import ast
from collections import OrderedDict
from PythonVoiceCodingPlugin.library import sorted_by_source_region,get_source_region,make_flat
from PythonVoiceCodingPlugin.library.info import *
from PythonVoiceCodingPlugin.library.traverse import search_upwards,search_upwards_log, find_matching,match_node, find_all_nodes,search_upwards_for_parent
from PythonVoiceCodingPlugin.queries.abstract import CollectionQuery
class CollectModule(CollectionQuery):
indexable = False
label = "Modules"
def handle_single(self,view_information,query_description,extra = {}):
build, origin, selection = self._preliminary(view_information,query_description,extra)
if not build:
return None,None
root,atok,m,r = build
definition_nodes = find_all_nodes(root,(ast.Import,ast.ImportFrom))
name_nodes = make_flat([get_module_names(x) for x in definition_nodes])
for name in name_nodes:
smaller = name.split(".")
if len( smaller)>1:
name_nodes.append(".".join(smaller[:-1]))
names = list(OrderedDict([(x,0) for x in name_nodes]).keys())
result = None
return names