Skip to content

Commit

Permalink
Merge pull request #131 from mrc-ide/mrc-5358
Browse files Browse the repository at this point in the history
mrc-5358: Report absolute path for root when helpful in hipercow_init
  • Loading branch information
richfitz authored Jun 14, 2024
2 parents cb95e01 + d1eb0ab commit 1039ac1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hipercow
Title: High Performance Computing
Version: 1.0.24
Version: 1.0.25
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
11 changes: 8 additions & 3 deletions R/root.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@
##' path <- withr::local_tempfile()
##' hipercow_init(path)
hipercow_init <- function(root = ".", driver = NULL, ...) {
abs_path <- fs::path_abs(root)
norm_path <- fs::path_norm(root)
not_same_path <- (abs_path != norm_path)
desc_root <- sprintf("'%s'%s", root,
if (not_same_path) sprintf(" (%s)", abs_path) else "")
dest <- file.path(root, "hipercow")
if (fs::dir_exists(dest)) {
cli::cli_alert_info("hipercow already initialised at '{root}'")
cli::cli_alert_info("hipercow already initialised at {desc_root}")
} else if (fs::file_exists(dest)) {
cli::cli_abort(
"Unexpected file 'hipercow' (rather than directory) found at '{root}'")
"Unexpected file 'hipercow' (rather than directory) found at {desc_root}")
} else {
fs::dir_create(dest)
cli::cli_alert_success("Initialised hipercow at '{root}'")
cli::cli_alert_success("Initialised hipercow at {desc_root}")
}
root <- hipercow_root(root)
if (is.null(driver)) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hipercow.windows
Title: DIDE HPC Support for Windows
Version: 1.0.24
Version: 1.0.25
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-root.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,21 @@ test_that("Prevent loading old root", {
expect_true(task_eval(b$ids[[13]], root = path_old))
expect_equal(task_result(b$ids[[13]], root = path_old), sqrt(13))
})


test_that("Report working directory if helpful", {
path <- withr::local_tempdir()
withr::with_dir(path,
res <- testthat::evaluate_promise(hipercow_init("."))
)
msg <- substring(res$messages[[1]], 3)
expect_match(msg, "Initialised hipercow at '.' (.+)\n")

path <- withr::local_tempdir()
withr::with_dir(path,
res <- testthat::evaluate_promise(hipercow_init(path))
)
msg <- substring(res$messages[[1]], 3)
expect_match(msg, "Initialised hipercow at '.+'\n")

})

0 comments on commit 1039ac1

Please sign in to comment.