Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[watchmedo] Lazy loading of the PyYAML module #847

Merged
merged 1 commit into from Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.rst
Expand Up @@ -10,6 +10,7 @@ Changelog

- Eliminate timeout in waiting on event queue. (`#861 <https://github.com/gorakhargosh/watchdog/pull/861>`_)
- [inotify] Fix ``not`` equality implementation for ``InotifyEvent``. (`#848 <https://github.com/gorakhargosh/watchdog/pull/848>`_)
- [watchmedo] ``PyYAML`` is loaded only when strictly necessary. Simple usages of ``watchmedo`` are possible without the module being installed. (`#847 <https://github.com/gorakhargosh/watchdog/pull/847>`_)
- Thanks to our beloved contributors: @sattlerc, @JanzenLiu, @BoboTiG

2.1.6
Expand Down
5 changes: 4 additions & 1 deletion src/watchdog/watchmedo.py
Expand Up @@ -31,7 +31,6 @@
from io import StringIO
from textwrap import dedent

import yaml
from watchdog.utils import WatchdogShutdown, load_class
from watchdog.version import VERSION_STRING

Expand Down Expand Up @@ -136,6 +135,8 @@ def load_config(tricks_file_pathname):
:returns:
A dictionary of configuration information.
"""
import yaml

with open(tricks_file_pathname, 'rb') as f:
return yaml.safe_load(f.read())

Expand Down Expand Up @@ -309,6 +310,8 @@ def tricks_generate_yaml(args):
"""
Command to generate Yaml configuration for tricks named on the command line.
"""
import yaml

python_paths = path_split(args.python_path)
add_to_sys_path(python_paths)
output = StringIO()
Expand Down