From 4a188f561b637c45d741ae758d703c28df57fcb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Schoentgen?= Date: Wed, 15 Dec 2021 14:34:58 +0100 Subject: [PATCH] [watchmedo] Lazy loading of the PyYAML module --- changelog.rst | 1 + src/watchdog/watchmedo.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.rst b/changelog.rst index 5f0e7ddd..cfea69a3 100644 --- a/changelog.rst +++ b/changelog.rst @@ -10,6 +10,7 @@ Changelog - Eliminate timeout in waiting on event queue. (`#861 `_) - [inotify] Fix ``not`` equality implementation for ``InotifyEvent``. (`#848 `_) +- [watchmedo] ``PyYAML`` is loaded only when strictly necessary. Simple usages of ``watchmedo`` are possible without the module being installed. (`#847 `_) - Thanks to our beloved contributors: @sattlerc, @JanzenLiu, @BoboTiG 2.1.6 diff --git a/src/watchdog/watchmedo.py b/src/watchdog/watchmedo.py index 8c2341e8..668984dc 100755 --- a/src/watchdog/watchmedo.py +++ b/src/watchdog/watchmedo.py @@ -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 @@ -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()) @@ -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()