MCPcopy
hub / github.com/explosion/spaCy / walk_directory

Function walk_directory

spacy/cli/_util.py:268–292  ·  view source on GitHub ↗

Given a directory and a suffix, recursively find all files matching the suffix. Directories or files with names beginning with a . are ignored, but hidden flags on filesystems are not checked. When provided with a suffix `None`, there is no suffix-based filtering.

(path: Path, suffix: Optional[str] = None)

Source from the content-addressed store, hash-verified

266
267
268def walk_directory(path: Path, suffix: Optional[str] = None) -> List[Path]:
269 """Given a directory and a suffix, recursively find all files matching the suffix.
270 Directories or files with names beginning with a . are ignored, but hidden flags on
271 filesystems are not checked.
272 When provided with a suffix `None`, there is no suffix-based filtering."""
273 if not path.is_dir():
274 return [path]
275 paths = [path]
276 locs = []
277 seen = set()
278 for path in paths:
279 if str(path) in seen:
280 continue
281 seen.add(str(path))
282 if path.parts[-1].startswith("."):
283 continue
284 elif path.is_dir():
285 paths.extend(path.iterdir())
286 elif suffix is not None and not path.parts[-1].endswith(suffix):
287 continue
288 else:
289 locs.append(path)
290 # It's good to sort these, in case the ordering messes up cache.
291 locs.sort()
292 return locs
293
294
295def _format_number(number: Union[int, float], ndigits: int = 2) -> str:

Callers 5

test_walk_directoryFunction · 0.90
applyFunction · 0.85
convertFunction · 0.85
verify_cli_argsFunction · 0.85
_get_converterFunction · 0.85

Calls 4

extendMethod · 0.80
appendMethod · 0.80
sortMethod · 0.80
addMethod · 0.45

Tested by 1

test_walk_directoryFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…