diff --git a/DESCRIPTION b/DESCRIPTION index a693b491..1ec6e3ff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: orderly2 Title: Orderly Next Generation -Version: 1.99.41 +Version: 1.99.42 Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), email = "rich.fitzjohn@gmail.com"), person("Robert", "Ashton", role = "aut"), diff --git a/NAMESPACE b/NAMESPACE index 4c96b240..82c4d04d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,9 @@ export(orderly_init) export(orderly_interactive_set_search_options) export(orderly_list_src) export(orderly_location_add) +export(orderly_location_add_http) +export(orderly_location_add_packit) +export(orderly_location_add_path) export(orderly_location_list) export(orderly_location_pull_metadata) export(orderly_location_pull_packet) diff --git a/R/location.R b/R/location.R index 03f84665..c728e269 100644 --- a/R/location.R +++ b/R/location.R @@ -3,9 +3,12 @@ ##' based locations are supported, with limited support for custom ##' locations. Note that adding a location does *not* pull metadata ##' from it, you need to call -##' [orderly2::orderly_location_pull_metadata] first. +##' [orderly2::orderly_location_pull_metadata] first. The function +##' `orderly_location_add` can add any sort of location, but the other +##' functions documented here (`orderly_location_add_path`, etc) will +##' typically be much easier to use in practice. ##' -##' We currently support two types of locations - `path`, which points +##' We currently support three types of locations - `path`, which points ##' to an outpack archive accessible by path (e.g., on the same ##' computer or on a mounted network share), `http`, which requires ##' that an outpack server is running at some url and uses an HTTP API @@ -14,13 +17,12 @@ ##' options to these location types will definitely be needed in ##' future. ##' -##' Configuration options for different location types: +##' Configuration options for different location types are described +##' in the arguments to their higher-level functions. ##' ##' **Path locations**: ##' -##' * `path`: The path to the other archive root. This should -##' generally be an absolute path, or the behaviour of outpack will -##' be unreliable. +##' Use `orderly_location_add_path`, which accepts a `path` argument. ##' ##' **HTTP locations**: ##' @@ -29,8 +31,7 @@ ##' the API, but also as we move to support things like TLS and ##' authentication. ##' -##' * `url`: The location of the server, including protocol, for -##' example `http://example.com:8080` +##' Use `orderly_location_add_http`, which accepts a `url` argument. ##' ##' **Packit locations**: ##' @@ -38,15 +39,8 @@ ##' outpack location but also provide authentication and later will ##' have more capabilities we think. ##' -##' * `url`: The location of the server -##' -##' * `token`: The value for your your login token (currently this is -##' a GitHub token with `read:org` scope). If missing or NULL, orderly2 will -##' perform an interactive authentication against GitHub to obtain one. -##' -##' * `save_token`: If no token is provided and interactive authentication is -##' used, this controls whether the GitHub token should be saved to disk. -##' Defaults to TRUE if missing. +##' Use `orderly_location_add_packit`, which accepts `url`, `token` +##' and `save_token` arguments. ##' ##' **Custom locations**: ##' @@ -100,26 +94,16 @@ orderly_location_add <- function(name, type, args, root = NULL, locate = TRUE) { loc <- new_location_entry(name, type, args, call = environment()) if (type == "path") { - ## We won't be necessarily be able to do this _generally_ but - ## here, let's confirm that we can read from the outpack archive - ## at the requested path; this will just fail but without - ## providing the user with anything actionable yet. - assert_scalar_character(loc$args[[1]]$path, name = "args$path", - call = environment()) - root_open(loc$args[[1]]$path, locate = FALSE, require_orderly = FALSE) + assert_scalar_character(args$path, name = "path") + root_open(args$path, locate = FALSE, require_orderly = FALSE) } else if (type == "http") { - assert_scalar_character(loc$args[[1]]$url, name = "args$url", - call = environment()) + assert_scalar_character(args$url, name = "url") } else if (type == "packit") { - assert_scalar_character(loc$args[[1]]$url, name = "args$url", - call = environment()) - assert_scalar_character(loc$args[[1]]$token, name = "args$token", - allow_null = TRUE, - call = environment()) - assert_scalar_logical(loc$args[[1]]$save_token, name = "args$save_token", - allow_null = TRUE, - call = environment()) - if (!is.null(loc$args[[1]]$token) && !is.null(loc$args[[1]]$save_token)) { + assert_scalar_character(args$url, name = "url") + assert_scalar_character(args$token, name = "token", allow_null = TRUE) + assert_scalar_logical(args$save_token, name = "save_token", + allow_null = TRUE) + if (!is.null(args$token) && !is.null(args$save_token)) { cli::cli_abort("Cannot specify both 'token' and 'save_token'") } } @@ -132,6 +116,50 @@ orderly_location_add <- function(name, type, args, root = NULL, locate = TRUE) { } +##' @rdname orderly_location_add +##' +##' @param path The path to the other archive root. This should +##' generally be an absolute path, or the behaviour of outpack will +##' be unreliable. +##' +##' @export +orderly_location_add_path <- function(name, path, root = NULL) { + args <- list(path = path) + orderly_location_add(name, "path", args, root = root) +} + + +##' @rdname orderly_location_add +##' +##' @param url The location of the server, including protocol, for +##' example `http://example.com:8080` +##' +##' @export +orderly_location_add_http <- function(name, url, root = NULL) { + args <- list(url = url) + orderly_location_add(name, "http", args, root = root) +} + + +##' @rdname orderly_location_add +##' +##' @param token The value for your your login token (currently this +##' is a GitHub token with `read:org` scope). If `NULL`, orderly2 +##' will perform an interactive authentication against GitHub to +##' obtain one. +##' +##' @param save_token If no token is provided and interactive +##' authentication is used, this controls whether the GitHub token +##' should be saved to disk. Defaults to `TRUE` if `NULL`. +##' +##' @export +orderly_location_add_packit <- function(name, url, token = NULL, + save_token = NULL, root = NULL) { + args <- list(url = url, token = token, save_token = save_token) + orderly_location_add(name, "packit", args, root = root) +} + + ##' Rename an existing location ##' ##' @title Rename a location diff --git a/_pkgdown.yml b/_pkgdown.yml index 72bbe997..506abbc4 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -63,6 +63,9 @@ reference: - subtitle: Manage locations contents: - orderly_location_add + - orderly_location_add_path + - orderly_location_add_http + - orderly_location_add_packit - orderly_location_list - orderly_location_remove - orderly_location_rename diff --git a/man/orderly_location_add.Rd b/man/orderly_location_add.Rd index 42ceb069..d25c1762 100644 --- a/man/orderly_location_add.Rd +++ b/man/orderly_location_add.Rd @@ -2,9 +2,24 @@ % Please edit documentation in R/location.R \name{orderly_location_add} \alias{orderly_location_add} +\alias{orderly_location_add_path} +\alias{orderly_location_add_http} +\alias{orderly_location_add_packit} \title{Add a new location} \usage{ orderly_location_add(name, type, args, root = NULL, locate = TRUE) + +orderly_location_add_path(name, path, root = NULL) + +orderly_location_add_http(name, url, root = NULL) + +orderly_location_add_packit( + name, + url, + token = NULL, + save_token = NULL, + root = NULL +) } \arguments{ \item{name}{The short name of the location to use. Cannot be in @@ -29,6 +44,22 @@ for. If \code{TRUE}, then we looks in the directory given for \code{root} (or the working directory if \code{NULL}) and then up through its parents until it finds an \code{.outpack} directory or \code{orderly_config.yml}} + +\item{path}{The path to the other archive root. This should +generally be an absolute path, or the behaviour of outpack will +be unreliable.} + +\item{url}{The location of the server, including protocol, for +example \verb{http://example.com:8080}} + +\item{token}{The value for your your login token (currently this +is a GitHub token with \code{read:org} scope). If \code{NULL}, orderly2 +will perform an interactive authentication against GitHub to +obtain one.} + +\item{save_token}{If no token is provided and interactive +authentication is used, this controls whether the GitHub token +should be saved to disk. Defaults to \code{TRUE} if \code{NULL}.} } \value{ Nothing @@ -39,10 +70,13 @@ and pulled into your local archive. Currently only file and http based locations are supported, with limited support for custom locations. Note that adding a location does \emph{not} pull metadata from it, you need to call -\link{orderly_location_pull_metadata} first. +\link{orderly_location_pull_metadata} first. The function +\code{orderly_location_add} can add any sort of location, but the other +functions documented here (\code{orderly_location_add_path}, etc) will +typically be much easier to use in practice. } \details{ -We currently support two types of locations - \code{path}, which points +We currently support three types of locations - \code{path}, which points to an outpack archive accessible by path (e.g., on the same computer or on a mounted network share), \code{http}, which requires that an outpack server is running at some url and uses an HTTP API @@ -51,14 +85,12 @@ server. More types may be added later, and more configuration options to these location types will definitely be needed in future. -Configuration options for different location types: +Configuration options for different location types are described +in the arguments to their higher-level functions. \strong{Path locations}: -\itemize{ -\item \code{path}: The path to the other archive root. This should -generally be an absolute path, or the behaviour of outpack will -be unreliable. -} + +Use \code{orderly_location_add_path}, which accepts a \code{path} argument. \strong{HTTP locations}: @@ -66,25 +98,17 @@ Accessing outpack over HTTP requires that an outpack server is running. The interface here is expected to change as we expand the API, but also as we move to support things like TLS and authentication. -\itemize{ -\item \code{url}: The location of the server, including protocol, for -example \verb{http://example.com:8080} -} + +Use \code{orderly_location_add_http}, which accepts a \code{url} argument. \strong{Packit locations}: Packit locations work over HTTPS, and include everything in an outpack location but also provide authentication and later will have more capabilities we think. -\itemize{ -\item \code{url}: The location of the server -\item \code{token}: The value for your your login token (currently this is -a GitHub token with \code{read:org} scope). If missing or NULL, orderly2 will -perform an interactive authentication against GitHub to obtain one. -\item \code{save_token}: If no token is provided and interactive authentication is -used, this controls whether the GitHub token should be saved to disk. -Defaults to TRUE if missing. -} + +Use \code{orderly_location_add_packit}, which accepts \code{url}, \code{token} +and \code{save_token} arguments. \strong{Custom locations}: diff --git a/tests/testthat/test-location-path.R b/tests/testthat/test-location-path.R index 155edab2..dabc4729 100644 --- a/tests/testthat/test-location-path.R +++ b/tests/testthat/test-location-path.R @@ -151,8 +151,7 @@ test_that("can detect differences between locations when destination empty", { ids <- create_random_packet_chain(client, 4) server <- create_temporary_root(use_file_store = TRUE, path_archive = NULL) - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) files <- lapply(ids, function(id) client$index$metadata(id)$files$hash) @@ -183,8 +182,7 @@ test_that("Import complete tree via push into server", { ids <- create_random_packet_chain(client, 4) server <- create_temporary_root(use_file_store = TRUE, path_archive = NULL) - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) plan <- orderly_location_push(ids[[4]], "server", client) @@ -208,8 +206,7 @@ test_that("Import packets into root with archive as well as store", { server <- create_temporary_root(use_file_store = TRUE, path_archive = "archive") - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) plan <- orderly_location_push(ids[[4]], "server", client) @@ -228,8 +225,7 @@ test_that("Prevent pushing things that would corrupt the store", { ids <- create_random_packet_chain(client, 4) server <- create_temporary_root(use_file_store = TRUE, path_archive = NULL) - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) id <- ids[[3]] str <- read_string(file.path(client$path, ".outpack", "metadata", id)) @@ -259,8 +255,7 @@ test_that("Can only push into a root with a file store", { client <- create_temporary_root() ids <- create_random_packet_chain(client, 2) server <- create_temporary_root() - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) expect_error( orderly_location_push(ids[[2]], "server", client), "Can't push files into this server, as it does not have a file store") @@ -271,8 +266,7 @@ test_that("pushing twice does nothing", { client <- create_temporary_root() ids <- create_random_packet_chain(client, 4) server <- create_temporary_root(use_file_store = TRUE, path_archive = NULL) - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) plan1 <- orderly_location_push(ids[[4]], "server", client) plan2 <- orderly_location_push(ids[[4]], "server", client) expect_equal(plan2, list(packet_id = character(), files = character())) @@ -282,8 +276,7 @@ test_that("pushing twice does nothing", { test_that("push overlapping tree", { client <- create_temporary_root() server <- create_temporary_root(use_file_store = TRUE, path_archive = NULL) - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) id_base <- create_random_packet(server) orderly_location_pull_metadata(root = client) @@ -302,8 +295,7 @@ test_that("Push single packet", { id <- create_random_packet(client) server <- create_temporary_root(use_file_store = TRUE, path_archive = NULL) - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) plan <- orderly_location_push(id, "server", client) @@ -357,8 +349,7 @@ test_that("Fail to push sensibly if files have been changed", { ids <- create_random_packet_chain(client, 4) server <- create_temporary_root(use_file_store = TRUE, path_archive = NULL) - orderly_location_add("server", "path", list(path = server$path), - root = client) + orderly_location_add_path("server", path = server$path, root = client) ## Corrupt one file: path <- file.path(client$path, "archive", "b", ids[["b"]], "script.R") diff --git a/tests/testthat/test-location.R b/tests/testthat/test-location.R index 114a4c26..e66ef24a 100644 --- a/tests/testthat/test-location.R +++ b/tests/testthat/test-location.R @@ -15,10 +15,10 @@ test_that("Can add a location", { root[[name]] <- create_temporary_root() } - orderly_location_add("b", "path", list(path = root$b$path), root = root$a) + orderly_location_add_path("b", path = root$b$path, root = root$a) expect_setequal(orderly_location_list(root = root$a), c("local", "b")) - orderly_location_add("c", "path", list(path = root$c$path), root = root$a) + orderly_location_add_path("c", path = root$c$path, root = root$a) expect_setequal(orderly_location_list(root = root$a), c("local", "b", "c")) res <- orderly_location_list(verbose = TRUE, root = root$a) @@ -35,8 +35,7 @@ test_that("Can't add a location with reserved name", { upstream <- create_temporary_root() expect_error( - orderly_location_add("local", "path", list(path = upstream$path), - root = root), + orderly_location_add_path("local", path = upstream$path, root = root), "Cannot add a location with reserved name 'local'") }) @@ -47,11 +46,9 @@ test_that("Can't add a location with existing name", { root[[name]] <- create_temporary_root() } - orderly_location_add("upstream", "path", list(path = root$b$path), - root = root$a) + orderly_location_add_path("upstream", path = root$b$path, root = root$a) expect_error( - orderly_location_add("upstream", "path", list(path = root$c$path), - root = root$a), + orderly_location_add_path("upstream", path = root$c$path, root = root$a), "A location with name 'upstream' already exists") expect_equal(orderly_location_list(root = root$a), c("local", "upstream")) @@ -64,11 +61,11 @@ test_that("Require that (for now) locations must be paths", { other <- temp_file() expect_error( - orderly_location_add("other", "path", list(path = other), root = root), + orderly_location_add_path("other", other, root = root), "Directory does not exist:") fs::dir_create(other) expect_error( - orderly_location_add("other", "path", list(path = other), root = root), + orderly_location_add_path("other", other, root = root), "Did not find existing orderly (or outpack) root in", fixed = TRUE) }) @@ -80,7 +77,7 @@ test_that("Can rename a location", { root[[name]] <- create_temporary_root() } - orderly_location_add("b", "path", list(path = root$b$path), root = root$a) + orderly_location_add_path("b", path = root$b$path, root = root$a) expect_setequal(orderly_location_list(root = root$a), c("local", "b")) orderly_location_rename("b", "c", root = root$a) @@ -95,8 +92,8 @@ test_that("Can't rename a location using an existent name", { root[[name]] <- create_temporary_root() } - orderly_location_add("b", "path", list(path = root$b$path), root = root$a) - orderly_location_add("c", "path", list(path = root$c$path), root = root$a) + orderly_location_add_path("b", path = root$b$path, root = root$a) + orderly_location_add_path("c", path = root$c$path, root = root$a) expect_error(orderly_location_rename("b", "c", root$a), "A location with name 'c' already exists") @@ -130,8 +127,8 @@ test_that("Can remove a location", { root[[name]] <- create_temporary_root() } - orderly_location_add("b", "path", list(path = root$b$path), root = root$a) - orderly_location_add("c", "path", list(path = root$c$path), root = root$a) + orderly_location_add_path("b", path = root$b$path, root = root$a) + orderly_location_add_path("c", path = root$c$path, root = root$a) expect_setequal(orderly_location_list(root = root$a), c("local", "b", "c")) id <- create_random_packet(root$b) @@ -159,9 +156,9 @@ test_that("Removing a location orphans packets only from that location", { root[[name]] <- create_temporary_root() } - orderly_location_add("c", "path", list(path = root$c$path), root = root$b) - orderly_location_add("b", "path", list(path = root$b$path), root = root$a) - orderly_location_add("c", "path", list(path = root$c$path), root = root$a) + orderly_location_add_path("c", path = root$c$path, root = root$b) + orderly_location_add_path("b", path = root$b$path, root = root$a) + orderly_location_add_path("c", path = root$c$path, root = root$a) expect_setequal(orderly_location_list(root = root$a), c("local", "b", "c")) expect_setequal(orderly_location_list(root = root$b), c("local", "c")) @@ -201,8 +198,8 @@ test_that("re-adding a location de-orphans packets", { root[[name]] <- create_temporary_root()$path } - orderly_location_add("b", "path", list(path = root$b), root = root$a) - orderly_location_add("c", "path", list(path = root$c), root = root$a) + orderly_location_add_path("b", path = root$b, root = root$a) + orderly_location_add_path("c", path = root$c, root = root$a) id_b <- replicate(2, create_random_packet(root$b)) id_c <- replicate(3, create_random_packet(root$c)) @@ -215,7 +212,7 @@ test_that("re-adding a location de-orphans packets", { "Orphaning 3 packets") expect_equal(nrow(root_open(root$a, FALSE)$index$location(orphan)), 5) - orderly_location_add("b", "path", list(path = root$b), root = root$a) + orderly_location_add_path("b", path = root$b, root = root$a) expect_message(orderly_location_pull_metadata(root = root$a), "De-orphaning 2 packets") @@ -247,8 +244,8 @@ test_that("can pull metadata from a file base location", { ids <- vcapply(1:3, function(i) create_random_packet(root_upstream$path)) root_downstream <- create_temporary_root(use_file_store = TRUE) - orderly_location_add("upstream", "path", list(path = root_upstream$path), - root = root_downstream) + orderly_location_add_path("upstream", path = root_upstream$path, + root = root_downstream) expect_equal(orderly_location_list(root = root_downstream), c("local", "upstream")) @@ -271,8 +268,8 @@ test_that("can pull empty metadata", { root_upstream <- create_temporary_root(use_file_store = TRUE) root_downstream <- create_temporary_root(use_file_store = TRUE) - orderly_location_add("upstream", "path", list(path = root_upstream$path), - root = root_downstream) + orderly_location_add_path("upstream", path = root_upstream$path, + root = root_downstream) orderly_location_pull_metadata("upstream", root = root_downstream) index <- root_downstream$index$data() @@ -287,8 +284,7 @@ test_that("pull metadata from subset of locations", { root$a <- create_temporary_root(use_file_store = TRUE) for (name in c("x", "y", "z")) { root[[name]] <- create_temporary_root(use_file_store = TRUE) - orderly_location_add(name, "path", list(path = root[[name]]$path), - root = root$a) + orderly_location_add_path(name, path = root[[name]]$path, root = root$a) } expect_equal(orderly_location_list(root = root$a), @@ -350,10 +346,10 @@ test_that("Can pull metadata through chain of locations", { ## knowing directly about an earlier location ## > a -> b -> c -> d ## > `--------/ - orderly_location_add("a", "path", list(path = root$a$path), root = root$b) - orderly_location_add("b", "path", list(path = root$b$path), root = root$c) - orderly_location_add("b", "path", list(path = root$b$path), root = root$d) - orderly_location_add("c", "path", list(path = root$c$path), root = root$d) + orderly_location_add_path("a", path = root$a$path, root = root$b) + orderly_location_add_path("b", path = root$b$path, root = root$c) + orderly_location_add_path("b", path = root$b$path, root = root$d) + orderly_location_add_path("c", path = root$c$path, root = root$d) ## Create a packet and make sure it's in both b and c id1 <- create_random_packet(root$a) @@ -390,8 +386,7 @@ test_that("can pull a packet from one location to another, using file store", { } id <- create_random_packet(root$src) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) orderly_location_pull_metadata(root = root$dst) suppressMessages(orderly_location_pull_packet(id, root = root$dst)) @@ -411,8 +406,7 @@ test_that("can error where a query returns no packets", { } id <- create_random_packet(root$src) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) err <- expect_error( orderly_location_pull_packet(name = "data", root = root$dst), "No packets found in query, so cannot pull anything") @@ -426,8 +420,7 @@ test_that("can pull a packet from one location to another, archive only", { } id <- create_random_packet(root$src) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) orderly_location_pull_metadata(root = root$dst) suppressMessages(orderly_location_pull_packet(id, root = root$dst)) @@ -455,8 +448,7 @@ test_that("detect and avoid modified files in source repository", { id[[i]] <- p$id } - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) orderly_location_pull_metadata(root = root$dst) ## Corrupt the file in the first id by truncating it: @@ -486,8 +478,7 @@ test_that("Do not unpack a packet twice", { } id <- create_random_packet(root$src) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) orderly_location_pull_metadata(root = root$dst) expect_equal( suppressMessages(orderly_location_pull_packet(id, root = root$dst)), @@ -506,8 +497,7 @@ test_that("Sensible error if packet not known", { } id <- create_random_packet(root$src) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) err <- expect_error( suppressMessages(orderly_location_pull_packet(id, root = root$dst)), sprintf("Failed to find packet '%s'", id), @@ -526,12 +516,11 @@ test_that("Sensible error if dependent packet not known", { } id <- create_random_packet_chain(root$a, 5) - orderly_location_add("a", "path", list(path = root$a$path), - root = root$b) + orderly_location_add_path("a", path = root$a$path, root = root$b) orderly_location_pull_metadata(root = root$b) suppressMessages(orderly_location_pull_packet(id[[5]], root = root$b)) - orderly_location_add("b", "path", list(path = root$b$path), + orderly_location_add_path("b", path = root$b$path, root = root$c) orderly_location_pull_metadata(root = root$c) @@ -558,8 +547,7 @@ test_that("Can pull a tree recursively", { ## This just does a simple graph a -> b -> c id <- as.list(create_random_packet_chain(root$src, 3)) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) orderly_location_pull_metadata(root = root$dst) expect_equal(suppressMessages( orderly_location_pull_packet(id$c, recursive = TRUE, root = root$dst)), @@ -580,8 +568,7 @@ test_that("Can resolve locations", { for (name in c("dst", "a", "b", "c", "d")) { root[[name]] <- create_temporary_root() if (name != "dst") { - orderly_location_add(name, "path", list(path = root[[name]]$path), - root = root$dst) + orderly_location_add_path(name, path = root[[name]]$path, root = root$dst) } } @@ -635,21 +622,20 @@ test_that("Can filter locations", { for (name in c("dst", "a", "b", "c", "d")) { root[[name]] <- create_temporary_root() if (name != "dst") { - orderly_location_add(name, "path", list(path = root[[name]]$path), - root = root$dst) + orderly_location_add_path(name, path = root[[name]]$path, root = root$dst) } } ids_a <- vcapply(1:3, function(i) create_random_packet(root$a$path)) - orderly_location_add("a", "path", list(path = root$a$path), root = root$b) + orderly_location_add_path("a", path = root$a$path, root = root$b) orderly_location_pull_metadata(root = root$b) suppressMessages(orderly_location_pull_packet(ids_a, root = root$b)) ids_b <- c(ids_a, vcapply(1:3, function(i) create_random_packet(root$b$path))) ids_c <- vcapply(1:3, function(i) create_random_packet(root$c$path)) - orderly_location_add("a", "path", list(path = root$a$path), root = root$d) - orderly_location_add("c", "path", list(path = root$c$path), root = root$d) + orderly_location_add_path("a", path = root$a$path, root = root$d) + orderly_location_add_path("c", path = root$c$path, root = root$d) orderly_location_pull_metadata(root = root$d) suppressMessages(orderly_location_pull_packet(ids_a, root = root$d)) suppressMessages(orderly_location_pull_packet(ids_c, root = root$d)) @@ -712,8 +698,7 @@ test_that("can pull from multiple locations with multiple files", { for (name in c("dst", "a", "b")) { root[[name]] <- create_temporary_root() if (name != "dst") { - orderly_location_add(name, "path", list(path = root[[name]]$path), - root = root$dst) + orderly_location_add_path(name, path = root[[name]]$path, root = root$dst) } } @@ -761,7 +746,7 @@ test_that("if recursive pulls are required, pulls are recursive by default", { id <- create_random_packet_chain(root$src, 3) for (r in root[c("shallow", "deep")]) { - orderly_location_add("src", "path", list(path = root$src$path), root = r) + orderly_location_add_path("src", path = root$src$path, root = r) orderly_location_pull_metadata(root = r) } @@ -813,23 +798,21 @@ test_that("validate arguments to packit locations", { "Field missing from args: 'url'") expect_error( - orderly_location_add("other", "packit", - list(url = "example.com", token = 123), - root = root), - "Expected 'args$token' to be character", fixed = TRUE) + orderly_location_add_packit("other", url = "example.com", token = 123, + root = root), + "Expected 'token' to be character", fixed = TRUE) expect_error( - orderly_location_add("other", "packit", - list(url = "example.com", save_token = "value"), - root = root), - "Expected 'args$save_token' to be logical", fixed = TRUE) + orderly_location_add_packit("other", "packit", url = "example.com", + save_token = "value", root = root), + "Expected 'save_token' to be logical", fixed = TRUE) expect_error( - orderly_location_add("other", "packit", - list(url = "example.com", - token = "xx", - save_token = TRUE), - root = root), + orderly_location_add_packit("other", + url = "example.com", + token = "xx", + save_token = TRUE, + root = root), "Cannot specify both 'token' and 'save_token'", fixed = TRUE) expect_equal(orderly_location_list(root = root), "local") @@ -955,8 +938,7 @@ test_that("can pull packets as a result of a query", { ids <- vcapply(1:3, function(i) { create_random_packet(root$src$path, parameters = list(i = i)) }) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst$path) + orderly_location_add_path("src", path = root$src$path, root = root$dst$path) ids_moved <- suppressMessages( orderly_location_pull_packet( "parameter:i < 3", @@ -974,8 +956,7 @@ test_that("pull packet sets allow_remote to TRUE if not given", { } id <- create_random_packet(root$src) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) orderly_location_pull_metadata(root = root$dst) expect_error( orderly_location_pull_packet(NULL, options = list(allow_remote = FALSE), @@ -987,7 +968,7 @@ test_that("pull packet sets allow_remote to TRUE if not given", { test_that("handle metadata where the hash does not match reported", { here <- create_temporary_root() there <- create_temporary_root() - orderly_location_add("server", "path", list(path = there$path), root = here) + orderly_location_add_path("server", path = there$path, root = here) id <- create_random_packet(there) path_metadata <- file.path(there$path, ".outpack", "metadata", id) @@ -1016,8 +997,8 @@ test_that("handle metadata where two locations differ in hash for same id", { create_random_packet(root$a, id = id) create_random_packet(root$b, id = id) - orderly_location_add("a", "path", list(path = root$a$path), root = root$us) - orderly_location_add("b", "path", list(path = root$b$path), root = root$us) + orderly_location_add_path("a", path = root$a$path, root = root$us) + orderly_location_add_path("b", path = root$b$path, root = root$us) orderly_location_pull_metadata(location = "a", root = root$us) err <- expect_error( @@ -1036,7 +1017,7 @@ test_that("avoid duplicated metadata", { skip_if_not_installed("mockery") here <- create_temporary_root() there <- create_temporary_root() - orderly_location_add("server", "path", list(path = there$path), root = here) + orderly_location_add_path("server", path = there$path, root = here) id <- create_random_packet(there) driver <- location_driver("server", root = here) @@ -1063,8 +1044,7 @@ test_that("skip files in the file store", { } id <- create_random_packet_chain(root$src, 3) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) orderly_location_pull_metadata(root = root$dst) suppressMessages(orderly_location_pull_packet(id[[1]], root = root$dst)) @@ -1083,8 +1063,7 @@ test_that("skip files known elsewhere on disk", { } id <- create_random_packet_chain(root$src, 3) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) orderly_location_pull_metadata(root = root$dst) suppressMessages(orderly_location_pull_packet(id[[1]], root = root$dst)) @@ -1101,8 +1080,7 @@ test_that("can prune orphans from tree", { for (name in c("here", "there")) { root[[name]] <- create_temporary_root() } - orderly_location_add("there", "path", list(path = root$there$path), - root = root$here) + orderly_location_add_path("there", path = root$there$path, root = root$here) id <- create_random_packet_chain(root$there, 5) orderly_location_pull_metadata(root = root$here) expect_message( diff --git a/tests/testthat/test-outpack-config.R b/tests/testthat/test-outpack-config.R index 4f7f78f6..3f21c6a1 100644 --- a/tests/testthat/test-outpack-config.R +++ b/tests/testthat/test-outpack-config.R @@ -80,8 +80,7 @@ test_that("Can add file_store", { id <- create_random_packet_chain(root$src, 3) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst$path) + orderly_location_add_path("src", path = root$src$path, root = root$dst$path) orderly_location_pull_metadata(root = root$dst$path) suppressMessages( orderly_location_pull_packet(id[["c"]], root = root$dst$path)) @@ -294,8 +293,7 @@ test_that("Enabling recursive pulls forces pulling missing packets", { expect_false(root$dst$config$core$require_complete_tree) id <- create_random_packet_chain(root$src, 3) - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst$path) + orderly_location_add_path("src", path = root$src$path, root = root$dst$path) orderly_location_pull_metadata(root = root$dst$path) suppressMessages( orderly_location_pull_packet(id[["c"]], root = root$dst$path)) diff --git a/tests/testthat/test-outpack-helpers.R b/tests/testthat/test-outpack-helpers.R index 76ede872..b6f7b5ec 100644 --- a/tests/testthat/test-outpack-helpers.R +++ b/tests/testthat/test-outpack-helpers.R @@ -15,7 +15,7 @@ test_that("can copy files from outpack", { test_that("can copy files from location, using store", { here <- create_temporary_root(use_file_store = TRUE) there <- create_temporary_root(use_file_store = TRUE) - orderly_location_add("there", "path", list(path = there$path), root = here) + orderly_location_add_path("there", path = there$path, root = here) id <- create_random_packet(there) tmp <- withr::local_tempdir() @@ -45,7 +45,7 @@ test_that("can copy files from location, using store", { test_that("can copy files from location, using archive", { here <- create_temporary_root(use_file_store = FALSE) there <- create_temporary_root(use_file_store = TRUE) - orderly_location_add("there", "path", list(path = there$path), root = here) + orderly_location_add_path("there", path = there$path, root = here) id <- create_random_packet(there) tmp <- withr::local_tempdir() diff --git a/tests/testthat/test-outpack-packet.R b/tests/testthat/test-outpack-packet.R index 079377a0..6354c757 100644 --- a/tests/testthat/test-outpack-packet.R +++ b/tests/testthat/test-outpack-packet.R @@ -677,8 +677,7 @@ test_that("can pull in dependency from specific location", { ids[[name]] <- vcapply(1:3, function(i) { create_random_packet(root[[name]], "data", list(p = i)) }) - orderly_location_add(name, "path", list(path = root[[name]]$path), - root = root$a) + orderly_location_add_path(name, path = root[[name]]$path, root = root$a) } orderly_location_pull_metadata(root = root$a) for (id in ids$z) { @@ -724,10 +723,8 @@ test_that("can pull in dependency when not found, if requested", { ids <- vcapply(1:3, function(i) { create_random_packet(root$x, "data", list(p = i)) }) - orderly_location_add("x", "path", list(path = root$x$path), - root = root$a) - orderly_location_add("x", "path", list(path = root$x$path), - root = root$b) + orderly_location_add_path("x", path = root$x$path, root = root$a) + orderly_location_add_path("x", path = root$x$path, root = root$b) path_src_a <- withr::local_tempdir() query <- quote(latest(name == "data" && parameter:p > 2)) diff --git a/tests/testthat/test-outpack-root.R b/tests/testthat/test-outpack-root.R index 0352aea9..734c19f0 100644 --- a/tests/testthat/test-outpack-root.R +++ b/tests/testthat/test-outpack-root.R @@ -101,7 +101,7 @@ test_that("Can work out what packets are missing", { root[[name]] <- create_temporary_root() } ids <- unname(create_random_packet_chain(root$a, 3)) - orderly_location_add("a", "path", list(path = root$a$path), root = root$b) + orderly_location_add_path("a", path = root$a$path, root = root$b) orderly_location_pull_metadata(root = root$b) ## Nothing missing in this case: diff --git a/tests/testthat/test-query-index.R b/tests/testthat/test-query-index.R index b280d10a..5a6eb82d 100644 --- a/tests/testthat/test-query-index.R +++ b/tests/testthat/test-query-index.R @@ -3,8 +3,7 @@ test_that("index can include only unpacked packets", { for (name in c("src", "dst")) { root[[name]] <- create_temporary_root() } - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) x1 <- create_random_packet(root$src, "x") x2 <- create_random_packet(root$src, "x") @@ -77,8 +76,7 @@ test_that("can apply a location filter to index", { root$a <- create_temporary_root(use_file_store = TRUE) for (name in c("x", "y", "z")) { root[[name]] <- create_temporary_root(use_file_store = TRUE) - orderly_location_add(name, "path", list(path = root[[name]]$path), - root = root$a) + orderly_location_add_path(name, path = root[[name]]$path, root = root$a) } ids <- list() diff --git a/tests/testthat/test-query-search.R b/tests/testthat/test-query-search.R index 134800f4..73a70325 100644 --- a/tests/testthat/test-query-search.R +++ b/tests/testthat/test-query-search.R @@ -217,8 +217,7 @@ test_that("Can filter query to packets that are locally available (unpacked)", { root$a <- create_temporary_root(use_file_store = TRUE) for (name in c("x", "y", "z")) { root[[name]] <- create_temporary_root(use_file_store = TRUE) - orderly_location_add(name, "path", list(path = root[[name]]$path), - root = root$a) + orderly_location_add_path(name, path = root[[name]]$path, root = root$a) } ids <- list() @@ -263,8 +262,7 @@ test_that("scope and allow_local can be used together to filter query", { for (name in c("src", "dst")) { root[[name]] <- create_temporary_root(use_file_store = TRUE) } - orderly_location_add("src", "path", list(path = root$src$path), - root = root$dst) + orderly_location_add_path("src", path = root$src$path, root = root$dst) x1 <- create_random_packet(root$src, "x", list(p = 1)) x2 <- create_random_packet(root$src, "x", list(p = 1)) @@ -876,7 +874,7 @@ test_that("allow search before query", { root <- list() root$a <- create_temporary_root(use_file_store = TRUE) root$b <- create_temporary_root(use_file_store = TRUE) - orderly_location_add("b", "path", list(path = root$b$path), root = root$a) + orderly_location_add_path("b", path = root$b$path, root = root$a) ids <- vcapply(1:3, function(i) { create_random_packet(root$b, "data", list(p = i)) }) diff --git a/tests/testthat/test-run.R b/tests/testthat/test-run.R index 122125f5..9641fc7b 100644 --- a/tests/testthat/test-run.R +++ b/tests/testthat/test-run.R @@ -763,8 +763,7 @@ test_that("Can select location when querying dependencies for a report", { ids[[nm]] <- orderly_run_quietly("data", root = path[[nm]], envir = new.env()) - orderly_location_add(nm, "path", list(path = path[[nm]]), - root = path[["us"]]) + orderly_location_add_path(nm, path = path[[nm]], root = path[["us"]]) orderly_location_pull_metadata(nm, root = path[["us"]]) for (i in ids[[nm]]) { suppressMessages(orderly_location_pull_packet(i, root = path[["us"]])) @@ -810,8 +809,7 @@ test_that("can select location when querying dependencies interactively", { if (nm != "us") { ids[[nm]] <- orderly_run_quietly("data", envir = envir1, root = path[[nm]]) - orderly_location_add(nm, "path", list(path = path[[nm]]), - root = path[["us"]]) + orderly_location_add_path(nm, path = path[[nm]], root = path[["us"]]) orderly_location_pull_metadata(nm, root = path[["us"]]) for (i in ids[[nm]]) { suppressMessages(orderly_location_pull_packet(i, root = path[["us"]])) diff --git a/tests/testthat/test-zzz-location-http.R b/tests/testthat/test-zzz-location-http.R index 8992c693..5d571c9c 100644 --- a/tests/testthat/test-zzz-location-http.R +++ b/tests/testthat/test-zzz-location-http.R @@ -83,8 +83,7 @@ describe("http location integration tests", { it("can pull metadata", { root_downstream <- create_temporary_root(use_file_store = TRUE) expect_null(names(root_downstream$index$data()$metadata)) - orderly_location_add("upstream", "http", list(url = url), - root = root_downstream) + orderly_location_add_http("upstream", url = url, root = root_downstream) expect_equal(orderly_location_list(root = root_downstream), c("local", "upstream")) orderly_location_pull_metadata("upstream", root = root_downstream) @@ -115,8 +114,7 @@ describe("http location integration tests", { it("can push a single packet", { root_downstream <- create_temporary_root(use_file_store = TRUE) ids_downstream <- create_random_packet(root_downstream, n_files = 1) - orderly_location_add("upstream", "http", list(url = url), - root = root_downstream) + orderly_location_add_http("upstream", url = url, root = root_downstream) plan <- orderly_location_push(ids_downstream, "upstream", root = root_downstream) @@ -131,8 +129,7 @@ describe("http location integration tests", { it("can push a packet chain into server", { root_downstream <- create_temporary_root(use_file_store = TRUE) ids_downstream <- create_random_packet_chain(root_downstream, 3) - orderly_location_add("upstream", "http", list(url = url), - root = root_downstream) + orderly_location_add_http("upstream", url = url, root = root_downstream) plan <- orderly_location_push(ids_downstream[[3]], "upstream", root = root_downstream) expect_setequal(plan$packet_id, ids_downstream) diff --git a/vignettes/collaboration.Rmd b/vignettes/collaboration.Rmd index e5d9c1a4..c34f8639 100644 --- a/vignettes/collaboration.Rmd +++ b/vignettes/collaboration.Rmd @@ -131,15 +131,13 @@ orderly2::orderly_init(".") orderly2::orderly_list_src() ``` -The plan is to work with Bob, sharing results on their shared server, so Alice adds that to her `orderly2` configuration with `orderly2::orderly_location_add()`: +The plan is to work with Bob, sharing results on their shared "[Packit](https://github.com/mrc-ide/packit)" server, so Alice adds that to her `orderly2` configuration with `orderly2::orderly_location_add_packit()`: ```{r, include = FALSE, inwd = path_alice} -orderly2::orderly_location_add( - "server", "path", list(path = path_server)) +orderly2::orderly_location_add_path("server", path = path_server) ``` ```{r, eval = FALSE, as = "alice"} -orderly2::orderly_location_add( - "server", "http", list(url = "http://orderly.example.com")) +orderly2::orderly_location_add_packit("server", "http://packit.example.com") ``` Once done, she can run any analysis: @@ -160,12 +158,10 @@ Now, consider Bob. He also needs the source code cloned, orderly initialised, an orderly2::orderly_init(".") ``` ```{r, include = FALSE, inwd = path_bob} -orderly2::orderly_location_add( - "server", "path", list(path = path_server)) +orderly2::orderly_location_add_path("server", path = path_server) ``` ```{r, eval = FALSE, as = "bob"} -orderly2::orderly_location_add( - "server", "http", list(url = "http://orderly.example.com")) +orderly2::orderly_location_add_packit("server", "http://packit.example.com") ``` (Here, Bob has also used the name `server` to refer to their shared server, but could have used anything; this is similar to git's use of `origin`.) @@ -263,8 +259,7 @@ orderly2::orderly_init( Create an orderly store with a file store and a complete tree. See `orderly2::orderly_init()` for more details. 1. Add this as a location ```{r, as="alice", inwd = path_alice} -orderly2::orderly_location_add( - "sharepoint", "path", list(path = path_sharepoint_alice)) +orderly2::orderly_location_add_path("sharepoint", path = path_sharepoint_alice) ``` 1. Push any packets you want to share @@ -277,13 +272,10 @@ Then these will be available for your collaborator to pull. Note that the data i 1. Sync the same drive to a location on their machine. Here Bob has synced to `path_sharepoint_bob` 1. Add the location ```{r, as="bob", inwd = path_bob} -orderly2::orderly_location_add( - "alices_orderly", "path", list(path = path_sharepoint_bob)) +orderly2::orderly_location_add_path("alices_orderly", path_sharepoint_bob) ``` 1. Pull the metadata and use the packets as desired ```{r, as="bob", inwd = path_bob} -orderly2::orderly_location_pull_metadata( - "alices_orderly" -) +orderly2::orderly_location_pull_metadata("alices_orderly") ```