mosey.Walker
¶
Bases: Protocol
A directory walker, built by Mosey.build.
Walker is the type to annotate walkers with: you never create one yourself.
A walker never changes once it's built, so one walker can take any number of walks,
one after another or at the same time, on any number of threads. Each call to
walk returns its own iterator: share the walker between
threads, but never an iterator.
check_walk_can_start
¶
Check that a walk can start, without walking.
This runs exactly the checks that walk runs before it
returns its iterator, and raises exactly what walk raises for them: the same
exceptions, naming the same paths, as listed under walk's "Raises". It lists
nothing within start, and reads no ignore-files, as documented at
starting directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
PathLike[str] | str
|
Path to the directory to walk. |
required |
start
|
PathLike[str] | str
|
Path to the subdirectory to start in, relative to |
'.'
|
Source code in src/mosey/walker.py
walk
¶
Walk a directory and yield a Step for every file not ignored.
Files are yielded in a deterministic walk order, documented at https://cariad.github.io/mosey/walk-order/.
The files and directories that the walker's patterns ignore aren't yielded or walked, nor are the files and directories within them.
Its patterns are the ones added by
Mosey.add_pattern, and, when it has an ignore-file
name (set by Mosey.set_ignore_filename),
those in each directory's ignore-file, which is read when the
walk reaches the directory. The ignore-files themselves aren't yielded either,
unless the name was set with ignore=False, or a pattern re-includes them.
When the walker ignores symlinks (set by
Mosey.ignore_symlinks), it yields none.
With start, the walk yields only what a walk of root yields within that
subdirectory, and lists nothing beside it, as documented at
starting directories.
To run the checks listed under "Raises" without walking, call
check_walk_can_start.
A relative root is found from the working directory each time a subdirectory is read, so don't change the working directory during a walk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
PathLike[str] | str
|
Path to the directory to walk. |
required |
start
|
PathLike[str] | str
|
Path to the subdirectory to start in, relative to |
'.'
|
Returns:
| Type | Description |
|---|---|
Iterator[Step]
|
An iterator of The iterator raises When the walker has an ignore-file name, it also raises Without |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When |
NotADirectoryError
|
When |
OSError
|
When the operating system can't resolve |
PermissionError
|
When file system permissions deny reaching or listing
|
ValueError
|
When |