diff --git a/R/exec.R b/R/exec.R index a61eb539d..63cb189f4 100644 --- a/R/exec.R +++ b/R/exec.R @@ -42,24 +42,37 @@ path_derive_precommit_exec <- function() { if (path == "") { os <- tolower(Sys.info()[["sysname"]]) if (os == "darwin") { - path <- c( - fs::path(fs::dir_ls(path_if_exist("~/Library/Python/")), "bin"), # pip - "/usr/local/bin" # homebrew - ) %>% - path_derive_precommit_exec_impl() + path <- path_derive_precommit_exec_macOS() } else if (os == "windows") { - # path <- path_derive_precommit_exec_impl("~/.local/bin") + path <- path_derive_precommit_exec_win() } else if (os == "linux") { - path <- path_derive_precommit_exec_impl( - "~/.local/bin" # pip: https://unix.stackexchange.com/questions/240037/why-did-pip-install-a-package-into-local-bin - ) + path <- path_derive_precommit_exec_linux() } } path } +path_derive_precommit_exec_linux <- function() { + path_derive_precommit_exec_impl( + "~/.local/bin" # pip: https://unix.stackexchange.com/questions/240037/why-did-pip-install-a-package-into-local-bin + ) +} + +path_derive_precommit_exec_win <- function() { + path_derive_precommit_exec_impl(fs::path_home("AppData/Roaming/Python/Scripts")) +} + +path_derive_precommit_exec_macOS <- function() { + c( + fs::path(fs::dir_ls(path_if_exist("~/Library/Python/")), "bin"), # pip + "/usr/local/bin" # homebrew + ) %>% + path_derive_precommit_exec_impl() +} + + path_derive_precommit_exec_impl <- function(candidate) { - assumed <- fs::path(candidate, "pre-commit") + assumed <- fs::path(candidate, precommit_executable()) existant <- assumed[fs::file_exists(assumed)] if (length(existant) > 0) { existant[1] @@ -74,7 +87,7 @@ path_derive_precommit_exec_impl <- function(candidate) { #' Returns `""` if no executable is found. #' @keywords internal path_derive_precommit_exec_path <- function() { - unname(Sys.which("pre-commit")[1]) + unname(Sys.which(precommit_executable())[1]) } path_derive_precommit_exec_conda <- function() { @@ -86,10 +99,14 @@ path_derive_precommit_exec_conda <- function() { derived <- fs::path( path_reticulate, ifelse(is_windows(), "Scripts", ""), - ifelse(is_windows(), "pre-commit.exe", "pre-commit") + precommit_executable() ) unname(ifelse(fs::file_exists(derived), derived, "")) }, error = function(e) "" ) } + +precommit_executable <- function() { + ifelse(is_windows(), "pre-commit.exe", "pre-commit") +} diff --git a/appveyor.yml b/appveyor.yml index 3c79731b6..359486c7d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,11 @@ before_build: Rscript -e "tic::before_install()" build_script: Rscript -e "tic::install()" after_build: Rscript -e "tic::after_install()" before_test: Rscript -e "tic::before_script()" -test_script: Rscript -e "tic::script()" +test_script: + - cmd: Rscript -e "tic::script()" + - cmd: "R CMD INSTALL ." + - cmd: pip install pre-commit --user + - cmd: Rscript -e "if (precommit:::path_derive_precommit_exec_win() == '') stop('Could not find pip executable.')" on_success: Rscript -e "try(tic::after_success(), silent = TRUE)" on_failure: Rscript -e "tic::after_failure()" before_deploy: Rscript -e "tic::before_deploy()" @@ -45,6 +49,7 @@ environment: # secure: VXO22OHLkl4YhVIomSMwCZyOTx03Xf2WICaVng9xH7gISlAg8a+qrt1DtFtk8sK5 PYTHON: "C:\Python36" PYTHON_ARCH: "64" + PYTHON_VERSION: "3.6.0" USE_RTOOLS: true artifacts: