Skip to content

Commit

Permalink
Merge pull request #256 from vimc/vimc-4382
Browse files Browse the repository at this point in the history
vimc-4382: Allow orderly_bundle_import to work with arbitrary filename
  • Loading branch information
r-ash authored Nov 9, 2020
2 parents 04cf22c + f2d0abe commit 21d9bd3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# orderly 1.2.18

* Allow `orderly_bundle_import` to accept a filename that has been renamed from `<id>.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)
Expand Down
8 changes: 5 additions & 3 deletions R/bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 18 additions & 2 deletions tests/testthat/test-bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.*'")
Expand All @@ -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))
})

0 comments on commit 21d9bd3

Please sign in to comment.