Skip to content

Commit a43588e

Browse files
committed
Docs and performance
1 parent e72c238 commit a43588e

10 files changed

+43
-44
lines changed

Diff for: R/class_builder.R

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ target_run.tar_builder <- function(target, envir, path_store) {
128128
target_gc(target)
129129
builder_ensure_deps(target, target$subpipeline, "worker")
130130
frames <- frames_produce(envir, target, target$subpipeline)
131-
builder_set_tar_runtime(target, frames, path_store)
131+
builder_set_tar_runtime(target, frames)
132132
store_update_stage_early(target$store, target$settings$name, path_store)
133133
builder_update_build(target, frames_get_envir(frames))
134134
builder_ensure_paths(target, path_store)
@@ -186,6 +186,8 @@ target_skip.tar_builder <- function(
186186

187187
#' @export
188188
target_conclude.tar_builder <- function(target, pipeline, scheduler, meta) {
189+
on.exit(builder_unset_tar_runtime())
190+
builder_set_tar_runtime(target, NULL)
189191
target_update_queue(target, scheduler)
190192
builder_handle_warnings(target, scheduler)
191193
builder_ensure_workspace(
@@ -496,7 +498,7 @@ builder_wait_correct_hash <- function(target) {
496498
store_ensure_correct_hash(target$store, storage, deployment)
497499
}
498500

499-
builder_set_tar_runtime <- function(target, frames, path_store) {
501+
builder_set_tar_runtime <- function(target, frames) {
500502
tar_runtime$target <- target
501503
tar_runtime$frames <- frames
502504
}

Diff for: R/class_store_repository_cas.R

-9
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ store_upload_object.tar_repository_cas <- function(store) {
3535
text = store$methods_repository$upload,
3636
args = list(key = store$file$hash, path = store$file$stage)
3737
)
38-
tar_assert_true(
39-
all(file.exists(store$file$stage)),
40-
msg = paste0(
41-
"CAS repository upload attempted deleted file ",
42-
store$file$stage,
43-
". Uploads should not delete the output files from targets ",
44-
"because it causes problems with format = \"file\"."
45-
)
46-
)
4738
}
4839

4940
#' @export

Diff for: R/class_store_repository_cas_file.R

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ store_upload_object.tar_repository_cas_file <- function(store) {
2525
tar_assert_true(
2626
all(file.exists(store$file$path)),
2727
msg = paste0(
28-
"CAS repository upload attempted deleted file ",
28+
"CAS repository upload deleted file ",
2929
store$file$path,
30-
". Uploads should not delete the output files from targets ",
31-
"because it causes problems with format = \"file\""
30+
". Uploads should not delete format = \"file\" output files."
3231
)
3332
)
3433
}

Diff for: R/tar_definition.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
tar_definition <- function(
3232
default = targets::tar_target_raw("target_name", quote(identity()))
3333
) {
34-
tar_assert_target(default)
35-
if_any(!is.null(tar_runtime$target), tar_runtime$target, default)
34+
if (is.null(tar_runtime$target)) {
35+
tar_assert_target(default)
36+
default
37+
} else {
38+
.subset2(tar_runtime, "target")
39+
}
3640
}

Diff for: R/tar_repository_cas.R

+3-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@
4242
#'
4343
#' See the [tar_repository_cas_local()] function for an example
4444
#' CAS system based on a local folder on disk.
45-
#' It uses [tar_repository_cas_local_upload()],
46-
#' [tar_repository_cas_local_download()], and
47-
#' [tar_repository_cas_local_exists()] for the respective
48-
#' `upload`, `download`, and `exists` methods.
45+
#' It uses [tar_cas_u()] for uploads,
46+
#' [tar_cas_d()] for downloads, and
47+
#' [tar_cas_e()] for existence.
4948
#' See the "Repository functions" section for specific advice on how
5049
#' to write your own methods.
5150
#' @section Repository functions:

Diff for: R/tar_repository_cas_local.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ tar_cas_u <- function(cas, key, path) {
9393
cas <- cas %|||% path_cas_dir(tar_runtime$store)
9494
to <- file.path(cas, key)
9595
if (!file.exists(to)) {
96-
# Defined in R/utils_files.R. Works on both files and directories.
97-
file_copy(path, to)
96+
if_any(
97+
identical(tar_definition()$settings$format, "file"),
98+
file_copy(path, to), # Defined in R/utils_files.R for files & dirs.
99+
file_move(path, to) # Defined in R/utils_files.R for files & dirs.
100+
)
98101
}
99102
}
100103

@@ -106,7 +109,7 @@ tar_cas_u <- function(cas, key, path) {
106109
#' @inheritParams tar_cas_u
107110
tar_cas_d <- function(cas, key, path) {
108111
cas <- cas %|||% path_cas_dir(tar_runtime$store)
109-
# Defined in R/utils_files.R. Works on both directories.
112+
# Defined in R/utils_files.R. Works on both files and directories.
110113
file_copy(file.path(cas, key), path)
111114
}
112115

Diff for: man/tar_repository_cas.Rd

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/tar_repository_cas_local.Rd

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/tar_repository_cas_local_gc.Rd

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/testthat/test-tar_repository_cas_local.R

+13-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ tar_test("local CAS repository works on default directory", {
4646
tar_target(z, write_file(y), format = "file", repository = repository)
4747
)
4848
})
49-
tar_make(reporter = "silent")
50-
expect_equal(tar_read(x), c(2L, 4L))
51-
expect_equal(unname(tar_read(y)), c(2L, 4L))
52-
expect_equal(unname(tar_read(y, branches = 2L)), 4L)
53-
expect_equal(readLines(tar_read(z)), c("2", "4"))
54-
expect_equal(tar_outdated(), character(0L))
55-
unlink(file.path(tar_config_get("store"), "cas", tar_meta(z)$data))
56-
expect_equal(tar_outdated(), "z")
57-
tar_destroy()
49+
on.exit(tar_option_reset())
50+
for (storage in c("main", "worker")) {
51+
tar_option_set(storage = storage, retrieval = storage)
52+
tar_make(callr_function = NULL, reporter = "silent")
53+
expect_equal(tar_read(x), c(2L, 4L))
54+
expect_equal(unname(tar_read(y)), c(2L, 4L))
55+
expect_equal(unname(tar_read(y, branches = 2L)), 4L)
56+
expect_equal(readLines(tar_read(z)), c("2", "4"))
57+
expect_equal(tar_outdated(), character(0L))
58+
unlink(file.path(tar_config_get("store"), "cas", tar_meta(z)$data))
59+
expect_equal(tar_outdated(), "z")
60+
tar_destroy()
61+
}
5862
})
5963

6064
tar_test("local CAS repository works on custom directory", {

0 commit comments

Comments
 (0)