Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up cli spinners / installation progress reminders #698

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
)
}

Expand All @@ -42,20 +40,22 @@ 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()

}

}

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()}",
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions R/install_greta_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions R/new_install_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion R/reinstallers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
15 changes: 7 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Expand All @@ -822,20 +821,20 @@ 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"
)
}
# 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"
)
}
Expand Down
Loading