115 init = os.path.join(path, "__init__.py") |
115 init = os.path.join(path, "__init__.py") |
116 if os.path.exists(init): |
116 if os.path.exists(init): |
117 # project is a package |
117 # project is a package |
118 return path |
118 return path |
119 else: |
119 else: |
120 # TODO: replace os.listdir() with os.scandir() |
|
121 # check, if any of the top directories is a package |
120 # check, if any of the top directories is a package |
122 for entry in [e for e in os.listdir(path) if not e.startswith(".")]: |
121 with os.scandir(path) as dirEntriesIterator: |
123 fullpath = os.path.join(path, entry) |
122 for entry in [ |
124 if os.path.isdir(fullpath): |
123 e for e in dirEntriesIterator if not e.name.startswith(".") |
125 init = os.path.join(fullpath, "__init__.py") |
124 ]: |
126 if os.path.exists(init): |
125 if entry.is_dir() and os.path.exists( |
127 candidates.append(fullpath) |
126 os.path.join(entry.path, "__init__.py") |
128 |
127 ): |
129 # TODO: replace os.listdir() with os.scandir() |
128 candidates.append(entry.path) |
|
129 |
130 # check, if project uses the 'src' layout |
130 # check, if project uses the 'src' layout |
131 if os.path.exists(os.path.join(path, "src")): |
131 srcPath = os.path.join(path, "src") |
132 srcPath = os.path.join(path, "src") |
132 if os.path.exists(srcPath): |
133 for entry in [e for e in os.listdir(srcPath) if not e.startswith(".")]: |
133 with os.scandir(srcPath) as dirEntriesIterator: |
134 fullpath = os.path.join(srcPath, entry) |
134 for entry in [ |
135 if os.path.isdir(fullpath): |
135 e for e in dirEntriesIterator if not e.name.startswith(".") |
136 init = os.path.join(fullpath, "__init__.py") |
136 ]: |
137 if os.path.exists(init): |
137 if entry.is_dir() and os.path.exists( |
138 candidates.append(fullpath) |
138 os.path.join(entry.path, "__init__.py") |
|
139 ): |
|
140 candidates.append(entry.path) |
139 |
141 |
140 if len(candidates) == 1: |
142 if len(candidates) == 1: |
141 return candidates[0] |
143 return candidates[0] |
142 elif len(candidates) > 1: |
144 elif len(candidates) > 1: |
143 root, ok = QInputDialog.getItem( |
145 root, ok = QInputDialog.getItem( |