Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodetect pip installation on windows #133

Merged
merged 13 commits into from
Mar 29, 2020
41 changes: 29 additions & 12 deletions R/exec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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() {
Expand All @@ -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")
}
7 changes: 6 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
Expand All @@ -45,6 +49,7 @@ environment:
# secure: VXO22OHLkl4YhVIomSMwCZyOTx03Xf2WICaVng9xH7gISlAg8a+qrt1DtFtk8sK5
PYTHON: "C:\Python36"
PYTHON_ARCH: "64"
PYTHON_VERSION: "3.6.0"
USE_RTOOLS: true

artifacts:
Expand Down