From 14174eb527afaa7818f9e3a43892795e94f5520e Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Nov 2020 16:13:20 +0000 Subject: [PATCH 1/3] Allow importing from a renamed bundle --- R/bundle.R | 8 +++++--- tests/testthat/test-bundle.R | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/R/bundle.R b/R/bundle.R index 77de5e667..ea58d90c6 100644 --- a/R/bundle.R +++ b/R/bundle.R @@ -199,13 +199,15 @@ orderly_bundle_complete <- function(path) { orderly_bundle_info <- function(path) { + id <- fs::path_split(zip::zip_list(path)$filename[[1]])[[1]] + tmp <- tempfile() dir_create(tmp) on.exit(unlink(tmp)) - id <- sub("\\.zip$", "", basename(path)) + tryCatch( - zip::unzip(path, sprintf("%s/meta/info.rds", id), - junkpaths = TRUE, exdir = tmp), + zip::unzip(path, sprintf("%s/meta/info.rds", id), exdir = tmp, + junkpaths = TRUE), error = function(e) stop(sprintf("Failed to extract bundle info from '%s'\n(%s)", path, e$message), call. = FALSE)) diff --git a/tests/testthat/test-bundle.R b/tests/testthat/test-bundle.R index b62183eab..56088da66 100644 --- a/tests/testthat/test-bundle.R +++ b/tests/testthat/test-bundle.R @@ -256,3 +256,19 @@ test_that("can run a bundle from a relative path", { ## Just ensure that we run without error expect_equal(length(dir(workdir)), 1) }) + + +test_that("Can rename a bundle before import", { + path <- prepare_orderly_example("minimal") + on.exit(unlink(path, recursive = TRUE)) + + path_bundles <- tempfile() + res <- orderly_bundle_pack(path_bundles, "example", root = path) + ans <- orderly_bundle_run(res$path, echo = FALSE) + tmp <- tempfile() + on.exit(unlink(tmp), add = TRUE) + file_copy(ans$path, tmp) + expect_true(orderly_bundle_import(tmp, root = path)) + expect_equal(orderly_list_archive(path), + data_frame(name = "example", id = res$id)) +}) From 25b730663f6c311b9e6d2465c33f414c565fb01c Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Nov 2020 16:15:58 +0000 Subject: [PATCH 2/3] Bump version and add news --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index cb9e28cb2..5e00a4892 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: orderly Title: Lightweight Reproducible Reporting -Version: 1.2.17 +Version: 1.2.18 Description: Order, create and store reports from R. By defining a lightweight interface around the inputs and outputs of an analysis, a lot of the repetitive work for reproducible research diff --git a/NEWS.md b/NEWS.md index ee7cdd163..325dec9aa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# orderly 1.2.18 + +* Allow `orderly_bundle_import` to accept a filename that has been renamed from `.zip`. While this is not generally desireable, it may be needed for some workflows (VIMC-4382) + # orderly 1.2.17 * Fixes bug where `orderly_bundle_pack` failed when the orderly tree and temporary directory were on different filesystems (VIMC-4354) From f2d0abecc7a4a6d640b008467d563a36e281c510 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Nov 2020 16:34:23 +0000 Subject: [PATCH 3/3] Umpdate junk path example --- tests/testthat/test-bundle.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-bundle.R b/tests/testthat/test-bundle.R index 56088da66..e300baff3 100644 --- a/tests/testthat/test-bundle.R +++ b/tests/testthat/test-bundle.R @@ -230,8 +230,8 @@ test_that("can't import an unrun bundle", { test_that("sensible error when given junk input", { path <- orderly::orderly_example("minimal") - tmp <- tempfile() - file.create(tmp) + tmp <- tempfile(fileext = ".zip") + zip_dir(file.path(path, "src"), tmp) expect_error( orderly_bundle_import(tmp, root = path), "Failed to extract bundle info from '.*'")