Skip to content

Commit

Permalink
improving docs
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Apr 2, 2022
1 parent 62994db commit 4328ea1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ for changes in watch('./path/to/dir'):
```
See [`watch` docs][watchfiles.watch] for more details.

`watch` (and all other methods) can watch either files or directories and can watch more than one path with
a single instance.

```py
title="awatch Usage"
import asyncio
Expand Down
4 changes: 2 additions & 2 deletions watchfiles/_rust_notify.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class RustNotify:
"""
Create a new RustNotify instance and start a thread to watch for changes.
`FileNotFoundError` is raised if one of the directories does not exist.
`FileNotFoundError` is raised if one of the paths does not exist.
Args:
watch_paths: file system paths to watch for changes
watch_paths: file system paths to watch for changes, can be directories or files
debug: if true, print details about all events to stderr
"""
def watch(
Expand Down
21 changes: 11 additions & 10 deletions watchfiles/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class Change(IntEnum):
"""

added = 1
"""A new file was added."""
"""A new file or directory was added."""
modified = 2
"""A file was modified, can be either a metadata or data change."""
"""A file or directory was modified, can be either a metadata or data change."""
deleted = 3
"""A file was deleted."""
"""A file or directory was deleted."""

def raw_str(self) -> str:
if self == Change.added:
Expand Down Expand Up @@ -64,18 +64,20 @@ def watch(
raise_interrupt: bool = True,
) -> Generator[Set[FileChange], None, None]:
"""
Watch one or more directories and yield a set of changes whenever files change
in those directories (or subdirectories).
Watch one or more paths and yield a set of changes whenever files change.
The paths watched can be directories or files, directories are watched recursively - changes in subdirectories
are also detected.
Args:
*paths: filesystem directories to watch
*paths: filesystem paths to watch
watch_filter: callable used to filter out changes which are not important, you can either use a raw callable
or a [`BaseFilter`][watchfiles.BaseFilter] instance,
defaults to an instance of [`DefaultFilter`][watchfiles.DefaultFilter]. To keep all changes, use `None`.
debounce: maximum time in milliseconds to group changes over before yielding them.
step: time to wait for new changes in milliseconds, if no changes are detected in this time, and
at least one change has been detected, the changes are yielded.
stop_event: event to stop watching, if this is set, the generator will stop yielding changes,
stop_event: event to stop watching, if this is set, the generator will stop iteration,
this can be anything with an `is_set()` method which returns a bool, e.g. `threading.Event()`.
debug: whether to print information about all filesystem changes in rust to stdout.
raise_interrupt: whether to re-raise `KeyboardInterrupt`s, or suppress the error and just stop iterating.
Expand Down Expand Up @@ -124,13 +126,12 @@ async def awatch(
All async methods use [anyio](https://anyio.readthedocs.io/en/latest/) to run the event loop.
Args:
*paths: filesystem directories to watch
stop_event:
*paths: filesystem paths to watch
watch_filter: matches the same argument of [`watch`][watchfiles.watch].
debounce: matches the same argument of [`watch`][watchfiles.watch].
step: matches the same argument of [`watch`][watchfiles.watch].
debug: matches the same argument of [`watch`][watchfiles.watch].
stop_event: `anyio.Event` which can be used to stop iteration, see example below.
debug: matches the same argument of [`watch`][watchfiles.watch].
raise_interrupt: matches the same argument of [`watch`][watchfiles.watch].
Yields:
Expand Down
4 changes: 2 additions & 2 deletions watchfiles/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run_process(
`run_process` can work in two ways:
* Using `multiprocessing.Process` † to run a python function
* Or, use `subprocess.Popen` to run a command
* Or, using `subprocess.Popen` to run a command
!!! note
Expand All @@ -62,7 +62,7 @@ def run_process(
args: arguments to pass to `target`, only used if `target` is a function
kwargs: keyword arguments to pass to `target`, only used if `target` is a function
target_type: type of target. Can be `'function'`, `'command'`, or `'auto'` in which case
[`detect_target_type`][watchfiles.run_process.detect_target_type] is used to determine the type.
[`detect_target_type`][watchfiles.run.detect_target_type] is used to determine the type.
callback: function to call on each reload, the function should accept a set of changes as the sole argument
watch_filter: matches the same argument of [`watch`][watchfiles.watch]
debounce: matches the same argument of [`watch`][watchfiles.watch]
Expand Down

0 comments on commit 4328ea1

Please sign in to comment.