aaronpeikert / repro

Easy Setup of a Reproducible Workflow
GNU General Public License v3.0
34 stars 7 forks source link

Idea: automate() via pre-commit hooks #51

Open brandmaier opened 3 years ago

brandmaier commented 3 years ago

I believe that the major breakpoint with repro is currently that users may change dependencies on packages, code, or scripts and forget to run automate() to update the Dockerfile. Here is an idea to discuss.

What if repro had a function generate_hash_from_yaml() that takes a Rmd-file and generates a hash code from the YAML. With this hash, we can determine whether the header of any given Rmd-file has changed. Then, we use pre-commit hooks (https://github.com/lorenzwalthert/precommit) to trigger automate() whenever the user commits a new version to git if the YAML has changed since the last time.

lorenzwalthert commented 1 year ago

You don’t need that function probably, just create a hook that has a file filter for this file. And if the file matches, run automate. It would be a local hook. You can see some local hooks in the r precommit repo that are not intended for others to use, they are literally tied to that repo and for that repo only. As opposed to like style or linter hooks that the r precommit repo exposes.

aaronpeikert commented 1 year ago

automate() is taking a look at all Rmd files, and all changes in files in the .repro directory may trigger changes. However, there is no harm in just always running it? Maybe people want to opt out of this? Or maybe we should do it as an opt in the first time automate is run?

lorenzwalthert commented 1 year ago

You can also always run it yes, if you specify that in your config file, see the docs. Depends on how long this takes, it’s a bit annoying for the developer if it’s run for no reason. You can always skip individual hooks with setting the end variable SKIP to the hook id when running git commit. SKIP=hook-id git commit -m Test. Or skip all hooks with git commit -m test —no-verify. These approaches don’t work with the git gui in RStudio since you can’t set eng variables or options for the git commit call.

aaronpeikert commented 1 year ago

About 0.162 sec elapsed ;)