Skip to content

Commit 0d6798c

Browse files
Merge pull request #330 from lorenzwalthert/issue-329
- locate pre-commit executable on macOs build with pip (#329).
2 parents e1c2d83 + 76fec81 commit 0d6798c

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

R/config.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use_precommit_config <- function(config_source = getOption("precommit.config_sou
4040
)
4141
escaped_name_target <- "^\\.pre-commit-config\\.yaml$"
4242
name_target <- ".pre-commit-config.yaml"
43-
if (!fs::file_exists(fs::path(root, name_target)) | force) {
43+
if (!file_exists(fs::path(root, name_target)) | force) {
4444
fs::file_copy(
4545
config_source,
4646
fs::path(root, name_target),
@@ -103,7 +103,7 @@ set_config_source <- function(config_source,
103103
)
104104
config_source <- system.file(name_origin, package = "precommit")
105105
}
106-
if (!fs::file_exists(config_source)) {
106+
if (!file_exists(config_source)) {
107107
rlang::abort(paste0(
108108
"File ", config_source, " does not exist. Please use the ",
109109
"argument `config_source` to provide a path to an existing ",

R/exec.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ path_precommit_exec <- function(check_if_exists = TRUE) {
2020
if (!check_if_exists) {
2121
return(final)
2222
}
23-
if (!fs::file_exists(final)) {
23+
if (!file_exists(final)) {
2424
rlang::abort(paste0(
2525
"pre-commit executable does not exist at ",
2626
final,
@@ -112,7 +112,7 @@ path_warn_multiple_execs <- function(paths) {
112112

113113
path_candidate_to_actual <- function(candidate) {
114114
assumed <- fs::path(candidate, precommit_executable_file())
115-
assumed[fs::file_exists(assumed)]
115+
assumed[file_exists(assumed)]
116116
}
117117

118118
path_derive_precommit_exec_linux <- function() {
@@ -200,7 +200,7 @@ path_derive_precommit_exec_conda_impl <- function(conda_env) {
200200
ifelse(is_windows(), "Scripts", ""),
201201
precommit_executable_file()
202202
)
203-
unname(ifelse(fs::file_exists(derived), derived, ""))
203+
unname(ifelse(file_exists(derived), derived, ""))
204204
},
205205
error = function(e) ""
206206
)

R/install.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ remove_usethis_readme_hook <- function() {
129129
encoding = "UTF-8"
130130
)
131131
candidate <- ".git/hooks/pre-commit"
132-
if (fs::file_exists(candidate)) {
132+
if (file_exists(candidate)) {
133133
if (identical(readLines(candidate, encoding = "UTF-8"), legacy)) {
134134
fs::file_delete(candidate)
135135
cli::cli_alert_info(paste(
@@ -172,7 +172,7 @@ uninstall_precommit <- function(scope = "repo",
172172
if (scope == "repo") {
173173
uninstall_repo(ask = (ask %in% c("repo", "both")))
174174
path_config <- ".pre-commit-config.yaml"
175-
if (fs::file_exists(path_config)) {
175+
if (file_exists(path_config)) {
176176
fs::file_delete(path_config)
177177
cli::cli_alert_success("Removed .pre-commit-config.yaml")
178178
}
@@ -260,7 +260,7 @@ uninstall_repo <- function(ask) {
260260
}
261261
}
262262
path_file <- ".pre-commit-config.yaml"
263-
if (fs::file_exists(path_file)) {
263+
if (file_exists(path_file)) {
264264
fs::file_delete(path_file)
265265
cli::cli_alert_success(paste(
266266
"Removed .pre-commit-config.yaml. If you want your collaborators",
@@ -280,5 +280,5 @@ uninstall_repo <- function(ask) {
280280
}
281281

282282
is_installed <- function() {
283-
fs::file_exists(path_precommit_exec(check_if_exists = FALSE))
283+
file_exists(path_precommit_exec(check_if_exists = FALSE))
284284
}

R/utils.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ is_url <- function(text) {
1212
inherits("url")
1313
}
1414

15+
file_exists <- function(...) {
16+
fs::file_exists(fs::path_expand(...))
17+
}
18+
1519

1620
path_if_exist <- function(...) {
1721
path <- c(...)
18-
path[fs::file_exists(path)]
22+
path[file_exists(path)]
1923
}
2024

2125
is_conda_installation <- function() {

tests/testthat/test-conda.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ if (!on_cran()) {
9090
uninstall_precommit(scope = "repo", root = tempdir),
9191
"Uninstalled pre-commit from repo scope.*"
9292
)
93-
expect_false(fs::file_exists(fs::path(tempdir, ".pre-commit-config.yaml")))
93+
expect_false(file_exists(fs::path(tempdir, ".pre-commit-config.yaml")))
9494
expect_false(any(grepl(".pre-commit", readline(fs::path(tempdir, ".Rbuildignore")))))
9595
# second time
9696
expect_message(

tests/testthat/test-config.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test_that(".Rbuildignore is written to the right directory when root is relative
5454
fs::path_dir(root),
5555
use_precommit_config(root = fs::path_file(root))
5656
)
57-
expect_true(fs::file_exists(fs::path(root, ".Rbuildignore")))
57+
expect_true(file_exists(fs::path(root, ".Rbuildignore")))
5858
})
5959

6060
test_that(".Rbuildignore is written to the right directory when root is absolute", {
@@ -67,5 +67,5 @@ test_that(".Rbuildignore is written to the right directory when root is absolute
6767
desc$write("DESCRIPTION")
6868
})
6969
use_precommit_config(root = root)
70-
expect_true(fs::file_exists(fs::path(root, ".Rbuildignore")))
70+
expect_true(file_exists(fs::path(root, ".Rbuildignore")))
7171
})

tests/testthat/test-setup.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ test_that("GitHub Action CI setup works", {
2828
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
2929
)
3030
use_ci("gha", root = getwd())
31-
expect_true(fs::file_exists(".github/workflows/pre-commit.yaml"))
31+
expect_true(file_exists(".github/workflows/pre-commit.yaml"))
3232
})
3333

3434
test_that("Pre-commit CI setup works", {
3535
local_test_setup(
3636
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
3737
)
3838
use_ci(root = getwd())
39-
expect_false(fs::file_exists(".github/workflows/pre-commit.yaml"))
39+
expect_false(file_exists(".github/workflows/pre-commit.yaml"))
4040
})

tests/testthat/test-zzz.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that("tests don't write to styler-perm", {
22
skip_on_cran()
3-
expect_false(fs::file_exists(
3+
expect_false(file_exists(
44
fs::path(R.cache::getCacheRootPath(), "styler-perm")
55
))
66
})

0 commit comments

Comments
 (0)