Skip to content

Commit

Permalink
Use an allow list of packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dfalbel committed Oct 17, 2024
1 parent 07d365e commit 96e9917
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/ark/src/modules/positron/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ ark_methods_table$ark_positron_variable_has_children <- new.env(parent = emptyen
ark_methods_table$ark_positron_variable_kind <- new.env(parent = emptyenv())
lockEnvironment(ark_methods_table, TRUE)

ark_methods_allowed_packages <- c("torch", "reticulate")

#' Register the methods with the Positron runtime
#'
#' @param generic Generic function name as a character to register
#' @param class Class name as a character
#' @param method A method to be registered. Should be a call object.
#' @export
.ark.register_method <- function(generic, class, method) {

# Check if the caller is an allowed package
if (!in_ark_tests()) {
calling_env <- .ps.env_name(topenv(parent.frame()))
if (!(calling_env %in% paste0("namespace:", ark_methods_allowed_packages))) {
stop("Only allowed packages can register methods. Called from ", calling_env)
}
}

stopifnot(
is_string(generic),
generic %in% names(ark_methods_table),
Expand Down

0 comments on commit 96e9917

Please sign in to comment.