Skip to content

Commit

Permalink
Merge pull request #3677 from gipi/fix-event-handler
Browse files Browse the repository at this point in the history
Make rebuild/reload act only when file is modified.
  • Loading branch information
Kwpolska committed Apr 8, 2023
2 parents 21c8e82 + 64ca06d commit 2b01fa1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Features
Bug Fixes
---------

* Fix ``auto`` command infinite loop (Issue #3677)
* Fix API URL in CSS and JS minifiers (Issue #3658)
* Fix ``:align: center`` for images in reST (Issue #3657)
* ``GZIP_COMMAND`` parsing on ``win32`` platforms (Issue #3649)
Expand Down
15 changes: 6 additions & 9 deletions nikola/plugins/command/auto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,25 +587,22 @@ def __init__(self, function, loop):
self.function = function
self.loop = loop

async def on_any_event(self, event):
"""Handle all file events."""
await self.function(event)

def dispatch(self, event):
"""Dispatch events to handler."""
self.loop.call_soon_threadsafe(asyncio.ensure_future, self.on_any_event(event))
if event.event_type in {"opened", "closed"}:
return
self.loop.call_soon_threadsafe(asyncio.ensure_future, self.function(event))


class ConfigEventHandler(NikolaEventHandler):
"""A Nikola-specific handler for Watchdog that handles the config file (as a workaround)."""

def __init__(self, configuration_filename, function, loop):
"""Initialize the handler."""
super().__init__(function, loop)
self.configuration_filename = configuration_filename
self.function = function
self.loop = loop

async def on_any_event(self, event):
def dispatch(self, event):
"""Handle file events if they concern the configuration file."""
if event._src_path == self.configuration_filename:
await self.function(event)
super().dispatch(event)

0 comments on commit 2b01fa1

Please sign in to comment.