From 818313baf0b24b3a7cda1e402758dada20755308 Mon Sep 17 00:00:00 2001 From: njtierney Date: Fri, 16 Aug 2024 13:46:35 +1000 Subject: [PATCH] I don't think is correctly implemented, might save this for another release --- R/checkers.R | 24 +++++++++++++----------- R/install_greta_deps.R | 2 -- R/new_install_process.R | 15 ++++++++++----- R/reinstallers.R | 7 ++++++- R/utils.R | 15 +++++++-------- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/R/checkers.R b/R/checkers.R index 2bbe5aac..429815cf 100644 --- a/R/checkers.R +++ b/R/checkers.R @@ -4,9 +4,6 @@ #' @importFrom utils compareVersion #' @importFrom reticulate py_available -#' @importFrom cli cli_process_start -#' @importFrom cli cli_process_done -#' @importFrom cli cli_process_failed check_tf_version <- function(alert = c("none", "error", "warn", @@ -26,9 +23,10 @@ check_tf_version <- function(alert = c("none", if (!greta_stash$python_has_been_initialised) { - cli_process_start( + cli::cli_progress_step( msg = "Initialising python and checking dependencies, this may take a \\ - moment." + moment.", + spinner = TRUE ) } @@ -42,10 +40,12 @@ check_tf_version <- function(alert = c("none", if (!greta_stash$python_has_been_initialised) { - cli_process_done( - msg_done = "Initialising python and checking dependencies ... done!") - cat("\n") + cli::cli_progress_update() greta_stash$python_has_been_initialised <- TRUE + cli::cli_progress_step( + msg_done = "Done intialising python and checking dependencies!" + ) + cli::cli_progress_done() } @@ -53,9 +53,9 @@ check_tf_version <- function(alert = c("none", if (!all(requirements_valid)) { - cli_process_failed() - - cli_msg <- c( + cli::cli_progress_update() + cli::cli_progress_step( + msg_failed = c( "x" = "The expected python packages are not available", "i" = "We recommend installing them (in a fresh R session) with:", "{.code install_greta_deps()}", @@ -64,7 +64,9 @@ check_tf_version <- function(alert = c("none", "({.strong Note}: Your R session should not have initialised \\ Tensorflow yet.)", "i" = "For more information, see {.code ?install_greta_deps}" + ), ) + cli::cli_progress_done() # if there was a problem, append the solution message_text <- cli::format_message(cli_msg) diff --git a/R/install_greta_deps.R b/R/install_greta_deps.R index fa4e1c5a..c8c04d17 100644 --- a/R/install_greta_deps.R +++ b/R/install_greta_deps.R @@ -61,8 +61,6 @@ #' @importFrom reticulate conda_create #' @importFrom reticulate conda_install #' @importFrom cli cli_alert_info -#' @importFrom cli cli_process_start -#' @importFrom cli cli_process_done #' @importFrom cli cli_ul #' @importFrom callr r_process_options #' @importFrom callr r_process diff --git a/R/new_install_process.R b/R/new_install_process.R index 278d3622..eaeb57eb 100644 --- a/R/new_install_process.R +++ b/R/new_install_process.R @@ -4,11 +4,14 @@ new_install_process <- function(callr_process, stderr_file = NULL, cli_start_msg = NULL, cli_end_msg = NULL){ - cli::cli_process_start(cli_start_msg) + cli::cli_progress_step(msg = cli_start_msg, + spinner = TRUE) # convert max timeout from milliseconds into minutes timeout_minutes <- timeout * 1000 * 60 r_callr_process <- callr::r_process$new(callr_process) + cli::cli_progress_update() r_callr_process$wait(timeout = timeout_minutes) + cli::cli_progress_update() status <- r_callr_process$get_exit_status() output_notes <- read_char(stdout_file) @@ -18,20 +21,22 @@ new_install_process <- function(callr_process, output_error <- output_error %||% "No output detected in stderr" if (is.null(status)) { - cli::cli_process_failed() + cli::cli_progress_step(msg_failed = "Installation timed out") msg_timeout <- timeout_install_msg(timeout, output_error) cli::cli_abort( - msg_timeout + message = msg_timeout ) } else if (no_output) { - cli::cli_process_failed() + cli::cli_progress_step(msg_failed = "Installation failed") msg_other <- other_install_fail_msg(output_error) cli::cli_abort( msg_other ) } - cli_process_done(msg_done = cli_end_msg) + cli::cli_progress_update() + cli::cli_progress_step(msg_done = cli_end_msg) + cli::cli_progress_done() return( list(output_notes = output_notes, diff --git a/R/reinstallers.R b/R/reinstallers.R index 100395f0..ea45c872 100644 --- a/R/reinstallers.R +++ b/R/reinstallers.R @@ -99,8 +99,13 @@ reinstall_greta_deps <- function(python_deps = greta_python_deps(), destroy_greta_deps <- function(){ cli::cli_progress_step( msg = "You are removing greta env and miniconda", - msg_done = c("You have successfully removed greta env and miniconda") + spinner = TRUE ) + cli::cli_progress_update() remove_greta_env() + cli::cli_progress_update() + cli::cli_progress_step(msg_done = "You have successfully removed greta env") remove_miniconda() + cli::cli_progress_update() + cli::cli_progress_step(msg_done = "You have successfully removed miniconda") } diff --git a/R/utils.R b/R/utils.R index 0c10987a..3c353b61 100644 --- a/R/utils.R +++ b/R/utils.R @@ -798,19 +798,18 @@ check_if_software_available <- function(software_available, ideal_version = NULL, software_name){ - cli::cli_process_start("checking if {.pkg {software_name}} available") + cli::cli_progress_step(msg = "checking if {.pkg {software_name}} available", + spinner = TRUE) # if the software is detected if (!software_available) { - cli::cli_process_failed( - msg_failed = "{.pkg {software_name}} not available" - ) + cli::cli_progress_step(msg_failed = "{.pkg {software_name}} not available") } if (software_available) { if (is.null(ideal_version) & !is.null(version)){ - cli::cli_process_done( + cli::cli_progress_step( msg_done = "{.pkg {software_name}} (v{version}) available" ) } @@ -822,12 +821,12 @@ check_if_software_available <- function(software_available, version_match <- compareVersion(version_chr, ideal_version) == 0 if (version_match){ - cli::cli_process_done( + cli::cli_progress_step( msg_done = "{.pkg {software_name}} (v{version}) available" ) } if (!version_match){ - cli::cli_process_failed( + cli::cli_progress_step( msg_failed = "{.pkg {software_name}} available, \\ however {.strong {ideal_version}} is needed and \\ {.strong {version}} was detected" @@ -835,7 +834,7 @@ check_if_software_available <- function(software_available, } # if there is no version for the software } else if (is.null(version)){ - cli::cli_process_done( + cli::cli_progress_step( msg_done = "{.pkg {software_name}} available" ) }