Skip to content

Commit

Permalink
Fix short path portability
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jun 6, 2024
1 parent 995e36f commit 4927783
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ build_cmdstan <- function(dir,
run_cmd <- make_cmd()
}
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
c("HOME" = short_path(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
Expand All @@ -479,7 +479,7 @@ clean_cmdstan <- function(dir = cmdstan_path(),
cores = getOption("mc.cores", 2),
quiet = FALSE) {
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
c("HOME" = short_path(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
Expand All @@ -501,7 +501,7 @@ clean_cmdstan <- function(dir = cmdstan_path(),

build_example <- function(dir, cores, quiet, timeout) {
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
c("HOME" = short_path(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
Expand Down
4 changes: 2 additions & 2 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,9 @@ compile <- function(quiet = TRUE,
if (compile_standalone) {
expose_stan_functions(self$functions, !quiet)
}

withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
c("HOME" = short_path(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
Expand Down
2 changes: 1 addition & 1 deletion R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ check_target_exe <- function(exe) {
exe_path <- file.path(cmdstan_path(), exe)
if (!file.exists(exe_path)) {
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
c("HOME" = short_path(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
Expand Down
10 changes: 9 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ stanc_cmd <- function() {

# paths and extensions ----------------------------------------------------

short_path <- function(path) {
if (os_is_windows()) {
utils::shortPathName(path)
} else {
path
}
}

# Replace `\\` with `/` in a vector of paths
# Needed for windows if CmdStan version is < 2.21:
# https://github.com/stan-dev/cmdstanr/issues/1#issuecomment-539118598
Expand Down Expand Up @@ -693,7 +701,7 @@ assert_file_exists <- checkmate::makeAssertionFunction(check_file_exists)
get_cmdstan_flags <- function(flag_name) {
cmdstan_path <- cmdstanr::cmdstan_path()
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
c("HOME" = short_path(Sys.getenv("HOME"))),
flags <- wsl_compatible_run(
command = "make",
args = c("-s", paste0("print-", flag_name)),
Expand Down

0 comments on commit 4927783

Please sign in to comment.