Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove root src #130

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
##' depending on the configuration. (Later this will make more sense
##' once we support a "bare" outpack layout.)
##'
##' @section Manually setting report source directory:
##'
##' To manually set the report source directory, you will need to set
##' the path of the directory as the `ORDERLY_REPORT_SRC` environment
##' variable.
##'
##' @title Run a report
##'
##' @param name Name of the report to run. Any leading `./` `src/` or
Expand Down Expand Up @@ -136,12 +142,6 @@
##' then orderly looks in the working directory and up through its
##' parents until it finds an `.outpack` directory
##'
##' @param root_src Separately, the root of the orderly source tree,
##' if separate from the outpack root (given as `root`). This is
##' intended for running reports in situations where the source tree
##' is kept in a different place to the outpack root; see Details
##' for more information.
##'
##' @return The id of the created report (a string)
##'
##' @export
Expand All @@ -158,16 +158,15 @@
##' # and we can query the metadata:
##' orderly2::orderly_metadata_extract(name = "data", root = path)
orderly_run <- function(name, parameters = NULL, envir = NULL, echo = TRUE,
search_options = NULL, root = NULL, locate = TRUE,
root_src = NULL) {
if (is.null(root_src)) {
root <- root_open(root, locate, require_orderly = TRUE,
call = environment())
search_options = NULL, root = NULL, locate = TRUE) {
env_root_src <- Sys.getenv("ORDERLY_SRC_ROOT", NA_character_)
root <- root_open(root, locate, require_orderly = is.na(env_root_src),
call = environment())

if (is.na(env_root_src)) {
root_src <- root$path
} else {
root <- root_open(root, locate, require_orderly = FALSE,
call = environment())
root_src <- orderly_src_root(root_src, locate, call = environment())
root_src <- orderly_src_root(env_root_src, locate, call = environment())
}

name <- validate_orderly_directory(name, root_src, environment())
Expand Down
17 changes: 9 additions & 8 deletions man/orderly_run.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 25 additions & 19 deletions tests/testthat/test-run-separate.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
test_that("can run simple case in separate directory", {
info <- test_prepare_orderly_example_separate("explicit")
id <- orderly_run_quietly("explicit", envir = new.env(),
root = info$outpack, root_src = info$src)
id <- withr::with_envvar(
c(ORDERLY_SRC_ROOT = info$src),
orderly_run_quietly("explicit", envir = new.env(), root = info$outpack)
)
expect_type(id, "character")
expect_true(file.exists(file.path(info$src, "draft")))
expect_false(file.exists(file.path(info$src, "archive")))
Expand All @@ -16,9 +18,10 @@ test_that("can run shared resources case in separate directory", {
## resources are relative to the *source* tree and not the outpack
## root.
info <- test_prepare_orderly_example_separate("shared")
envir <- new.env()
id <- orderly_run_quietly("shared", envir = envir,
root = info$outpack, root_src = info$src)
id <- withr::with_envvar(
c(ORDERLY_SRC_ROOT = info$src),
orderly_run_quietly("shared", envir = new.env(), root = info$outpack)
)
expect_setequal(
dir(file.path(info$outpack, "archive", "shared", id)),
c("shared_data.csv", "mygraph.png", "shared.R"))
Expand All @@ -28,13 +31,14 @@ test_that("can run shared resources case in separate directory", {
test_that("can use dependencies in separate directory", {
## Ensures that we hit the outpack root for pulling deps in
info <- test_prepare_orderly_example_separate(c("data", "depends"))
envir1 <- new.env()
id1 <- orderly_run_quietly("data", envir = envir1,
root = info$outpack, root_src = info$src)
envir2 <- new.env()
id2 <- orderly_run_quietly("depends", envir = envir2,
root = info$outpack, root_src = info$src)

id1 <- withr::with_envvar(
c(ORDERLY_SRC_ROOT = info$src),
orderly_run_quietly("data", envir = new.env(), root = info$outpack)
)
id2 <- withr::with_envvar(
c(ORDERLY_SRC_ROOT = info$src),
orderly_run_quietly("depends", envir = new.env(), root = info$outpack)
)
path1 <- file.path(info$outpack, "archive", "data", id1)
path2 <- file.path(info$outpack, "archive", "depends", id2)

Expand All @@ -48,8 +52,10 @@ test_that("can use dependencies in separate directory", {
test_that("can get git information in separate directory", {
info <- test_prepare_orderly_example_separate("explicit")
info$git <- helper_add_git(info$src)
id <- orderly_run_quietly("explicit", envir = new.env(),
root = info$outpack, root_src = info$src)
id <- withr::with_envvar(
c(ORDERLY_SRC_ROOT = info$src),
orderly_run_quietly("explicit", envir = new.env(), root = info$outpack)
)
meta <- orderly_metadata(id, root = info$outpack)
expect_mapequal(meta$git, info$git[c("sha", "branch", "url")])
})
Expand All @@ -59,13 +65,13 @@ test_that("can't run interactively in separate directory", {
## Picking on depends here because it really requires the outpack
## root
info <- test_prepare_orderly_example_separate(c("data", "depends"))
envir1 <- new.env()
id1 <- orderly_run_quietly("data", envir = envir1,
root = info$outpack, root_src = info$src)
envir2 <- new.env()
id1 <- withr::with_envvar(
c(ORDERLY_SRC_ROOT = info$src),
orderly_run_quietly("data", envir = new.env(), root = info$outpack)
)
path_src <- file.path(info$src, "src", "depends")
expect_error(
withr::with_dir(path_src,
sys.source("depends.R", envir2)),
sys.source("depends.R", new.env())),
"orderly directory '.+' not initialised")
})
Loading