From 544ad9693b0cb8961237466c1d89b0b2aa4764d9 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 29 Mar 2020 15:12:15 +0200 Subject: [PATCH] use precommit instead of pre_commit --- API | 1 + NAMESPACE | 1 + R/exec.R | 11 +++++++++-- R/install.R | 16 ++++++++-------- R/setup.R | 2 +- _pkgdown.yml | 4 ++-- ...pre_commit_exec.Rd => path_precommit_exec.Rd} | 9 ++++++--- vignettes/manual-installation.Rmd | 6 +++--- 8 files changed, 31 insertions(+), 19 deletions(-) rename man/{path_pre_commit_exec.Rd => path_precommit_exec.Rd} (61%) diff --git a/API b/API index e9e1bbf0b..6d81fc426 100644 --- a/API +++ b/API @@ -7,6 +7,7 @@ install_precommit() open_config(path_root = here::here()) open_wordlist(path_root = here::here()) path_pre_commit_exec(check_if_exists = TRUE) +path_precommit_exec(check_if_exists = TRUE) uninstall_precommit(scope = "repo", ask = "global", path_root = ".") use_precommit(path_cp_config_from = getOption("precommit.path_cp_config_from"), force = FALSE, open = rstudioapi::isAvailable(), path_root = here::here()) use_precommit_config(path_cp_config_from = getOption("precommit.path_cp_config_from"), force, open = rstudioapi::isAvailable(), path_root = here::here(), verbose = FALSE) diff --git a/NAMESPACE b/NAMESPACE index c133ce6fb..cfc49264c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(install_precommit) export(open_config) export(open_wordlist) export(path_pre_commit_exec) +export(path_precommit_exec) export(uninstall_precommit) export(use_precommit) export(use_precommit_config) diff --git a/R/exec.R b/R/exec.R index 7e23f9751..182007e9d 100644 --- a/R/exec.R +++ b/R/exec.R @@ -1,9 +1,9 @@ -#' Locate the pre-comit executable +#' Locate the pre-commit executable #' #' @param check_if_exists Whether or not to make sure the returned path also #' exists. #' @export -path_pre_commit_exec <- function(check_if_exists = TRUE) { +path_precommit_exec <- function(check_if_exists = TRUE) { final <- getOption("precommit.executable") %>% as.character() if (!check_if_exists) { @@ -21,6 +21,13 @@ path_pre_commit_exec <- function(check_if_exists = TRUE) { final } +#' @rdname path_precommit_exec +#' @export +path_pre_commit_exec <- function(check_if_exists = TRUE) { + .Deprecated("path_precommit_exec", old = "path_pre_commit_exec") + path_precommit_exec(check_if_exists = check_if_exists) +} + #' Derive the path to the pre-commit executable #' #' First check if there is an executable on the `$PATH`, then check if the diff --git a/R/install.R b/R/install.R index 4112c24ae..09d75d663 100644 --- a/R/install.R +++ b/R/install.R @@ -11,7 +11,7 @@ install_system <- function() { ) options(precommit.executable = path_derive_precommit_exec()) } else { - path_exec <- path_pre_commit_exec(check_if_exists = FALSE) + path_exec <- path_precommit_exec(check_if_exists = FALSE) usethis::ui_info(c( "pre-commit already installed at the following locations:", paste0("- ", path_exec) @@ -87,7 +87,7 @@ uninstall_precommit_system <- function(ask = TRUE) { "Please remove manually or set the R option to the appropriate ", "executable that lives in a conda environment. You find the ", "currently used executable (conda or other) with ", - "`precommit::path_pre_commit_exec()`." + "`precommit::path_precommit_exec()`." )) } else { out <- system2( @@ -124,16 +124,16 @@ uninstall_precommit_repo <- function(ask) { if (continue) { success <- grepl( "pre-commit uninstalled", - system2(path_pre_commit_exec(), "uninstall", stdout = TRUE) + system2(path_precommit_exec(), "uninstall", stdout = TRUE) ) if (isTRUE(success)) { usethis::ui_done("Uninstalled pre-commit from repo scope.") } if (is_package(".")) { lines <- readLines(".Rbuildignore", encoding = "UTF-8") - pre_commit_hooks_idx <- which(lines == "^\\.pre-commit-hooks\\.yaml$") - remaining <- rlang::seq2(1, length(lines)) %>% setdiff(pre_commit_hooks_idx) - if (length(pre_commit_hooks_idx) > 0) { + precommit_hooks_idx <- which(lines == "^\\.pre-commit-hooks\\.yaml$") + remaining <- rlang::seq2(1, length(lines)) %>% setdiff(precommit_hooks_idx) + if (length(precommit_hooks_idx) > 0) { usethis::ui_info("Removing .pre-commit-hooks.yaml from .Rbuildignore") usethis::write_over(".Rbuildignore", lines[remaining]) } @@ -161,7 +161,7 @@ uninstall_precommit_repo <- function(ask) { install_repo <- function(path_root) { tmp <- tempfile() withr::with_dir(path_root, { - out <- suppressWarnings(system2(path_pre_commit_exec(), "install", stdout = NULL, stderr = tmp)) + out <- suppressWarnings(system2(path_precommit_exec(), "install", stdout = NULL, stderr = tmp)) if (out == 0) { usethis::ui_done("Sucessfully installed pre-commit for repo {fs::path_file(path_root)}.") } else { @@ -171,5 +171,5 @@ install_repo <- function(path_root) { } is_installed <- function() { - fs::file_exists(path_pre_commit_exec(check_if_exists = FALSE)) + fs::file_exists(path_precommit_exec(check_if_exists = FALSE)) } diff --git a/R/setup.R b/R/setup.R index b3d9326ed..3c95682ea 100644 --- a/R/setup.R +++ b/R/setup.R @@ -83,7 +83,7 @@ install_precommit_impl <- function() { autoupdate <- function(path_root = here::here()) { withr::with_dir(path_root, { assert_correct_upstream_repo_url() - out <- system2(path_pre_commit_exec(), "autoupdate") + out <- system2(path_precommit_exec(), "autoupdate") if (out == 0) { usethis::ui_done(paste0( "Ran `pre-commit autoupdate` to get the latest version of the hooks." diff --git a/_pkgdown.yml b/_pkgdown.yml index 94f0652e1..019ee687a 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -16,7 +16,7 @@ reference: - title: "Other" - contents: - uninstall_precommit - - path_pre_commit_exec + - path_precommit_exec destination: docs navbar: @@ -31,4 +31,4 @@ navbar: - text: 'FAQ' href: articles/FAQ.html - text: 'Manual installation' - href: articles/manual-installation.html \ No newline at end of file + href: articles/manual-installation.html diff --git a/man/path_pre_commit_exec.Rd b/man/path_precommit_exec.Rd similarity index 61% rename from man/path_pre_commit_exec.Rd rename to man/path_precommit_exec.Rd index c6b5df221..e04d84322 100644 --- a/man/path_pre_commit_exec.Rd +++ b/man/path_precommit_exec.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/exec.R -\name{path_pre_commit_exec} +\name{path_precommit_exec} +\alias{path_precommit_exec} \alias{path_pre_commit_exec} -\title{Locate the pre-comit executable} +\title{Locate the pre-commit executable} \usage{ +path_precommit_exec(check_if_exists = TRUE) + path_pre_commit_exec(check_if_exists = TRUE) } \arguments{ @@ -11,5 +14,5 @@ path_pre_commit_exec(check_if_exists = TRUE) exists.} } \description{ -Locate the pre-comit executable +Locate the pre-commit executable } diff --git a/vignettes/manual-installation.Rmd b/vignettes/manual-installation.Rmd index a255e3613..1813b11fd 100644 --- a/vignettes/manual-installation.Rmd +++ b/vignettes/manual-installation.Rmd @@ -16,7 +16,7 @@ sure R finds the executable. To check that, start a new R session after the installation process of pre-commit has completely successfully and run this command: ```{r, eval = FALSE} -precommit::path_pre_commit_exec() +precommit::path_precommit_exec() #> "/usr/local/bin/pre-commit" ``` If it shows a path (like above), you are all set. Skip the rest of this @@ -45,12 +45,12 @@ installation method and operating system, so it's hard for us to give general advice. You may use a Google search like *where does pip install executable on Ubuntu?* to find the path to the executable. -We are working towards making `precommit::path_pre_commit_exec()` find +We are working towards making `precommit::path_precommit_exec()` find executables automatically with any operating system and installation method, so please open up an [issue](https://github.com/lorenzwalthert/precommit/issues) on GitHub and tell us your installation method, platform and the location of the executable so we can adapt the search heuristic of -`precommit::path_pre_commit_exec()`. +`precommit::path_precommit_exec()`. If you can't get it right, you can still install via conda, where linking the executable is not required.