diff --git a/docs/index.md b/docs/index.md index 25af2a3c..142fb105 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/watchfiles/_rust_notify.pyi b/watchfiles/_rust_notify.pyi index bcc7591d..8c57add9 100644 --- a/watchfiles/_rust_notify.pyi +++ b/watchfiles/_rust_notify.pyi @@ -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( diff --git a/watchfiles/main.py b/watchfiles/main.py index d541a07b..eab42467 100644 --- a/watchfiles/main.py +++ b/watchfiles/main.py @@ -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: @@ -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. @@ -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: diff --git a/watchfiles/run.py b/watchfiles/run.py index 76f37b08..83819509 100644 --- a/watchfiles/run.py +++ b/watchfiles/run.py @@ -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 @@ -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]