precommit initial CRAN release

Jun 13, 2020 18:07 · 479 words · 3 minute read packages workflow

This article was also published on r-bloggers.com

I am happy to announce that {precommit} 0.1.2 is available from CRAN. Pre-commit hooks are tests that run each time you attempt to commit. If the tests pass, the commit will be made, otherwise not. A very basic test is to check if code is syntactically valid, making sure you have not forgotten a comma, brace or quote. Such hooks increase the quality of commits and the consistency in a code base. The goal of this package is to twofold:

  • Provide a set of hooks that are useful when your git repo contains R code. Examples are styling files with {styler} or to make sure there is no browser() in your code. Check out the list of currently supported hooks from this package.

  • Provide usethis-like functionality for common tasks such as installation and set-up and config file modification.

Note that because pre-commit is a language agnostic framework to manage git hooks, you can add other useful hooks to your git repo that are written in / for other languages, e.g. hooks from https://github.com/pre-commit/pre-commit-hooks. Some useful other hooks I discovered in this repo are:

  • check-added-large-files makes sure you don’t commit huge files accidentally.

  • end-of-file-fixer make sure all your committed files have a blank line at the end.

  • formatters for yaml, python and other file types.

There is also a list with many more repos that contain useful hooks.

Convinced? Let’s get started. You’ll find all relevant installation and usage instructions in the README.

If you already use {precommit}…

To guarantee a smooth experience, I suggest everyone who currently uses a devel version to upgrade both the R package (with install.package("precommit")) and the hook reversion (with precommit::autoupdate()). Depending on which devel version you use, we might also have added new hooks and changed the order in the default config file for a better user experience, so you could also make a copy of your current .pre-commit-config.yaml file and then use precommit::use_precommit(force = TRUE) in your repo to replace the config file and then manually port your deviations from the template config to the new config.

If you use conda, you may need to precommit::install_precommit(force = TRUE). You can also check the changelog for breaking changes we introduced before the CRAN release so you can adapt. In particular:

  • conda and reticulate are no longer required.

  • a few arguments in the API were renamed.

  • the speed of some hooks was improved through caching.

If you are a GitHub Actions specialist…

We currently use travis in a non-standard setup because we also have to test different installation methods (pip, conda, brew) on different platforms (macOS, Linux, Windows), but I’d like to switch to GitHub Actions. If you have experience and want to contribute to this, please open an issue on GitHub.

Thanks for everyone who made this release possible:

@alessap, @DaveParr, @dfrankow, @dirkschumacher, @fschoner, @jonmcalder, @krzyslom, @maelle, @maurolepore, @michaelquinn32, @mikekaminsky, @pat-s, @tblazina, and @zkamvar

tweet Share