Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions API
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions R/exec.R
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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])
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
}
2 changes: 1 addition & 1 deletion R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ reference:
- title: "Other"
- contents:
- uninstall_precommit
- path_pre_commit_exec
- path_precommit_exec

destination: docs
navbar:
Expand All @@ -31,4 +31,4 @@ navbar:
- text: 'FAQ'
href: articles/FAQ.html
- text: 'Manual installation'
href: articles/manual-installation.html
href: articles/manual-installation.html
9 changes: 6 additions & 3 deletions man/path_pre_commit_exec.Rd → man/path_precommit_exec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vignettes/manual-installation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down