Skip to content

Commit

Permalink
Merge pull request #4 from mrc-ide/epic-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz authored Apr 25, 2023
2 parents a8012f3 + 12dc0bb commit e234766
Show file tree
Hide file tree
Showing 47 changed files with 2,132 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, epic-poc]
pull_request:
branches: [main, master]
branches: [main, master, epic-poc]

name: R-CMD-check

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, epic-poc]
pull_request:
branches: [main, master]
branches: [main, master, epic-poc]
release:
types: [published]
workflow_dispatch:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, epic-poc]
pull_request:
branches: [main, master]
branches: [main, master, epic-poc]

name: test-coverage

Expand Down
9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ Description: Reimplementation of orderly based on outpack.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.2.3
URL: https://github.com/mrc-ide/orderly3
BugReports: https://github.com/mrc-ide/orderly3/issues
Imports:
fs,
jsonlite,
orderly,
outpack,
outpack (>= 0.2.4),
withr,
yaml
Suggests:
jsonvalidate,
mockery,
pkgload,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Remotes: mrc-ide/outpack
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Generated by roxygen2: do not edit by hand

export(orderly_artefact)
export(orderly_dependency)
export(orderly_global_resource)
export(orderly_parameters)
export(orderly_plugin_add_metadata)
export(orderly_plugin_context)
export(orderly_plugin_register)
export(orderly_resource)
export(orderly_run)
21 changes: 18 additions & 3 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ orderly_config_yml_read <- function(path) {
assert_named(raw)
}

## This has a structure that makes using plugins later easier
check <- list(
plugins = orderly_config_validate_plugins,
global_resources = orderly_config_validate_global_resources)

required <- character()
optional <- c(setdiff(names(check), required))

optional <- setdiff(names(check), required)
check_fields(raw, filename, required, optional)

dat <- list()
Expand All @@ -42,3 +41,19 @@ orderly_config_validate_global_resources <- function(global_resources,
global_resources
}
}


orderly_config_validate_plugins <- function(plugins, filename) {
if (is.null(plugins)) {
return(NULL)
}
assert_named(plugins, unique = TRUE, name = sprintf("%s:plugins", filename))

ret <- list()
for (nm in names(plugins)) {
dat <- load_orderly_plugin(nm)
dat$config <- dat$config(plugins[[nm]], filename)
ret[[nm]] <- dat
}
ret
}
59 changes: 59 additions & 0 deletions R/context.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
orderly_context <- function() {
p <- get_active_packet()
is_active <- !is.null(p)
if (is_active) {
path <- p$path
root <- p$root$path
config <- p$orderly3$config
env <- p$orderly3$envir
src <- p$orderly3$src
parameters <- p$parameters
} else {
path <- getwd()
root <- detect_orderly_interactive_path(path)$path
config <- orderly_root(root, FALSE)$config
env <- orderly_environment("orderly3")
src <- path
parameters <- current_orderly_parameters(src, env)
}
list(is_active = is_active, path = path, config = config, env = env,
root = root, src = src, parameters = parameters,
packet = p)
}


## This is a real trick, and is only used in the case where the report
## is being run interactively, and in that case the correct thing is
## *almost certainly* the global environment, as the user has to do
## some tricks to stop that being the case; for example running
##
## source("orderly.R", local = TRUE)
##
## We want to find the environment that corresponds to the top level
## environment for orderly; that will be the one that called the
## plugin function. So we'll have a stack of frames (corresponding to
## the environments on the call stack) with *parents* that look like
## this, outermost first:
##
## - (anything else)
## - (calling environment) <-- this is what we're looking for
## - (plugin)
## - (orderly3; orderly_plugin_context)
## - (orderly3; from orderly_context)
## - (orderly3; from orderly_environment)
##
## so we loop down the stack looking for the first call to a function
## in the plugin package, then take the frame *above* that.
##
## When we want this for a non-plugin case (i.e., the caller is in
## orderly3) then we just need to pass name = "orderly3" here
orderly_environment <- function(name) {
frames <- sys.frames()
for (i in seq_along(frames)[-1]) {
if (environmentName(parent.env(frames[[i]])) == name) {
return(frames[[i - 1]])
}
}
## This error should never surface if the plugin is configured correctly
stop("Could not determine calling environment safely - please report")
}
16 changes: 16 additions & 0 deletions R/interactive.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## This is something that we might improve over time - it will likely
## be useful to have some sort of "register interactive" function
## which we could then just look up.
##
## I am not sure if we also want to allow working interactively from a
## draft directory too.
detect_orderly_interactive_path <- function(path = getwd()) {
path_split <- fs::path_split(path)[[1]]
is_plausible <- length(path_split) > 2 &&
path_split[[length(path_split) - 1]] == "src" &&
file.exists(file.path(path, "../..", "orderly_config.yml"))
if (!is_plausible) {
stop(sprintf("Failed to detect orderly path at '%s'", path))
}
orderly_root(file.path(path, "../.."), FALSE)
}
Loading

0 comments on commit e234766

Please sign in to comment.