src/eric7/Graphics/ApplicationDiagramBuilder.py

branch
eric7
changeset 9646
ab5678db972f
parent 9645
31aaa11672d3
child 9653
e67609152c5e
--- a/src/eric7/Graphics/ApplicationDiagramBuilder.py	Fri Dec 23 11:37:49 2022 +0100
+++ b/src/eric7/Graphics/ApplicationDiagramBuilder.py	Sat Dec 24 17:31:46 2022 +0100
@@ -74,7 +74,7 @@
             0,
             tot,
             self.tr("%v/%m Modules"),
-            self.parent(),
+            None,
         )
         progress.setWindowTitle(self.tr("Application Diagram"))
         try:
@@ -117,25 +117,27 @@
             # project is a package
             return path
         else:
-            # TODO: replace os.listdir() with os.scandir()
             # check, if any of the top directories is a package
-            for entry in [e for e in os.listdir(path) if not e.startswith(".")]:
-                fullpath = os.path.join(path, entry)
-                if os.path.isdir(fullpath):
-                    init = os.path.join(fullpath, "__init__.py")
-                    if os.path.exists(init):
-                        candidates.append(fullpath)
+            with os.scandir(path) as dirEntriesIterator:
+                for entry in [
+                    e for e in dirEntriesIterator if not e.name.startswith(".")
+                ]:
+                    if entry.is_dir() and os.path.exists(
+                        os.path.join(entry.path, "__init__.py")
+                    ):
+                        candidates.append(entry.path)
 
-            # TODO: replace os.listdir() with os.scandir()
             # check, if project uses the 'src' layout
-            if os.path.exists(os.path.join(path, "src")):
-                srcPath = os.path.join(path, "src")
-                for entry in [e for e in os.listdir(srcPath) if not e.startswith(".")]:
-                    fullpath = os.path.join(srcPath, entry)
-                    if os.path.isdir(fullpath):
-                        init = os.path.join(fullpath, "__init__.py")
-                        if os.path.exists(init):
-                            candidates.append(fullpath)
+            srcPath = os.path.join(path, "src")
+            if os.path.exists(srcPath):
+                with os.scandir(srcPath) as dirEntriesIterator:
+                    for entry in [
+                        e for e in dirEntriesIterator if not e.name.startswith(".")
+                    ]:
+                        if entry.is_dir() and os.path.exists(
+                            os.path.join(entry.path, "__init__.py")
+                        ):
+                            candidates.append(entry.path)
 
             if len(candidates) == 1:
                 return candidates[0]

eric ide

mercurial