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

Epic: proof of concept #4

Merged
merged 57 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
36c2938
Start on proof of concept
richfitz Mar 29, 2023
ce21d08
Run simple report
richfitz Mar 30, 2023
ea8c201
Add docs
richfitz Mar 30, 2023
55ab93a
Expand testing of static reading
richfitz Mar 30, 2023
10fb4a2
More testing
richfitz Mar 30, 2023
249b451
Prevent parameters for now
richfitz Mar 30, 2023
b4b4d5e
Declare all deps
richfitz Mar 30, 2023
1374884
Add test of running outside of orderly
richfitz Mar 30, 2023
13c5178
Remove outdated comments
richfitz Mar 30, 2023
47b19f7
Normalise path with getwd
richfitz Mar 30, 2023
f59c5c1
Update tests/testthat/helper-orderly.R
richfitz Mar 31, 2023
074bf7c
Update tests/testthat/helper-orderly.R
richfitz Mar 31, 2023
12829ef
Fix lint
richfitz Mar 31, 2023
2b5717c
Cope with computed resources
richfitz Mar 31, 2023
7bc9dec
Fix order so that failure always ok
richfitz Mar 31, 2023
28e9384
Merge pull request #2 from mrc-ide/poc
richfitz Apr 3, 2023
52368fb
Basic parameter support
richfitz Apr 3, 2023
58c4c44
Start on interactive use
richfitz Apr 3, 2023
559ebf8
Start on interactive parameters
richfitz Apr 3, 2023
7452a07
Start on basic tests
richfitz Apr 3, 2023
315c438
Share more code
richfitz Apr 3, 2023
01aff2c
Finish basic implementation
richfitz Apr 3, 2023
9c75021
enable gha on branch
richfitz Apr 3, 2023
d2a2d41
Fix up old comments
richfitz Apr 3, 2023
30fcf27
Merge pull request #3 from mrc-ide/pars
richfitz Apr 4, 2023
dbd1e43
Most dependency support
richfitz Mar 31, 2023
3dce250
Flesh out testing
richfitz Mar 31, 2023
e4c5c33
Enable working interactively
richfitz Apr 4, 2023
4e10f9b
Tidy up implementation
richfitz Apr 4, 2023
7391cf8
Tidy up test
richfitz Apr 4, 2023
16f38cf
Simplify
richfitz Apr 4, 2023
155e3c3
Test for helper utility
richfitz Apr 4, 2023
a73db4f
Merge pull request #5 from mrc-ide/deps
r-ash Apr 5, 2023
53232e1
Start on global support
richfitz Apr 11, 2023
235736a
Test and document
richfitz Apr 11, 2023
56f4d01
Expand testing
richfitz Apr 11, 2023
2045640
Support global dependencies on directories
richfitz Apr 11, 2023
36481e8
Merge pull request #7 from mrc-ide/globals
r-ash Apr 11, 2023
df24f33
Fewer assumptions about parameter passing
richfitz Apr 12, 2023
49ea522
Extensible schema
richfitz Apr 12, 2023
5ccf6d3
Add core implementation
richfitz Apr 12, 2023
7b4cb8e
Test loading details
richfitz Apr 12, 2023
5cb892c
Explain and test the environment searching
richfitz Apr 12, 2023
34674ed
Add example
richfitz Apr 12, 2023
dfc1939
Include mockery
richfitz Apr 12, 2023
869965b
Don't use mockery unless supported
richfitz Apr 12, 2023
0ae63ef
Don't leak
richfitz Apr 12, 2023
5f596d0
Add cleanup support
richfitz Apr 17, 2023
da2172a
Update docs
richfitz Apr 18, 2023
d53e6c5
Remove outdated comment
richfitz Apr 19, 2023
b0de4c4
Rename function for consistency
richfitz Apr 19, 2023
9ab2aeb
Merge pull request #9 from mrc-ide/alex-comments
richfitz Apr 19, 2023
822beee
Merge pull request #8 from mrc-ide/plugin
richfitz Apr 19, 2023
2690cb0
Generalise context
richfitz Apr 19, 2023
3610e04
Reuse context support internally
richfitz Apr 19, 2023
e9c366d
Merge pull request #10 from mrc-ide/context
richfitz Apr 25, 2023
12dc0bb
Fix variable name
richfitz Apr 25, 2023
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
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