Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit_trigger() should trigger when a file moved to a destination under watch #7

Closed
bob-rove opened this issue Oct 17, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@bob-rove
Copy link

bob-rove commented Oct 17, 2022

The issue appears when performing a file move operation from not watched to a watched destination.

Expected behaviour: if destination file path in move operation appears to be watched (while source file path is not), pytest-watcher should trigger pytest.

Here is an example of events appearing when using unison tool, which is syncing changes to remote destination by first creating a temporary file and then renaming it to a destination:

2022-10-17 15:32:18 - Created file: ./tests/sites/.unison.test_discover.py.7f0384dc585055b3fcfb405908d8de58.unison.tmp
2022-10-17 15:32:18 - Modified directory: ./tests/sites
2022-10-17 15:32:18 - Modified file: ./tests/sites/.unison.test_discover.py.7f0384dc585055b3fcfb405908d8de58.unison.tmp
2022-10-17 15:32:18 - Modified directory: ./tests/sites
2022-10-17 15:32:18 - Modified file: ./tests/sites/.unison.test_discover.py.7f0384dc585055b3fcfb405908d8de58.unison.tmp
2022-10-17 15:32:18 - Moved file: from ./tests/sites/.unison.test_discover.py.7f0384dc585055b3fcfb405908d8de58.unison.tmp to ./tests/sites/test_discover.py
2022-10-17 15:32:18 - Modified directory: ./tests/sites

These events gathered with watchdog example code here: https://pypi.org/project/watchdog/

The fix seems to be pretty straightforward - just extend the condition in process_event method to something like this:

    def process_event(self, event: events.FileSystemEvent) -> None:
        if _is_path_watched(event.src_path):
            emit_trigger()
        elif event.event_type == events.EVENT_TYPE_MOVED and _is_path_watched(event.dest_path):
            emit_trigger()
@olzhasar
Copy link
Owner

Hey @bob-rove
Thanks for pointing that out,
I'll take a look

@olzhasar olzhasar mentioned this issue Oct 23, 2022
@olzhasar
Copy link
Owner

@bob-rove
Corresponding changes have been merged and new version released! Thanks, once again

@bob-rove
Copy link
Author

🚀 Awesome! Thanks a lot @olzhasar 🙇
Now it's playing well with Unison and similar sync strategies 👍

@olzhasar olzhasar added the bug Something isn't working label Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants