Skip to content

Commit

Permalink
Transport old metadata with new metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Feb 21, 2020
1 parent e11d14c commit b2b7f41
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 81 deletions.
35 changes: 22 additions & 13 deletions R/drake_meta_.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
drake_meta_ <- function(target, config) {
class(target) <- drake_meta_class(target, config)
out <- drake_meta_impl(target, config)
meta_old <- NULL
if (target_exists(target, config)) {
meta_old <- config$cache$get(key = target, namespace = "meta")
}
out <- drake_meta_impl(target, meta_old, config)
class(out) <- c("drake_meta", "drake")
out
}
Expand All @@ -10,7 +14,7 @@ print.drake_meta <- function(x, ...) {
cat("drake metadata for ", display_key(x$name), ":\n", sep = "")
elts <- names(x)
long <- c("command", "date")
lsts <- c("trigger", "time_start", "time_build", "time_command")
lsts <- c("trigger", "time_start", "time_build", "time_command", "meta_old")
list1 <- x[setdiff(elts, c(long, lsts))]
list2 <- x[intersect(elts, long)]
list2 <- lapply(list2, crop_text, width = getOption("width") - 18L)
Expand Down Expand Up @@ -38,15 +42,16 @@ drake_meta_class <- function(target, config) {
"static"
}

drake_meta_impl <- function(target, config) {
drake_meta_impl <- function(target, meta_old, config) {
UseMethod("drake_meta_impl")
}

drake_meta_impl.imported_file <- function(target, config) { # nolint
drake_meta_impl.imported_file <- function(target, meta_old, config) { # nolint
spec <- config$spec[[target]]
meta <- list(
name = target,
target = target,
meta_old = meta_old,
imported = TRUE,
isfile = TRUE,
format = "none",
Expand All @@ -57,15 +62,16 @@ drake_meta_impl.imported_file <- function(target, config) { # nolint
meta$mtime <- storage_mtime(path)
meta$size_storage <- storage_size(path)
spec$trigger <- trigger(condition = TRUE)
meta <- drake_meta_static_triggers(target, meta, spec, config)
meta <- decorate_trigger_meta(target, meta, spec, config)
meta
}

drake_meta_impl.imported_object <- function(target, config) { # nolint
drake_meta_impl.imported_object <- function(target, meta_old, config) { # nolint
spec <- config$spec[[target]]
meta <- list(
name = target,
target = target,
meta_old = meta_old,
imported = TRUE,
isfile = FALSE,
dynamic = FALSE,
Expand All @@ -74,26 +80,28 @@ drake_meta_impl.imported_object <- function(target, config) { # nolint
file_out = spec$deps_build$file_out
)
spec$trigger <- trigger(condition = TRUE)
meta <- drake_meta_static_triggers(target, meta, spec, config)
meta <- decorate_trigger_meta(target, meta, spec, config)
meta
}

drake_meta_impl.subtarget <- function(target, config) {
drake_meta_impl.subtarget <- function(target, meta_old, config) {
list(
name = target,
target = target,
meta_old = meta_old,
imported = FALSE,
isfile = FALSE,
seed = resolve_target_seed(target, config),
time_start = drake_meta_start(config)
)
}

drake_meta_impl.dynamic <- function(target, config) {
drake_meta_impl.dynamic <- function(target, meta_old, config) {
spec <- config$spec[[target]]
meta <- list(
name = target,
target = target,
meta_old = meta_old,
imported = FALSE,
isfile = FALSE,
dynamic = TRUE,
Expand All @@ -104,14 +112,15 @@ drake_meta_impl.dynamic <- function(target, config) {
dynamic_dependency_hash = dynamic_dependency_hash(target, config),
max_expand = spec$max_expand %||NA% config$max_expand
)
drake_meta_static_triggers(target, meta, spec, config)
decorate_trigger_meta(target, meta, spec, config)
}

drake_meta_impl.static <- function(target, config) {
drake_meta_impl.static <- function(target, meta_old, config) {
spec <- config$spec[[target]]
meta <- list(
name = target,
target = target,
meta_old = meta_old,
imported = FALSE,
isfile = FALSE,
dynamic = FALSE,
Expand All @@ -121,11 +130,11 @@ drake_meta_impl.static <- function(target, config) {
seed = resolve_target_seed(target, config),
time_start = drake_meta_start(config)
)
meta <- drake_meta_static_triggers(target, meta, spec, config)
meta <- decorate_trigger_meta(target, meta, spec, config)
meta
}

drake_meta_static_triggers <- function(target, meta, spec, config) {
decorate_trigger_meta <- function(target, meta, spec, config) {
meta$trigger <- as.list(spec$trigger)
if (meta$trigger$command) {
meta$command <- spec$command_standardized
Expand Down
Loading

0 comments on commit b2b7f41

Please sign in to comment.