Skip to content

Commit

Permalink
Merge pull request #198 from mrc-ide/mrc-5965
Browse files Browse the repository at this point in the history
Print message when pulling packets
  • Loading branch information
richfitz authored Nov 6, 2024
2 parents 3921d68 + 7aa9830 commit 9eebaad
Show file tree
Hide file tree
Showing 3 changed files with 45 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: orderly2
Title: Orderly Next Generation
Version: 1.99.54
Version: 1.99.55
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Robert", "Ashton", role = "aut"),
Expand Down
19 changes: 15 additions & 4 deletions R/location.R
Original file line number Diff line number Diff line change
Expand Up @@ -430,26 +430,35 @@ orderly_location_pull <- function(expr,
hint))
}

cli_alert_info(
"Pulling {length(ids)} packet{?s}: {squote(ids)}")

plan <- location_build_pull_plan(ids, location, recursive, root,
call = environment())

if (plan$info$n_extra > 0) {
cli::cli_alert_info(paste(
cli_alert_info(paste(
"Also pulling {plan$info$n_extra} packet{?s},",
"dependencies of those requested"))
}
if (plan$info$n_skip > 0) {
cli::cli_alert_info(paste(
cli_alert_info(paste(
"Skipping {plan$info$n_skip} of {plan$info$n_total} packet{?s}",
"already unpacked"))
}

n_pull <- plan$info$n_total - plan$info$n_skip
if (n_pull == 0) {
cli_alert_success("Nothing to do, everything is available locally")
return(plan$packet_id)
}

store <- location_pull_files(plan$files, root)

use_archive <- !is.null(root$config$core$path_archive)
if (use_archive) {
n <- length(plan$packet_id)
cli::cli_progress_bar(
cli_progress_bar(
format = paste(
"{cli::pb_spin} Writing files for '{id}' (packet {i} / {n})",
"| ETA: {cli::pb_eta} [{cli::pb_elapsed}]"),
Expand All @@ -462,13 +471,15 @@ orderly_location_pull <- function(expr,
for (i in seq_along(plan$packet_id)) {
id <- plan$packet_id[[i]]
if (use_archive) {
cli::cli_progress_update()
cli_progress_update()
location_pull_files_archive(id, store$value, root)
}
mark_packet_known(id, local, plan$hash[[id]], Sys.time(), root)
}
store$cleanup()

cli_alert_success("Unpacked {n_pull} packet{?s}")

invisible(plan$packet_id)
}

Expand Down
29 changes: 29 additions & 0 deletions tests/testthat/test-location.R
Original file line number Diff line number Diff line change
Expand Up @@ -1213,3 +1213,32 @@ test_that("verify location on addition", {
root = root))
expect_equal(orderly_location_list(root = root), c("local", "upstream"))
})


test_that("print list of pulled packets", {
withr::local_options(orderly.quiet = FALSE)
root <- list()
for (name in c("src", "dst")) {
root[[name]] <- create_temporary_root()
}

id <- create_random_packet(root$src)
suppressMessages({
orderly_location_add_path("src", path = root$src$path, root = root$dst)
orderly_location_fetch_metadata(root = root$dst)
})

msgs <- capture_messages(
orderly_location_pull(id, root = root$dst))
expect_match(msgs, sprintf("Pulling 1 packet: '%s'", id),
all = FALSE, fixed = TRUE)
expect_match(msgs, "Unpacked 1 packet",
all = FALSE, fixed = TRUE)

msgs <- capture_messages(
orderly_location_pull(id, root = root$dst))
expect_match(msgs, sprintf("Pulling 1 packet: '%s'", id),
all = FALSE, fixed = TRUE)
expect_match(msgs, "Nothing to do, everything is available locally",
all = FALSE, fixed = TRUE)
})

0 comments on commit 9eebaad

Please sign in to comment.