getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.6k stars 444 forks source link

nikola auto plugin constant loop due to watching opened and closed file events. #3683

Closed mccullerlp closed 1 year ago

mccullerlp commented 1 year ago

Environment

Python Version: Python 3.9 using conda forge for most packages Nikola Version: Nikola v8.2.3 installed through pip

Operating System: debian linux

Description:

With the current version of watchdog, events are generated when files are opened or closed. A number of files generate these events during the build process, which currently causes the built-in Nikola plugin "auto" and its associated command, to constantly rebuild after the first build is triggered.

The fix is simply to ignore those events inside the init.py of the "auto" plugin:

    async def queue_rebuild(self, event) -> None:
        """Rebuild the site."""
        # Move events have a dest_path, some editors like gedit use a
        # move on larger save operations for write protection
        event_path = event.dest_path if hasattr(event, 'dest_path') else event.src_path
        if sys.platform == 'win32':
            # Windows hidden files support
            is_hidden = os.stat(event_path).st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN
        else:
            is_hidden = False
        has_hidden_component = any(p.startswith('.') for p in event_path.split(os.sep))
        if event.event_type in ['opened', 'closed']:
            return

The last two lines here were added and seem to fix the issue. Tested by copying the plugin to a local folder.

Kwpolska commented 1 year ago

This issue is fixed on the master branch. A new release is overdue, I’ll try to release it before the end of the month.