diff --git a/kitty/window.py b/kitty/window.py index cd1eb629b..7e655d32e 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -776,13 +776,17 @@ class GlobalWatchers: raw_spec = get_options().watcher if raw_spec == self.options_spec: return self.ans - from .launch import load_watch_modules - spec = raw_spec.copy() if self.extra: spec[self.extra] = self.extra - ans = load_watch_modules(spec.keys()) - self.ans = Watchers() if ans is None else ans + if spec: + # Importing launch is slow, so do it only when there are watchers + from .launch import load_watch_modules + + ans = load_watch_modules(spec.keys()) + self.ans = Watchers() if ans is None else ans + else: + self.ans = Watchers() self.options_spec = raw_spec.copy() return self.ans diff --git a/kitty_tests/layout.py b/kitty_tests/layout.py index f94959a7f..3eb2cce8a 100644 --- a/kitty_tests/layout.py +++ b/kitty_tests/layout.py @@ -1751,10 +1751,12 @@ class TestWindowHelpers(BaseTest): opts.watcher = {'a.py': 'a.py'} self.assertIs(g(), w1) opts.watcher = {} + num_calls = len(calls) ans = g() self.assertIsNot(ans, w1) self.assertIsInstance(ans, Watchers) - self.ae(calls[-1], ()) + # with no watchers, the slow to import launch module is not used + self.ae(len(calls), num_calls) # changing the extra watcher after first use must take effect g.set_extra('y.py') self.assertIs(g(), w1)