### Install Watchdog from PyPI Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst Install the Watchdog library from PyPI using pip. To include the `watchmedo` utility, install the `watchdog[watchmedo]` package. ```bash python -m pip install -U watchdog ``` ```bash # or to install the watchmedo utility: python -m pip install -U 'watchdog[watchmedo]' ``` -------------------------------- ### Install Watchdog using pip Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/index.md Install the watchdog library using pip. This command ensures you get the latest version. ```bash $ python -m pip install -U watchdog ``` -------------------------------- ### Install Watchdog from Source Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst Install Watchdog from its source code using pip in editable mode. To include `watchmedo`, use the `.[watchmedo]` extra. ```bash python -m pip install -e . ``` ```bash # or to install the watchmedo utility: python -m pip install -e '.[watchmedo]' ``` -------------------------------- ### Monitor Directory Recursively with Watchdog Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/quickstart.md This example monitors the current directory recursively for file system changes and prints events to the console. It requires importing necessary classes from `watchdog.events` and `watchdog.observers`. The observer is started and kept alive with a `while True` loop, and stopped gracefully in a `finally` block. ```python import time from watchdog.events import FileSystemEvent, FileSystemEventHandler from watchdog.observers import Observer class MyEventHandler(FileSystemEventHandler): def on_any_event(self, event: FileSystemEvent) -> None: print(event) event_handler = MyEventHandler() observer = Observer() observer.schedule(event_handler, ".", recursive=True) observer.start() try: while True: time.sleep(1) finally: observer.stop() observer.join() ``` -------------------------------- ### Install Watchdog via pip Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/installation.md Installs the Watchdog library using the Python package manager. Includes an optional command to install the watchmedo utility. ```bash python -m pip install -U watchdog python -m pip install -U 'watchdog[watchmedo]' ``` -------------------------------- ### Install Watchdog from source tarball Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/installation.md Downloads, extracts, and installs the Watchdog library from a source tarball. Requires a local Python environment. ```bash wget -c https://pypi.python.org/packages/source/w/watchdog/watchdog-7.0.0.tar.gz tar zxvf watchdog-7.0.0.tar.gz cd watchdog-7.0.0 python -m pip install -e . python -m pip install -e '.[watchmedo]' ``` -------------------------------- ### Install Watchdog from repository Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/installation.md Clones the Watchdog source code directly from GitHub and installs it in editable mode. This is useful for developers or those needing the latest version. ```bash git clone --recursive git://github.com/gorakhargosh/watchdog.git cd watchdog python -m pip install -e . python -m pip install -e '.[watchmedo]' ``` -------------------------------- ### Example tricks.yaml Configuration Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst This YAML file configures `watchmedo` tricks for event handling. It includes a `LoggerTrick` and a custom `GoogleClosureTrick`, specifying patterns, mappings, and directories for JavaScript file processing. ```yaml tricks: - watchdog.tricks.LoggerTrick: patterns: ["**/*.py", "**/*.js"] - watchmedo_webtricks.GoogleClosureTrick: patterns: ['**/*.js'] hash_names: true mappings_format: json # json|yaml|python mappings_module: app/javascript_mappings suffix: .min.js compilation_level: advanced # simple|advanced source_directory: app/static/js/ destination_directory: app/public/js/ files: index-page: - app/static/js/vendor/jquery*.js - app/static/js/base.js - app/static/js/index-page.js about-page: - app/static/js/vendor/jquery*.js - app/static/js/base.js - app/static/js/about-page/**/*.js ``` -------------------------------- ### Activate virtual environment and install watchdog (Linux) Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/hacking.md This snippet demonstrates activating the Python virtual environment and installing the watchdog package in editable mode on Linux systems. ```bash . venv/bin/activate (venv)$ python -m pip install -e '.' ``` -------------------------------- ### Activate virtual environment and install watchdog (Windows) Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/hacking.md This snippet shows how to activate the Python virtual environment and install the watchdog package in editable mode on Windows systems. ```batch > venv\Scripts\activate (venv)> python -m pip install -e '.' ``` -------------------------------- ### Watchmedo Help Command Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst To get help on any `watchmedo` command, use the `--help` flag after the command name. ```bash watchmedo [command] --help ``` -------------------------------- ### Watchmedo Log Help Command Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst To get help on the `watchmedo log` command specifically, use the `--help` flag after `log`. ```bash watchmedo log --help ``` -------------------------------- ### Monitor Directory Recursively Using Context Manager Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/quickstart.md This variation demonstrates using the `watchdog.observers.Observer` as a context manager for more concise code. The `with observer:` statement automatically handles starting and stopping the observer, ensuring proper cleanup. ```python import time from watchdog.events import FileSystemEvent, FileSystemEventHandler from watchdog.observers import Observer class MyEventHandler(FileSystemEventHandler): def on_any_event(self, event: FileSystemEvent) -> None: print(event) event_handler = MyEventHandler() observer = Observer() observer.schedule(event_handler, ".", recursive=True) with observer: while True: time.sleep(1) ``` -------------------------------- ### Run Tox Tests Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst Execute tests using Tox. Ensure you have created and activated your virtual environment and installed `tox` first. You can specify the environment with `-e ENV` and quiet mode with `-q`. ```bash python -m pip install tox python -m tox [-q] [-e ENV] ``` -------------------------------- ### Clone watchdog and set up virtual environment (Bash) Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/hacking.md This snippet shows how to clone the watchdog repository, navigate into the directory, and create a Python virtual environment. ```bash git clone https://github.com/gorakhargosh/watchdog.git cd watchdog python -m venv venv ``` -------------------------------- ### Watchdog Utilities API Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/api.md Documentation for utility functions and directory snapshot capabilities. ```APIDOC ## Watchdog Utilities API ### Description This section outlines the API for utility functions provided by the `watchdog.utils` module. ### Method N/A (Module Documentation) ### Endpoint N/A (Module Documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## Watchdog Directory Snapshot API ### Description API reference for the directory snapshot utility found in `watchdog.utils.dirsnapshot`. ### Method N/A (Module Documentation) ### Endpoint N/A (Module Documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Type Hinting with Watchdog Observer Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/quickstart.md When using type annotations with watchdog, it's important to use `watchdog.observers.api.BaseObserver` for type hinting, as `watchdog.observers.Observer` is a variable holding the best available observer class for the platform, not a class itself. ```python from watchdog.observers import Observer from watchdog.observers.api import BaseObserver def my_func(obs: BaseObserver) -> None: # Do something with obs pass observer: BaseObserver = Observer() my_func(observer) ``` -------------------------------- ### Use PollingObserver for CIFS Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst When monitoring changes in CIFS file systems, explicitly use PollingObserver instead of relying on watchdog's default observer selection. This ensures proper functionality in such environments. ```python from watchdog.observers.polling import PollingObserver as Observer ``` -------------------------------- ### Watchdog Tricks API Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/api.md API reference for the tricks module, which likely contains event handling recipes or patterns. ```APIDOC ## Watchdog Tricks API ### Description This section provides API documentation for the `watchdog.tricks` module, which typically contains event handling patterns and recipes. ### Method N/A (Module Documentation) ### Endpoint N/A (Module Documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Increase File Descriptor Limit for kqueue Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst When using watchdog with kqueue on macOS, increase the number of allowed file descriptors by adding this line to your ~/.profile file. This is necessary because kqueue uses file descriptors for monitoring. ```shell ulimit -n 1024 ``` ```shell ulimit -n unlimited ``` -------------------------------- ### Logging Specific File Events with Watchmedo Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst Use `watchmedo log` to recursively monitor the current directory for events related to `*.py` and `*.txt` files, ignoring directory events. The `--patterns`, `--ignore-directories`, `--recursive`, and `--verbose` flags control the logging behavior. ```bash watchmedo log \ --patterns='**/*.py;**/*.txt' \ --ignore-directories \ --recursive \ --verbose \ . ``` -------------------------------- ### Watchdog Events API Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/api.md Documentation for the events module within the Watchdog library. ```APIDOC ## Watchdog Events API ### Description This section details the API for the `watchdog.events` module, which handles file system event objects. ### Method N/A (Module Documentation) ### Endpoint N/A (Module Documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Executing Shell Commands on File Events with Watchmedo Source: https://github.com/gorakhargosh/watchdog/blob/master/README.rst This command uses `watchmedo shell-command` to execute a shell command whenever `*.py` or `*.txt` files change. The `${watch_src_path}` variable provides the path of the changed file to the command. ```bash watchmedo shell-command \ --patterns='**/*.py;**/*.txt' \ --recursive \ --command='echo "${watch_src_path}"' \ . ``` -------------------------------- ### Watchdog Observers API Source: https://github.com/gorakhargosh/watchdog/blob/master/docs/source/api.md API reference for the observers module, including polling and general observer functionalities. ```APIDOC ## Watchdog Observers API ### Description This section covers the API for the `watchdog.observers` module, including its sub-modules for polling and general observer patterns. ### Method N/A (Module Documentation) ### Endpoint N/A (Module Documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## Watchdog Observers Polling API ### Description API documentation specific to the polling observer implementation within the `watchdog.observers.polling` module. ### Method N/A (Module Documentation) ### Endpoint N/A (Module Documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.