pathlib: replace py.path.local.visit() with our own function
Part of reducing dependency on `py`. Also enables upcoming improvements. In cases where there are simpler alternatives (in tests), I used those. What's left are a couple of uses in `_pytest.main` and `_pytest.python` and they only have modest requirements, so all of the featureful code from py is not needed.
This commit is contained in:
@@ -16,6 +16,7 @@ from os.path import isabs
|
||||
from os.path import sep
|
||||
from posixpath import sep as posix_sep
|
||||
from types import ModuleType
|
||||
from typing import Callable
|
||||
from typing import Iterable
|
||||
from typing import Iterator
|
||||
from typing import Optional
|
||||
@@ -556,3 +557,17 @@ def resolve_package_path(path: Path) -> Optional[Path]:
|
||||
break
|
||||
result = parent
|
||||
return result
|
||||
|
||||
|
||||
def visit(
|
||||
path: py.path.local, recurse: Callable[[py.path.local], bool],
|
||||
) -> Iterator[py.path.local]:
|
||||
"""Walk path recursively, in breadth-first order.
|
||||
|
||||
Entries at each directory level are sorted.
|
||||
"""
|
||||
entries = sorted(path.listdir())
|
||||
yield from entries
|
||||
for entry in entries:
|
||||
if entry.check(dir=1) and recurse(entry):
|
||||
yield from visit(entry, recurse)
|
||||
|
||||
Reference in New Issue
Block a user