1
1
# ' Install Python dependencies for greta
2
2
# '
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".
9
6
# '
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``).
12
23
# '
13
24
# ' @param timeout maximum time in minutes until the installation for each
14
25
# ' installation component times out and exits. Default is 5 minutes per
@@ -84,12 +95,46 @@ install_greta_deps <- function(python_deps = greta_python_deps(),
84
95
)
85
96
}
86
97
98
+ # TODO
99
+ # Issue warning if you already have conda env +/ miniconda
100
+ # suggest using `reinstall_greta_deps()`
87
101
greta_install_python_deps(
88
102
timeout = timeout ,
89
103
python_deps = python_deps
90
104
)
91
105
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 )
93
138
94
139
restart_or_not(restart )
95
140
@@ -160,7 +205,7 @@ restart_or_not <- function(restart){
160
205
# '
161
206
# ' @param tf_version Character. Tensorflow (TF) version in format major.minor.patch. Default is "2.15.0".
162
207
# ' @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".
164
209
# '
165
210
# ' @return list of dependencies
166
211
# ' @export
@@ -182,10 +227,10 @@ greta_python_deps <- function(tf_version = "2.15.0",
182
227
class = c(" greta_python_deps" , " data.frame" )
183
228
)
184
229
230
+ # check for envvar to silence these checks
185
231
check_tfp_tf_semantic(deps_obj )
186
232
check_greta_tf_range(deps_obj )
187
233
check_greta_tfp_range(deps_obj )
188
-
189
234
check_greta_python_range(deps_obj $ python_version )
190
235
check_greta_deps_config(deps_obj )
191
236
@@ -259,7 +304,8 @@ check_greta_deps_range <- function(python_deps,
259
304
{version_name} > {.val {latest_version}}" ,
260
305
" i" = " See {.url {gh_issue}} for more information" ,
261
306
" 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}}" ,
263
309
" i" = " Valid versions of TF, TFP, and Python are in \\
264
310
{.code greta_deps_tf_tfp}" ,
265
311
" i" = " Inspect with:" ,
@@ -280,7 +326,8 @@ check_greta_deps_range <- function(python_deps,
280
326
supported versions" ,
281
327
" The version {.val {version_provided}} was not in \\
282
328
{.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}}" ,
284
331
" i" = " Valid versions of TF, TFP, and Python are in \\
285
332
{.code greta_deps_tf_tfp}" ,
286
333
" i" = " Inspect with:" ,
@@ -332,7 +379,6 @@ check_greta_python_range <- function(version_provided,
332
379
check_greta_deps_config <- function (python_deps ,
333
380
call = rlang :: caller_env()){
334
381
335
- # check for envvar to silence these checks
336
382
check_greta_python_deps(python_deps )
337
383
338
384
python_deps <- python_deps | >
@@ -415,9 +461,9 @@ check_greta_deps_config <- function(python_deps,
415
461
" suggest_py" = py_matches
416
462
)
417
463
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 ) )
421
467
422
468
cli :: cli_abort(
423
469
message = c(" Provided {.code greta_python_deps} does not match valid \\
0 commit comments