diff --git a/staticjinja/reloader.py b/staticjinja/reloader.py index aef090c..f4ba3d9 100644 --- a/staticjinja/reloader.py +++ b/staticjinja/reloader.py @@ -1,4 +1,5 @@ import os +from pathlib import Path class Reloader(object): @@ -21,17 +22,14 @@ def searchpath(self): def should_handle(self, event_type, filename): """Check if an event should be handled. - An event should be handled if a file in the searchpath was modified. + An event should be handled if a file was created or modified, and + still exists. :param event_type: a string, representing the type of event :param filename: the path to the file that triggered the event. """ - return ( - event_type in ("modified", "created") - and filename.startswith(self.searchpath) - and os.path.isfile(filename) - ) + return event_type in ("modified", "created") and Path(filename).is_file() def event_handler(self, event_type, src_path): """Re-render templates if they are modified. diff --git a/tests/test_staticjinja.py b/tests/test_staticjinja.py index be97bdc..990a02d 100644 --- a/tests/test_staticjinja.py +++ b/tests/test_staticjinja.py @@ -160,12 +160,10 @@ def fake_watch(self): def test_should_handle(reloader, root_path, template_path): exists = template_path / "template1.html" DNE = template_path / "DNE.html" - outside_searchpath = root_path / "file.txt" assert reloader.should_handle("created", str(exists)) assert reloader.should_handle("modified", str(exists)) assert not reloader.should_handle("deleted", str(exists)) assert not reloader.should_handle("modified", str(DNE)) - assert not reloader.should_handle("modified", str(outside_searchpath)) def test_event_handler(monkeypatch, reloader, template_path):