Skip to content

Commit 6eff3b2

Browse files
Make it easier to test different methods
1 parent 47ea5ee commit 6eff3b2

2 files changed

Lines changed: 52 additions & 97 deletions

File tree

bpython/importcompletion.py

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,14 @@ def complete(cursor_offset, line):
136136
def find_modules(path):
137137
"""Find all modules (and packages) for a given directory."""
138138

139-
#global nameSubname
140-
#nameSubname = []
139+
global nameSubname
140+
nameSubname = []
141+
142+
#Decides if you are using the first method: usng name subname (1),
143+
# the second method: using pathname (2) or the original (3)
144+
global useNameSubname
145+
useNameSubname = 3
146+
#print("useNameSubname:", useNameSubname)
141147

142148
if not os.path.isdir(path):
143149
# Perhaps a zip file
@@ -195,40 +201,51 @@ def find_modules(path):
195201
continue
196202
else:
197203
if is_package:
198-
pathGood = True
199-
200-
pathList = re.split("[/]", pathname)
201-
#print("pathL length:", len(pathList))
202-
#for pathL in pathList:
203-
#print("pathL:", pathL)
204-
205-
for folder in range(len(pathList) - 2):
206-
if pathList[folder] == pathList[len(pathList) - 1]:
207-
pathGood = False
208-
#print(pathGood)
209-
#print()
210-
if pathGood:
211-
#pathNameList.append(pathname)
212-
#print("PathGood len", len(pathNameList), pathname)
204+
pathGood = False
205+
if useNameSubname == 2:
206+
pathGood = True
207+
208+
pathList = re.split("[/]", pathname)
209+
#print("pathL length:", len(pathList))
210+
#for pathL in pathList:
211+
#print("pathL:", pathL)
212+
213+
#I did path len - 2 because I am worried about folders like bpython/bpython
214+
# but if it is a symbolic link it will stop at bpython/bpython/bpython
215+
for folder in range(len(pathList) - 2):
216+
if pathList[folder] == pathList[len(pathList) - 1]:
217+
pathGood = False
218+
#print(pathGood)
219+
#print()
220+
if useNameSubname == 1 or pathGood:
221+
for subname in find_modules(pathname):
222+
if subname != "__init__":
223+
#If trying the first method using name and subname
224+
if useNameSubname == 1:
225+
doNotAppend = False
226+
#print("name: ", name, " subname: ", subname)
227+
for obj in nameSubname:
228+
nam = obj[0]
229+
subnam = obj[1]
230+
#print("name: ", name, " nam: ", nam, " subname: ", subname, " subnam: ", subnam)
231+
if (name == nam and subname == subnam) or \
232+
any(name in sub for sub in re.split("[.]", subnam)):
233+
#print("Excluded: ", name, subname, "because ", nam, subnam)
234+
doNotAppend = True
235+
break
236+
#print()
237+
if not doNotAppend:
238+
nameSubname.append((name, subname))
239+
#print(name, subname)
240+
yield "%s.%s" % (name, subname)
241+
#If trying seconf methond using the pathname
242+
else:
243+
yield "%s.%s" % (name, subname)
244+
elif useNameSubname == 3:
213245
for subname in find_modules(pathname):
214246
if subname != "__init__":
215-
#doNotAppend = False
216-
#print("name: ", name, " subname: ", subname)
217-
#for obj in nameSubname:
218-
#nam = obj[0]
219-
#subnam = obj[1]
220-
#print("name: ", name, " nam: ", nam, " subname: ", subname, " subnam: ", subnam)
221-
#if (name == nam and subname == subnam) or \
222-
#any(name in sub for sub in re.split("[.]", subnam)):
223-
#print("Excluded: ", name, subname, "because ", nam, subnam)
224-
#doNotAppend = True
225-
#break
226-
#print()
227-
#if not doNotAppend:
228-
#nameSubname.append((name, subname))
229-
print(name, subname)
230-
yield "%s.%s" % (name, subname)
231-
print(name)
247+
yield "%s.%s" % (name, subname)
248+
#print("Name: ", name)
232249
yield name
233250

234251
def find_all_modules(path=None):

importtest.py

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,4 @@
44
foo = find_modules(os.path.abspath("./importtestfolder"))
55

66
for thing in foo:
7-
pass
8-
9-
#bpython import_completion yield name | #bpython import yield name subname and yield name
10-
#bpdb | #bpdb
11-
#__pycache__ | #__pycache__
12-
# | #bpython __pycache__
13-
#__pycache__ | #__pycache__
14-
# | #curtsiesfrontend __pycache__
15-
# | #bpython curtsiesfrontend.__pycache__
16-
#curtsiesfrontend | #curtsiesfrontend
17-
# | #bpython curtsiesfrontend
18-
#fodder | #fodder
19-
# | #test fodder
20-
# | #bpython test.fodder
21-
#test | #test
22-
# | #bpython test
23-
#__pycache__ | #__pycache__
24-
# | #translations __pycache__
25-
# | #bpython translations.__pycache__
26-
#LC_MESSAGES | #LC_MESSAGES
27-
# | #de LC_MESSAGES
28-
# | #translations de.LC_MESSAGES
29-
# | #bpython translations.de.LC_MESSAGES
30-
#de | #de
31-
#LC_MESSAGES | #LC_MESSAGES
32-
# | #es_ES LC_MESSAGES
33-
# | #translations es_ES.LC_MESSAGES
34-
# | #bpython translations.es_ES.LC_MESSAGES
35-
#es_ES | #es_ES
36-
#LC_MESSAGES | #LC_MESSAGES
37-
# | #fr_FR LC_MESSAGES
38-
# | #translations fr_FR.LC_MESSAGES
39-
# | #bpython translations.fr_FR.LC_MESSAGES
40-
#fr_FR | #fr_FR
41-
#LC_MESSAGES | #LC_MESSAGES
42-
# | #it_IT LC_MESSAGES
43-
# | #translations it_IT.LC_MESSAGES
44-
# | #bpython translations.it_IT.LC_MESSAGES
45-
#it_IT | #it_IT
46-
#LC_MESSAGES | #LC_MESSAGES
47-
# | #nl_NL LC_MESSAGES
48-
# | #translations nl_NL.LC_MESSAGES
49-
# | #bpython translations.nl_NL.LC_MESSAGES
50-
#nl_NL | #nl_NL
51-
#translations | #translations
52-
# | #bpython translations
53-
#bpython | #bpython
54-
#data | #data
55-
#source | #source
56-
# | #sphinx source
57-
# | #doc sphinx.source
58-
#sphinx | #sphinx
59-
# | #doc sphinx
60-
#doc | #doc
61-
#Level2 | #Level2
62-
# | #Level1 Level2
63-
# | #Level0 Level1.Level2
64-
# | #importtestfolder Level0.Level1.Level2
65-
#Level1 | #Level1
66-
#Level0 | #Level0
67-
# | #importtestfolder Level0
68-
#importtestfolder | #importtestfolder
69-
#pip-wheel-metadata | #pip-wheel-metadata
7+
print("YIELD:", thing)

0 commit comments

Comments
 (0)