@@ -3,26 +3,28 @@ local({
3
3
# for some reason this also has implications for symlinking into the global cache
4
4
Sys.setenv(RENV_PATHS_LIBRARY = " renv/library" )
5
5
6
- # remind's renv integration previously relied on renv.lock, but now it should generally not be used anymore
7
- # this can safely be removed in January 2024
8
- if (file.exists(" renv.lock" ) && file.exists(" README.md" ) && ! file.exists(" renv/old_renv.lock" )) {
9
- file.rename(" renv.lock" , " renv/old_renv.lock" )
10
- message(" moved legacy renv.lock to renv/old_renv.lock" )
11
- }
12
-
13
6
# do not check if library and renv.lock are in sync, because normally renv.lock does not exist
14
7
options(renv.config.synchronized.check = FALSE )
15
8
16
- source(" renv/activate.R" )
9
+ # always set the renv project to the current directory
10
+ Sys.setenv(" RENV_PROJECT" = getwd())
17
11
18
12
# when increasing renvVersion first commit new version's activate script and
19
- # put that commit's hash into the download.file call below
13
+ # put that commit's hash into the git checkout call below
20
14
renvVersion <- " 1.0.7"
15
+
16
+ # reset renv/activate.R to match renv 1.0.7
17
+ gitRoot <- system2(" git" , c(" rev-parse" , " --show-toplevel" ), stdout = TRUE )
18
+ if (Sys.getenv(" RESET_RENV_ACTIVATE_SCRIPT" , unset = " TRUE" ) == " TRUE" &&
19
+ normalizePath(gitRoot ) == normalizePath(" ." )) {
20
+ system2(" git" , c(" checkout" , " b83bb1811ff08d8ee5ba8e834af5dd0080d10e66" , " --" , " renv/activate.R" ))
21
+ }
22
+
23
+ source(" renv/activate.R" )
24
+
21
25
if (packageVersion(" renv" ) != renvVersion ) {
22
26
renvLockExisted <- file.exists(renv :: paths $ lockfile())
23
27
renv :: install(paste0(" renv@" , renvVersion ))
24
- message(" Downloading 'renv/activate.R' of renv version 1.0.7" )
25
- download.file(" https://raw.githubusercontent.com/remindmodel/remind/b83bb1811ff08d8ee5ba8e834af5dd0080d10e66/renv/activate.R" , " renv/activate.R" )
26
28
if (! renvLockExisted ) {
27
29
unlink(renv :: paths $ lockfile())
28
30
}
@@ -36,30 +38,10 @@ if (!"https://rse.pik-potsdam.de/r/packages" %in% getOption("repos")) {
36
38
if (isTRUE(rownames(installed.packages(priority = " NA" )) == " renv" )) {
37
39
message(" R package dependencies are not installed in this renv, installing now..." )
38
40
renv :: install(" rmarkdown" , prompt = FALSE ) # rmarkdown is required to find dependencies in Rmd files
39
- renv :: hydrate() # auto-detect and install all dependencies
41
+ renv :: hydrate(prompt = FALSE , report = FALSE ) # auto-detect and install all dependencies
40
42
message(" Finished installing R package dependencies." )
41
43
}
42
44
43
- # bootstrapping python venv, will only run once after remind is freshly cloned
44
- if (! dir.exists(" .venv/" )
45
- && (Sys.which(" python3" ) != " "
46
- || (Sys.which(" python.exe" ) != " "
47
- && suppressWarnings(isTRUE(startsWith(system2(" python.exe" , " --version" , stdout = TRUE ), " Python 3" )))
48
- ))) {
49
- message(" Python venv is not available, setting up now..." )
50
- # use system python to set up venv
51
- if (.Platform $ OS.type == " windows" ) {
52
- system2(" python.exe" , c(" -mvenv" , " .venv" ))
53
- pythonInVenv <- normalizePath(file.path(" .venv" , " Scripts" , " python.exe" ), mustWork = TRUE )
54
- } else {
55
- system2(" python3" , c(" -mvenv" , " .venv" ))
56
- pythonInVenv <- normalizePath(file.path(" .venv" , " bin" , " python" ), mustWork = TRUE )
57
- }
58
- # use venv python to install dependencies in venv
59
- system2(pythonInVenv , c(" -mpip" , " install" , " --upgrade" , " pip" , " wheel" ))
60
- system2(pythonInVenv , c(" -mpip" , " install" , " -r" , " requirements.txt" ))
61
- }
62
-
63
45
# Configure locations of REMIND input data
64
46
# These can be located in directories on the local machine, remote directories,
65
47
# or default directories on the cluster.
@@ -74,51 +56,12 @@ if (!dir.exists(".venv/")
74
56
# REMIND_repos_dirs="C:\my\first\path;D:\my\second\path"
75
57
remindReposDirs <- Sys.getenv(" REMIND_repos_dirs" )
76
58
77
- # for scp targets, you need to set three environment variables
78
- # on linux e.g. (separate multiple paths by semicolons)
79
- # REMIND_repos_scp="scp://cluster.pik-potsdam.de/p/projects/rd3mod/inputdata/output;scp://cluster.pik-potsdam.de/p/projects/remind/inputdata/CESparametersAndGDX"
80
- # REMIND_repos_scp_user="myusername" # use your user name on the scp target, e.g. the cluster
81
- # REMIND_repos_scp_key="/home/myusername/.ssh/id_ed25519" # path to your your ssh private key on your laptop
82
- # on windows e.g.
83
- # REMIND_repos_scp="scp://cluster.pik-potsdam.de/p/projects/rd3mod/inputdata/output;scp://cluster.pik-potsdam.de/p/projects/remind/inputdata/CESparametersAndGDX"
84
- # REMIND_repos_scp_user="myusername" # use your user name on the scp target, e.g. the cluster
85
- # REMIND_repos_scp_key="C:\Users\myusername\.ssh\id_ed25519" # path to your your ssh private key on your laptop
86
- remindReposSCP <- Sys.getenv(" REMIND_repos_scp" ) # scp URL
87
- remindReposSCPUser <- Sys.getenv(" REMIND_repos_scp_user" ) # ssh user name
88
- remindReposSCPKey <- Sys.getenv(" REMIND_repos_scp_key" ) # ssh key path
89
-
90
- # unless specified otherwise, use cluster defaults
91
- use_cluster_defaults <- TRUE
92
-
93
59
# add local directories, if any
94
60
if (" " != remindReposDirs ) {
95
- directories <- unlist(strsplit(remindReposDirs , .Platform $ path.sep ,
96
- fixed = TRUE ))
61
+ directories <- unlist(strsplit(remindReposDirs , .Platform $ path.sep , fixed = TRUE ))
97
62
directoriesList <- rep(list (NULL ), length(directories ))
98
63
names(directoriesList ) <- directories
99
-
100
64
options(remind_repos = c(options(" remind_repos" )[[1 ]], directoriesList ))
101
- use_cluster_defaults <- FALSE
102
- }
103
-
104
- # add remote directories, if any remote directory and username and SSH key are set
105
- if (" " != remindReposSCP && " " != remindReposSCPUser && " " != remindReposSCPKey ) {
106
- SCPUrls <- unlist(strsplit(remindReposSCP , " ;" , fixed = TRUE ))
107
- config <- list (list (username = remindReposSCPUser , ssh_private_keyfile = remindReposSCPKey ))
108
- for (SCPUrl in SCPUrls ) {
109
- names(config ) <- SCPUrl
110
- options(remind_repos = c(options(" remind_repos" )[[1 ]], config ))
111
- }
112
- use_cluster_defaults <- FALSE
113
- }
114
-
115
- # default to cluster directories
116
- if (use_cluster_defaults &&
117
- all(file.exists(c(" /p/projects/rd3mod/inputdata/output" ,
118
- " /p/projects/remind/inputdata/CESparametersAndGDX" )))) {
119
- options(remind_repos = list (
120
- " /p/projects/rd3mod/inputdata/output" = NULL ,
121
- " /p/projects/remind/inputdata/CESparametersAndGDX" = NULL ))
122
65
}
123
66
124
67
# Include local calibration results, if they exist, from either the main
0 commit comments