(item: base.ScanLocation)
| 128 | |
| 129 | @staticmethod |
| 130 | def scan_directory(item: base.ScanLocation): |
| 131 | logger.debug(f"Collecting files in a directory '{item.str_location}") |
| 132 | topo = TopologySort() |
| 133 | collected = [] |
| 134 | |
| 135 | for f in utils.walk(item.location): |
| 136 | new_item = item.create_child( |
| 137 | f, |
| 138 | parent=item.parent, |
| 139 | strip_path=item.strip_path |
| 140 | ) |
| 141 | collected.append(new_item) |
| 142 | topo.add_node(Path(new_item.location).absolute()) |
| 143 | |
| 144 | logger.debug("Computing import graph") |
| 145 | |
| 146 | for x in collected: |
| 147 | if not x.metadata.get('py_imports'): |
| 148 | continue |
| 149 | |
| 150 | node = Path(x.location).absolute() |
| 151 | topo.add_edge(node, x.metadata['py_imports']['dependencies']) |
| 152 | |
| 153 | topology = topo.sort() |
| 154 | |
| 155 | collected.sort( |
| 156 | key=lambda x: topology.index(x.location) if x.location in topology else 0 |
| 157 | ) |
| 158 | logger.debug("Topology sorting finished") |
| 159 | |
| 160 | return collected |
no test coverage detected