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

Allow to unwatch files with LiveReloadServer #2777

Merged
merged 9 commits into from
Sep 18, 2022

Conversation

mondeja
Copy link
Contributor

@mondeja mondeja commented Feb 23, 2022

I'm working on a project that needs to watch files being served based in the content on other files. I've not found a way to stop watching files for changes. As far as I know, I can't access the watch object returned by observer.schedule needed to unwatch them, so crafted this unwatch method for the server.

Is working as expected in my local environment (Ubuntu 20.04). Mentioning @oprypin as creator and maintainer of the new livereload server.

@mondeja mondeja changed the title Allow to unwatch files between builds with LiveReloadServer Allow to unwatch files with LiveReloadServer Feb 23, 2022
@oprypin
Copy link
Contributor

oprypin commented Sep 16, 2022

Hmm by looking at the dependent pull request, I finally understand the problem that this tries to solve.
One might want to pick up new files to watch throughout the serve, and subsequently "un"-pick them up if they are no longer relevant.
Maybe there should be a better solution, such as building up the list of paths to watch from scratch every time (and calling on_serve every time).
But hm, this certainly can work, without many unnecessary changes.

To not give false hope that this can skip sub-paths of existing directories (the method doesn't even error in case it finds no match!), I think we should instead directly expose the result of observer.schedule and then operate based on it.

@oprypin
Copy link
Contributor

oprypin commented Sep 16, 2022

I looked into it more, and actually found it a bad experience to use those watch references directly. And it didn't even solve what I was trying to solve.

The main problem I was trying to avoid is for a plugin to accidentally unwatch paths that it didn't watch in the first place.
I solved it with a counter instead.
I pushed my changes directly. Sorry if you already started work.

@oprypin
Copy link
Contributor

oprypin commented Sep 16, 2022

Try it out if it works for you

@mondeja
Copy link
Contributor Author

mondeja commented Sep 16, 2022

It works, thank you! 👍🏼

@oprypin oprypin added this to the 1.4.0 milestone Sep 17, 2022
@oprypin oprypin merged commit 0ecb52f into mkdocs:master Sep 18, 2022
@mondeja mondeja deleted the livereload-unwatch branch September 19, 2022 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants