Skip to content

feat: Add support for auto reload by watching a set of files in tasks #3286

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

Open
wants to merge 36 commits into
base: main
Choose a base branch
from

Conversation

prsabahrami
Copy link
Contributor

@prsabahrami prsabahrami commented Mar 6, 2025

This PR introduces a new feature to pixi, pixi watch allowing it to watch files for changes and rerun tasks automatically.
The tasks can be defined as they would have been defined before and hence no changes are needed in the pixi.toml file.
The pixi watch command looks at the globs in the inputs field of a task and runs the task. Then watches the files that match the glob (relative to project root), then kills the previous task and reruns the task command.
For example, if the below is defined in the pixi.toml file:

[tasks]
watch-test = { cmd = "echo test", inputs = ["*.txt"] }

running pixi watch watch-test will print echo to the stdout whenever any text file is updated (or created) in the root directory until the user cancels it by ctrl_c.
I added a FileWatcher struct that uses rayon and notify to handle the file watching.
The expected behaviour for when the set of inputs is empty is for the task to quit as though pixi run was used.

@prsabahrami prsabahrami changed the title initial commit for autoreload support feat: Add support for auto reload by watching a set of files in tasks Mar 6, 2025
@bollwyvl
Copy link
Contributor

File-based watching is a magical feature! Some thoughts:

Adding a new schema thing seems a bit unnecessary vs using the existing inputs.

To allow all existing pixi projects to benefit from this without having to rewrite anything, perhaps putting the feature behind a pixi watch (instead of run) would allow for reusing the task.taskname.inputs, and avoid surprises on e.g. CI where a watching task that never finishes would be a pretty big problem.

This further introduces the challenge of depends-on in the case of watching.

One option might be to gather the whole list of watched globs -> tasks, and rerun the correct one, in order, when their appropriate input changes. This behavior could be disabled via e.g. pixi watch --skip-deps taskname.

@prsabahrami prsabahrami marked this pull request as draft March 14, 2025 20:43
@prsabahrami prsabahrami marked this pull request as ready for review March 20, 2025 15:42
@prsabahrami prsabahrami requested a review from baszalmstra March 21, 2025 20:51
@baszalmstra baszalmstra removed their request for review March 24, 2025 14:00
Copy link
Contributor

@ruben-arts ruben-arts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the description with the full design idea so I can validate it and see if it works as expected?

@prsabahrami prsabahrami requested a review from ruben-arts March 31, 2025 15:37
@prsabahrami
Copy link
Contributor Author

@Hofer-Julian updated the description!

@prsabahrami prsabahrami removed the request for review from ruben-arts March 31, 2025 15:55
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.

4 participants