MCPcopy Create free account
hub / github.com/pytest-dev/pytest / visit

Function visit

src/_pytest/pathlib.py:630–656  ·  view source on GitHub ↗

Walk a directory recursively, in breadth-first order. Entries at each directory level are sorted.

(
    path: Union[str, "os.PathLike[str]"], recurse: Callable[["os.DirEntry[str]"], bool]
)

Source from the content-addressed store, hash-verified

628
629
630def visit(
631 path: Union[str, "os.PathLike[str]"], recurse: Callable[["os.DirEntry[str]"], bool]
632) -> Iterator["os.DirEntry[str]"]:
633 """Walk a directory recursively, in breadth-first order.
634
635 Entries at each directory level are sorted.
636 """
637
638 # Skip entries with symlink loops and other brokenness, so the caller doesn't
639 # have to deal with it.
640 entries = []
641 for entry in os.scandir(path):
642 try:
643 entry.is_file()
644 except OSError as err:
645 if _ignore_error(err):
646 continue
647 raise
648 entries.append(entry)
649
650 entries.sort(key=lambda entry: entry.name)
651
652 yield from entries
653
654 for entry in entries:
655 if entry.is_dir() and recurse(entry):
656 yield from visit(entry.path, recurse)
657
658
659def absolutepath(path: Union[Path, str]) -> Path:

Callers 4

collectMethod · 0.90
collectMethod · 0.90
copytreeFunction · 0.85

Calls 2

_ignore_errorFunction · 0.85
appendMethod · 0.80

Tested by 1