src/eric7/Graphics/PackageDiagramBuilder.py

branch
eric7
changeset 9646
ab5678db972f
parent 9645
31aaa11672d3
child 9653
e67609152c5e
equal deleted inserted replaced
9645:31aaa11672d3 9646:ab5678db972f
152 extensions = Preferences.getPython("Python3Extensions") + [".rb"] 152 extensions = Preferences.getPython("Python3Extensions") + [".rb"]
153 153
154 subpackagesDict = {} 154 subpackagesDict = {}
155 subpackagesList = [] 155 subpackagesList = []
156 156
157 # TODO: replace os.listdir() with os.scandir() 157 with os.scandir(self.package) as dirEntriesIterator:
158 for subpackage in os.listdir(self.package): 158 for subpackage in dirEntriesIterator:
159 subpackagePath = os.path.join(self.package, subpackage) 159 if (
160 if ( 160 subpackage.is_dir()
161 os.path.isdir(subpackagePath) 161 and subpackage.name != "__pycache__"
162 and subpackage != "__pycache__" 162 and len(glob.glob(os.path.join(subpackage.path, "__init__.*"))) != 0
163 and len(glob.glob(os.path.join(subpackagePath, "__init__.*"))) != 0 163 ):
164 ): 164 subpackagesList.append(subpackage.path)
165 subpackagesList.append(subpackagePath)
166 165
167 tot = 0 166 tot = 0
168 for ext in supportedExt: 167 for ext in supportedExt:
169 for subpackage in subpackagesList: 168 for subpackage in subpackagesList:
170 tot += len(glob.glob(FileSystemUtilities.normjoinpath(subpackage, ext))) 169 tot += len(glob.glob(FileSystemUtilities.normjoinpath(subpackage, ext)))
176 self.tr("%v/%m Modules"), 175 self.tr("%v/%m Modules"),
177 self.parent(), 176 self.parent(),
178 ) 177 )
179 progress.setWindowTitle(self.tr("Package Diagram")) 178 progress.setWindowTitle(self.tr("Package Diagram"))
180 try: 179 try:
180 start = 0
181 progress.show() 181 progress.show()
182 QApplication.processEvents() 182 QApplication.processEvents()
183 183
184 now = time.monotonic() 184 now = time.monotonic()
185 for subpackage in subpackagesList: 185 for subpackage in subpackagesList:
188 modules = [] 188 modules = []
189 for ext in supportedExt: 189 for ext in supportedExt:
190 modules.extend( 190 modules.extend(
191 glob.glob(FileSystemUtilities.normjoinpath(subpackage, ext)) 191 glob.glob(FileSystemUtilities.normjoinpath(subpackage, ext))
192 ) 192 )
193 for prog, module in enumerate(modules): 193 for prog, module in enumerate(modules, start=start):
194 progress.setValue(prog) 194 progress.setValue(prog)
195 if time.monotonic() - now > 0.01: 195 if time.monotonic() - now > 0.01:
196 QApplication.processEvents() 196 QApplication.processEvents()
197 now = time.monotonic() 197 now = time.monotonic()
198 try: 198 try:
204 else: 204 else:
205 name = mod.name 205 name = mod.name
206 if "." in name: 206 if "." in name:
207 name = name.rsplit(".", 1)[1] 207 name = name.rsplit(".", 1)[1]
208 subpackagesDict[packageName].append(name) 208 subpackagesDict[packageName].append(name)
209 start = prog
209 subpackagesDict[packageName].sort() 210 subpackagesDict[packageName].sort()
210 # move __init__ to the front 211 # move __init__ to the front
211 if "__init__" in subpackagesDict[packageName]: 212 if "__init__" in subpackagesDict[packageName]:
212 subpackagesDict[packageName].remove("__init__") 213 subpackagesDict[packageName].remove("__init__")
213 subpackagesDict[packageName].insert(0, "__init__") 214 subpackagesDict[packageName].insert(0, "__init__")

eric ide

mercurial