Skip to content

Commit 60e241f

Browse files
authored
Merge pull request #683 from njtierney/collate-install-logs-493
Combine log files into a single file
2 parents ec5f67f + 855e8e6 commit 60e241f

29 files changed

+361
-173
lines changed

.github/workflows/R-CMD-check.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ jobs:
8181
run: remotes::install_local(dependencies = TRUE, force = TRUE)
8282

8383
- name: Install greta deps
84-
run: greta::install_greta_deps(timeout = 50)
84+
run: |
85+
library(greta)
86+
greta::install_greta_deps(timeout = 50)
8587
8688
- name: Situation Report on greta install
8789
run: greta::greta_sitrep()

DESCRIPTION

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Imports:
4646
reticulate (>= 1.19.0),
4747
rlang,
4848
tensorflow (>= 2.8.0),
49+
whisker,
4950
yesno
5051
Suggests:
5152
bayesplot,
@@ -130,6 +131,7 @@ Collate:
130131
'checkers.R'
131132
'test_if_forked_cluster.R'
132133
'testthat-helpers.R'
134+
'write-logfiles.R'
133135
'zzz.R'
134136
'internals.R'
135137
LazyData: true

NAMESPACE

+3-6
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export(colMeans)
181181
export(colSums)
182182
export(cov2cor)
183183
export(cpu_only)
184+
export(destroy_greta_deps)
184185
export(diag)
185186
export(dirichlet)
186187
export(dirichlet_multinomial)
@@ -196,14 +197,9 @@ export(gpu_only)
196197
export(gradient_descent)
197198
export(greta_array)
198199
export(greta_deps_receipt)
199-
export(greta_notes_conda_create_error)
200-
export(greta_notes_conda_create_output)
201-
export(greta_notes_conda_install_error)
202-
export(greta_notes_conda_install_output)
203-
export(greta_notes_install_miniconda_error)
204-
export(greta_notes_install_miniconda_output)
205200
export(greta_notes_tf_num_error)
206201
export(greta_python_deps)
202+
export(greta_set_install_logfile)
207203
export(greta_sitrep)
208204
export(hmc)
209205
export(hypergeometric)
@@ -268,6 +264,7 @@ export(uniform)
268264
export(variable)
269265
export(weibull)
270266
export(wishart)
267+
export(write_greta_install_log)
271268
export(zeros)
272269
import(methods)
273270
importFrom(R6,R6Class)

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ This release provides a few improvements to installation in greta. It should now
4141
* Added `greta_deps_receipt()` to list the current main python packages installed. (#668)
4242
* Added checking suite to ensure you are using valid versions of TF, TFP, and Python(#666)
4343
* Added data `greta_deps_tf_tfp` (#666), which contains valid versions combinations of TF, TFP, and Python.
44+
* remove `greta_nodes_install/conda_*()` options as #493 makes them defunct.
45+
* Added option to write to a single logfile with `greta_set_install_logfile()`, and `write_greta_install_log()`. (#493)
46+
* Added `destroy_greta_deps()` function to remove miniconda and python conda environment
4447

4548
## Minor
4649

R/checkers.R

+8-9
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ check_tf_version <- function(alert = c("none",
5656
cli_process_failed()
5757

5858
cli_msg <- c(
59-
"We have detected that you do not have the expected python packages \\
60-
setup.",
61-
"You can set these up by running this R code in the console:",
59+
"x" = "The expected python packages are not available",
60+
"i" = "We recommend installing them (in a fresh R session) with:",
6261
"{.code install_greta_deps()}",
63-
"Then, restart R and run:",
64-
"{.code library(greta)}",
62+
"or",
63+
"{.code reinstall_greta_deps()}",
6564
"({.strong Note}: Your R session should not have initialised \\
6665
Tensorflow yet.)",
67-
"For more information, see {.code ?install_greta_deps}"
66+
"i" = "For more information, see {.code ?install_greta_deps}"
6867
)
6968

7069
# if there was a problem, append the solution
@@ -74,9 +73,9 @@ check_tf_version <- function(alert = c("none",
7473

7574
switch(
7675
alert,
77-
error = stop(error_text, call. = FALSE),
78-
warn = warning(warning_text, call. = FALSE),
79-
message = message(message_text),
76+
error = rlang::abort(error_text),
77+
warn = rlang::warn(warning_text),
78+
message = rlang::inform(message_text),
8079
startup = packageStartupMessage(message_text),
8180
none = NULL
8281
)

R/data-deps-tf-tfp.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#' Suggested TF, TFP, and Python dependencies
1+
#' Suggested valid Python dependencies for greta
22
#'
33
#' This is a dataset that contains suggested valid versions of Tensorflow (TF),
44
#' Tensorflow Probability (TFP), and Python for linux, mac, and windows
55
#' machines. It was constructed from
6-
#' <https://www.tensorflow.org/install/source>,
6+
#' <https://www.tensorflow.org/install/source> and
77
#' <https://www.tensorflow.org/install/source_windows>, and by inspecting
88
#' <https://github.com/tensorflow/probability/releases>.
99
#'

R/greta_create_conda_env.R

-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,4 @@ greta_create_conda_env <- function(timeout = 5,
3131
greta_stash$conda_create_notes <- install_conda_create$output_notes
3232
greta_stash$conda_create_error <- install_conda_create$output_error
3333

34-
cli::cli_ul("To see full installation notes run:")
35-
cli::cli_ul("{.code greta_notes_conda_create_output()}")
36-
cli::cli_ul("To see any error messages, run:")
37-
cli::cli_ul("{.code greta_notes_conda_create_error()}")
38-
3934
}

R/greta_install_miniconda.R

-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,4 @@ greta_install_miniconda <- function(timeout = 5) {
2525
greta_stash$miniconda_notes <- install_miniconda_process$output_notes
2626
greta_stash$miniconda_error <- install_miniconda_process$output_error
2727

28-
cli::cli_ul("To see full installation notes run:")
29-
cli::cli_ul("{.code greta_notes_install_miniconda_output()}")
30-
cli::cli_ul("To see any error messages, run:")
31-
cli::cli_ul("{.code greta_notes_install_miniconda_error()}")
3228
}

R/greta_install_python_deps.R

-5
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,4 @@ greta_install_python_deps <- function(timeout = 5,
4949
greta_stash$conda_install_notes <- install_python_modules$output_notes
5050
greta_stash$conda_install_error <- install_python_modules$output_error
5151

52-
cli::cli_ul("To see full installation notes run:")
53-
cli::cli_ul("{.code greta_notes_conda_install_output()}")
54-
cli::cli_ul("To see any error messages, run:")
55-
cli::cli_ul("{.code greta_notes_conda_install_error()}")
56-
5752
}

R/greta_stash.R

+9-45
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,32 @@
11
greta_note_msg <- cli::format_message(
22
c(
33
"If you are reading this, the {.pkg greta} installation or error notes \\
4-
have been wiped."
4+
have been wiped. This likely means that installation has not happened, or \\
5+
it has happened and you've restarted R. See `?install_greta_deps()` for \\
6+
more information."
57
)
68
)
79

810
greta_stash$install_miniconda_notes <- greta_note_msg
11+
greta_stash$install_miniconda_error <- greta_note_msg
912
greta_stash$conda_create_notes <- greta_note_msg
13+
greta_stash$conda_create_error <- greta_note_msg
1014
greta_stash$conda_install_notes <- greta_note_msg
15+
greta_stash$conda_install_error <- greta_note_msg
1116
greta_stash$tf_num_error <- greta_note_msg
1217

13-
#' @title Retrieve python installation or error details.
18+
#' @title Retrieve python messages.
1419
#'
1520
#' @description
16-
#' These functions retrieve installation or error information output by python
17-
#' when running `install_miniconda()`, `conda_create()`, `conda_install()`, or
18-
#' when encountering a TensorFlow numerical problem.
21+
#' These functions retrieve specific python error messages that might
22+
#' come up during greta use.
1923
#'
2024
#' @rdname stash-notes
2125
#' @export
2226
#' @examples
2327
#' \dontrun{
24-
#' greta_notes_install_miniconda()
25-
#' greta_notes_conda_create()
26-
#' greta_notes_conda_install()
27-
#' greta_notes_tf_num_error()
2828
#' greta_notes_tf_error()
2929
#' }
30-
greta_notes_install_miniconda_output <- function() {
31-
cat(greta_stash$miniconda_notes)
32-
}
33-
34-
#' @name stash-notes
35-
#' @export
36-
greta_notes_install_miniconda_error <- function(){
37-
cat(greta_stash$miniconda_error)
38-
}
39-
40-
#' @name stash-notes
41-
#' @export
42-
greta_notes_conda_create_output <- function() {
43-
cat(greta_stash$conda_create_notes)
44-
}
45-
46-
#' @name stash-notes
47-
#' @export
48-
greta_notes_conda_create_error <- function() {
49-
cat(greta_stash$conda_create_error)
50-
}
51-
52-
#' @name stash-notes
53-
#' @export
54-
greta_notes_conda_install_output <- function() {
55-
cat(greta_stash$conda_install_notes)
56-
}
57-
58-
#' @name stash-notes
59-
#' @export
60-
greta_notes_conda_install_error <- function() {
61-
cat(greta_stash$conda_install_error)
62-
}
63-
64-
#' @name stash-notes
65-
#' @export
6630
greta_notes_tf_num_error <- function() {
6731
cat(greta_stash$tf_num_error)
6832
}

R/install_greta_deps.R

+63-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
#' Install Python dependencies for greta
22
#'
3-
#' This is a helper function to install Python dependencies needed. This
4-
#' includes the latest version of Tensorflow version (2.13.0 or higher),
5-
#' Tensorflow Probability 0.21.0 (or higher), and the latest version of
6-
#' numpy (1.21.0 or higher). These Python modules will be installed into a
7-
#' virtual or conda environment, named "greta-env-tf2". Note that "virtualenv"
8-
#' is not available on Windows.
3+
#' This is a helper function to install Python dependencies needed. By default
4+
#' these are TF 2.15.0, TFP 0.23.0, and Python 3.10. These Python modules
5+
#' will be installed into a conda environment named "greta-env-tf2".
96
#'
10-
#' @param python_deps object created with `greta_python_deps()` where you
11-
#' specify python, TF, and TFP versions.
7+
#' To see install notes or errors, there isn't an argument to specify,
8+
#' instead you will need to specify and environment variable,
9+
#' `GRETA_INSTALLATION_LOG`, with
10+
#' `Sys.setenv('GRETA_INSTALLATION_LOG'='path/to/logfile.html')`. Or use
11+
#' [greta_set_install_logfile()] to set the path, e.g.,
12+
#' `greta_set_install_logfile('path/to/logfile.html')`. You can also skip
13+
#' the restarting of R and use [write_greta_install_log()], which
14+
#' installation notes will indicate how to use if you haven't specified.
15+
#'
16+
#' @param python_deps object created with [greta_python_deps()] where you
17+
#' specify python, TF, and TFP versions. By default these are TF 2.15.0,
18+
#' TFP 0.23.0, and Python 3.10. These versions must be compatible
19+
#' with each other. If they are not, [greta_python_deps()] will error with
20+
#' more information and suggestions. See ?[greta_python_deps()] for more
21+
#' information, and see the data object `greta_deps_tf_tfp`
22+
#' (`?greta_deps_tf_tfp``).
1223
#'
1324
#' @param timeout maximum time in minutes until the installation for each
1425
#' installation component times out and exits. Default is 5 minutes per
@@ -84,12 +95,46 @@ install_greta_deps <- function(python_deps = greta_python_deps(),
8495
)
8596
}
8697

98+
# TODO
99+
# Issue warning if you already have conda env +/ miniconda
100+
# suggest using `reinstall_greta_deps()`
87101
greta_install_python_deps(
88102
timeout = timeout,
89103
python_deps = python_deps
90104
)
91105

92-
cli_alert_success("Installation of {.pkg greta} dependencies is complete!")
106+
# TODO
107+
# Detect if you have tried to install greta multiple times in the same
108+
# session, and suggest that perhaps they want to use
109+
# `reinstall_greta_deps()`
110+
# perhaps even stopping the session with a "yesno"
111+
112+
greta_logfile <- Sys.getenv("GRETA_INSTALLATION_LOG")
113+
114+
logfile_exists <- nzchar(greta_logfile)
115+
116+
no_logfile <- !logfile_exists
117+
118+
119+
if (logfile_exists) {
120+
write_greta_install_log(path = greta_logfile)
121+
}
122+
123+
if (no_logfile) {
124+
cli::cli_alert_warning(
125+
text = c(
126+
"No logfile specified. If you want to save the logfile to see any \\
127+
install notes, or potential errors, you will need to \\
128+
{.strong not restart R}, then run:\n\n",
129+
"{.run write_greta_install_log('greta-logfile.html')}"
130+
),
131+
wrap = TRUE
132+
)
133+
}
134+
135+
cli::cli_alert_success("Installation of {.pkg greta} dependencies \\
136+
is complete!",
137+
wrap = TRUE)
93138

94139
restart_or_not(restart)
95140

@@ -160,7 +205,7 @@ restart_or_not <- function(restart){
160205
#'
161206
#' @param tf_version Character. Tensorflow (TF) version in format major.minor.patch. Default is "2.15.0".
162207
#' @param tfp_version Character.Tensorflow probability (TFP) version major.minor.patch. Default is "0.23.0".
163-
#' @param python_version Character. Ptyhon version in format major.minor.patch. Default is "3.10".
208+
#' @param python_version Character. Python version in format major.minor.patch. Default is "3.10".
164209
#'
165210
#' @return list of dependencies
166211
#' @export
@@ -182,10 +227,10 @@ greta_python_deps <- function(tf_version = "2.15.0",
182227
class = c("greta_python_deps", "data.frame")
183228
)
184229

230+
# check for envvar to silence these checks
185231
check_tfp_tf_semantic(deps_obj)
186232
check_greta_tf_range(deps_obj)
187233
check_greta_tfp_range(deps_obj)
188-
189234
check_greta_python_range(deps_obj$python_version)
190235
check_greta_deps_config(deps_obj)
191236

@@ -259,7 +304,8 @@ check_greta_deps_range <- function(python_deps,
259304
{version_name} > {.val {latest_version}}",
260305
"i" = "See {.url {gh_issue}} for more information",
261306
"x" = "The provided version was {.val {version_provided}}",
262-
"i" = "The closest value is: {.val {latest_version}}",
307+
"i" = "The nearest valid version that is supported by \\
308+
{.pkg greta} is: {.val {latest_version}}",
263309
"i" = "Valid versions of TF, TFP, and Python are in \\
264310
{.code greta_deps_tf_tfp}",
265311
"i" = "Inspect with:",
@@ -280,7 +326,8 @@ check_greta_deps_range <- function(python_deps,
280326
supported versions",
281327
"The version {.val {version_provided}} was not in \\
282328
{.val {greta_deps_tf_tfp[[deps]]}}",
283-
"The closest value is: {.val {closest_value}}",
329+
"i" = "The nearest valid version that is supported by \\
330+
{.pkg greta} is: {.val {closest_value}}",
284331
"i" = "Valid versions of TF, TFP, and Python are in \\
285332
{.code greta_deps_tf_tfp}",
286333
"i" = "Inspect with:",
@@ -332,7 +379,6 @@ check_greta_python_range <- function(version_provided,
332379
check_greta_deps_config <- function(python_deps,
333380
call = rlang::caller_env()){
334381

335-
# check for envvar to silence these checks
336382
check_greta_python_deps(python_deps)
337383

338384
python_deps <- python_deps |>
@@ -415,9 +461,9 @@ check_greta_deps_config <- function(python_deps,
415461
"suggest_py" = py_matches
416462
)
417463

418-
suggested_tfp <- as.character(suggested_match$tfp_version)
419-
suggested_tf <- as.character(suggested_match$tf_version)
420-
suggested_py <- as.character(suggested_match$python_version_max)
464+
suggested_tfp <- as.character(max(suggested_match$tfp_version))
465+
suggested_tf <- as.character(max(suggested_match$tf_version))
466+
suggested_py <- as.character(max(suggested_match$python_version_max))
421467

422468
cli::cli_abort(
423469
message = c("Provided {.code greta_python_deps} does not match valid \\

R/package.R

+11-2
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,14 @@
3737

3838
# clear CRAN checks spotting floating global variables
3939
#' @importFrom utils globalVariables
40-
utils::globalVariables(c("N"), "greta")
41-
40+
utils::globalVariables(
41+
c("N",
42+
"greta_deps_tf_tfp",
43+
"greta_logfile",
44+
"os",
45+
"python_version_max",
46+
"python_version_min",
47+
"tf_version",
48+
"tfp_version",
49+
"greta")
50+
)

0 commit comments

Comments
 (0)