Skip to content

Commit

Permalink
Disambiguate custom formats from custom repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Aug 21, 2024
1 parent 98109bd commit dea079d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 59 deletions.
14 changes: 7 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ S3method(store_convert_object,tar_fst)
S3method(store_convert_object,tar_fst_dt)
S3method(store_convert_object,tar_fst_tbl)
S3method(store_convert_object,tar_parquet)
S3method(store_convert_object,tar_store_custom)
S3method(store_convert_object,tar_store_file)
S3method(store_convert_object,tar_store_format_custom)
S3method(store_convert_object,tar_url)
S3method(store_copy_object,tar_fst_dt)
S3method(store_copy_object,tar_store_custom)
S3method(store_copy_object,tar_store_format_custom)
S3method(store_delete_object,default)
S3method(store_delete_object,tar_gcp)
S3method(store_delete_objects,default)
Expand Down Expand Up @@ -138,7 +138,7 @@ S3method(store_hash_late,tar_store_file)
S3method(store_hash_late,tar_url)
S3method(store_marshal_object,default)
S3method(store_marshal_object,tar_keras)
S3method(store_marshal_object,tar_store_custom)
S3method(store_marshal_object,tar_store_format_custom)
S3method(store_marshal_object,tar_torch)
S3method(store_marshal_value,default)
S3method(store_marshal_value,tar_nonexportable)
Expand Down Expand Up @@ -171,8 +171,8 @@ S3method(store_read_path,tar_null)
S3method(store_read_path,tar_parquet)
S3method(store_read_path,tar_qs)
S3method(store_read_path,tar_rds)
S3method(store_read_path,tar_store_custom)
S3method(store_read_path,tar_store_file)
S3method(store_read_path,tar_store_format_custom)
S3method(store_read_path,tar_torch)
S3method(store_read_path,tar_url)
S3method(store_row_path,default)
Expand All @@ -191,7 +191,7 @@ S3method(store_unload,tar_aws_file)
S3method(store_unload,tar_gcp_file)
S3method(store_unmarshal_object,default)
S3method(store_unmarshal_object,tar_keras)
S3method(store_unmarshal_object,tar_store_custom)
S3method(store_unmarshal_object,tar_store_format_custom)
S3method(store_unmarshal_object,tar_torch)
S3method(store_unmarshal_value,default)
S3method(store_unmarshal_value,tar_nonexportable)
Expand All @@ -204,7 +204,7 @@ S3method(store_upload_object,tar_aws_file)
S3method(store_upload_object,tar_gcp)
S3method(store_upload_object,tar_gcp_file)
S3method(store_validate,default)
S3method(store_validate,tar_store_custom)
S3method(store_validate,tar_store_format_custom)
S3method(store_write_object,default)
S3method(store_write_object,tar_cloud)
S3method(store_write_object,tar_store_file)
Expand All @@ -216,8 +216,8 @@ S3method(store_write_path,tar_null)
S3method(store_write_path,tar_parquet)
S3method(store_write_path,tar_qs)
S3method(store_write_path,tar_rds)
S3method(store_write_path,tar_store_custom)
S3method(store_write_path,tar_store_file)
S3method(store_write_path,tar_store_format_custom)
S3method(store_write_path,tar_torch)
S3method(store_write_path,tar_url)
S3method(tar_make_interactive_load_target,tar_bud)
Expand Down
76 changes: 38 additions & 38 deletions R/class_store_custom.R → R/class_store_format_custom.R
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
#' @export
store_new.format_custom <- function(format, file = NULL, resources = NULL) {
format <- unlist(strsplit(format, split = "&", fixed = TRUE))
store <- store_custom_new(
store <- store_format_custom_new(
file = file,
resources = resources,
read = store_custom_field(
read = store_format_custom_field(
format = format,
pattern = "^read=",
default = store_custom_default_read()
default = store_format_custom_default_read()
),
write = store_custom_field(
write = store_format_custom_field(
format = format,
pattern = "^write=",
default = store_custom_default_write()
default = store_format_custom_default_write()
),
marshal = store_custom_field(
marshal = store_format_custom_field(
format = format,
pattern = "^marshal=",
default = store_custom_default_marshal()
default = store_format_custom_default_marshal()
),
unmarshal = store_custom_field(
unmarshal = store_format_custom_field(
format = format,
pattern = "^unmarshal=",
default = store_custom_default_unmarshal()
default = store_format_custom_default_unmarshal()
),
convert = store_custom_field(
convert = store_format_custom_field(
format = format,
pattern = "^convert=",
default = store_custom_default_convert()
default = store_format_custom_default_convert()
),
copy = store_custom_field(
copy = store_format_custom_field(
format = format,
pattern = "^copy=",
default = store_custom_default_copy()
default = store_format_custom_default_copy()
)
)
}

#' @export
store_class_format.format_custom <- function(format) {
c("tar_store_custom", "tar_nonexportable", "tar_store")
c("tar_store_format_custom", "tar_nonexportable", "tar_store")
}

store_custom_new <- function(
store_format_custom_new <- function(
file = NULL,
resources = NULL,
read = NULL,
Expand All @@ -66,7 +66,7 @@ store_custom_new <- function(
)
}

store_custom_field <- function(format, pattern, default) {
store_format_custom_field <- function(format, pattern, default) {
out <- base64url::base64_urldecode(keyvalue_field(format, pattern))
if ((length(out) < 1L) || !any(nzchar(out))) {
out <- default
Expand All @@ -79,60 +79,60 @@ store_assert_format_setting.format_custom <- function(format) {
}

#' @export
store_read_path.tar_store_custom <- function(store, path) {
store_custom_call_method(
store_read_path.tar_store_format_custom <- function(store, path) {
store_format_custom_call_method(
store = store,
text = store$read,
args = list(path = path)
)
}

#' @export
store_write_path.tar_store_custom <- function(store, object, path) {
store_custom_call_method(
store_write_path.tar_store_format_custom <- function(store, object, path) {
store_format_custom_call_method(
store = store,
text = store$write,
args = list(object = object, path = path)
)
}

#' @export
store_marshal_object.tar_store_custom <- function(store, object) {
store_custom_call_method(
store_marshal_object.tar_store_format_custom <- function(store, object) {
store_format_custom_call_method(
store = store,
text = store$marshal,
args = list(object = object)
)
}

#' @export
store_unmarshal_object.tar_store_custom <- function(store, object) {
store_custom_call_method(
store_unmarshal_object.tar_store_format_custom <- function(store, object) {
store_format_custom_call_method(
store = store,
text = store$unmarshal,
args = list(object = object)
)
}

#' @export
store_convert_object.tar_store_custom <- function(store, object) {
store_custom_call_method(
store_convert_object.tar_store_format_custom <- function(store, object) {
store_format_custom_call_method(
store = store,
text = store$convert,
args = list(object = object)
)
}

#' @export
store_copy_object.tar_store_custom <- function(store, object) {
store_custom_call_method(
store_copy_object.tar_store_format_custom <- function(store, object) {
store_format_custom_call_method(
store = store,
text = store$copy,
args = list(object = object)
)
}

store_custom_call_method <- function(store, text, args) {
store_format_custom_call_method <- function(store, text, args) {
envvars <- store$resources$custom_format$envvars
if (length(envvars)) {
names <- names(envvars)
Expand All @@ -146,8 +146,8 @@ store_custom_call_method <- function(store, text, args) {
}

#' @export
store_validate.tar_store_custom <- function(store) {
tar_assert_correct_fields(store, store_custom_new)
store_validate.tar_store_format_custom <- function(store) {
tar_assert_correct_fields(store, store_format_custom_new)
store_validate_packages(store)
tar_assert_list(store$resources)
for (field in c("read", "write", "marshal", "unmarshal", "convert")) {
Expand All @@ -157,46 +157,46 @@ store_validate.tar_store_custom <- function(store) {
}
}

store_custom_old_repository <- function(format) {
store_format_custom_old_repository <- function(format) {
format <- unlist(strsplit(format, split = "&", fixed = TRUE))
value <- grep("^repository=", format, value = TRUE)
value <- gsub("^repository=", "", value)
value %||% "local"
}

store_custom_default_read <- function() {
store_format_custom_default_read <- function() {
tar_deparse_safe(
function(path) readRDS(path)
)
}

store_custom_default_write <- function() {
store_format_custom_default_write <- function() {
tar_deparse_safe(
function(object, path) {
saveRDS(object = object, file = path, version = 3L)
}
)
}

store_custom_default_marshal <- function() {
store_format_custom_default_marshal <- function() {
tar_deparse_safe(
function(object) object
)
}

store_custom_default_unmarshal <- function() {
store_format_custom_default_unmarshal <- function() {
tar_deparse_safe(
function(object) object
)
}

store_custom_default_convert <- function() {
store_format_custom_default_convert <- function() {
tar_deparse_safe(
function(object) object
)
}

store_custom_default_copy <- function() {
store_format_custom_default_copy <- function() {
tar_deparse_safe(
function(object) object
)
Expand Down
2 changes: 1 addition & 1 deletion R/class_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ target_init <- function(
if (identical(format, "url")) {
repository <- "local"
}
if (store_custom_old_repository(format) == "aws") {
if (store_format_custom_old_repository(format) == "aws") {
repository <- "aws"
}
settings <- settings_init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,36 +215,36 @@ tar_test("class_store_custom equilvalent of fst_dt format", {
expect_equal(tar_read(target_c), "a")
})

tar_test("store_custom_default_read()", {
fun <- eval(parse(text = store_custom_default_read()))
tar_test("store_format_custom_default_read()", {
fun <- eval(parse(text = store_format_custom_default_read()))
tmp <- tempfile()
saveRDS("x", tmp)
expect_equal(fun(tmp), "x")
})

tar_test("store_custom_default_write()", {
fun <- eval(parse(text = store_custom_default_write()))
tar_test("store_format_custom_default_write()", {
fun <- eval(parse(text = store_format_custom_default_write()))
tmp <- tempfile()
fun(object = "x", path = tmp)
expect_equal(readRDS(tmp), "x")
})

tar_test("store_custom_default_marshal()", {
fun <- eval(parse(text = store_custom_default_marshal()))
tar_test("store_format_custom_default_marshal()", {
fun <- eval(parse(text = store_format_custom_default_marshal()))
expect_equal(fun("x"), "x")
})

tar_test("store_custom_default_unmarshal()", {
fun <- eval(parse(text = store_custom_default_unmarshal()))
tar_test("store_format_custom_default_unmarshal()", {
fun <- eval(parse(text = store_format_custom_default_unmarshal()))
expect_equal(fun("x"), "x")
})

tar_test("store_custom_default_convert()", {
fun <- eval(parse(text = store_custom_default_convert()))
tar_test("store_format_custom_default_convert()", {
fun <- eval(parse(text = store_format_custom_default_convert()))
expect_equal(fun("x"), "x")
})

tar_test("store_custom_default_copy()", {
fun <- eval(parse(text = store_custom_default_copy()))
tar_test("store_format_custom_default_copy()", {
fun <- eval(parse(text = store_format_custom_default_copy()))
expect_equal(fun("x"), "x")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-tar_repository_cas.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tar_test("tar_repository_cas() generates a format string", {
tar_test("tar_repository_cas() generates an encoded string", {
out <- tar_repository_cas(
upload = function(path, key) {
file.move(path, file.path("cas", key))
Expand Down

0 comments on commit dea079d

Please sign in to comment.