Skip to content

Commit 1461e67

Browse files
REVDEP: modernize [ci skip]
1 parent e9f41ec commit 1461e67

File tree

2 files changed

+80
-31
lines changed

2 files changed

+80
-31
lines changed

revdep/run.R

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env Rscript
2+
if (!requireNamespace("revdepcheck")) {
3+
stop('Install revdepcheck: remotes::install_github("r-lib/revdepcheck")')
4+
}
25
library("revdepcheck")
36
options(warn = 1L)
47

@@ -96,38 +99,69 @@ revdep_children <- local({
9699
}
97100
})
98101

99-
revdep_pkgs_with_status <- function(status = "error") {
102+
revdep_pkgs_with_status <- function(status = c("error", "failure")) {
100103
status <- match.arg(status)
101104
res <- revdepcheck::revdep_summary()
102-
field <- switch(status, error = "errors")
103-
has_status <- vapply(res, FUN = function(x) {
104-
z <- x[["new"]][[field]]
105-
is.character(z) && any(nchar(z) > 0)
106-
}, FUN.VALUE = NA, USE.NAMES = TRUE)
107-
has_status <- !is.na(has_status) & has_status
108-
names(has_status)[has_status]
105+
if (status == "failure") {
106+
names(which(sapply(res, FUN = .subset2, "status") == "E"))
107+
} else if (status == "error") {
108+
field <- switch(status, error = "errors")
109+
has_status <- vapply(res, FUN = function(x) {
110+
z <- x[["new"]][[field]]
111+
is.character(z) && any(nchar(z) > 0)
112+
}, FUN.VALUE = NA, USE.NAMES = TRUE)
113+
has_status <- !is.na(has_status) & has_status
114+
names(has_status)[has_status]
115+
}
109116
}
110117

111-
revdep_preinstall <- function(pkgs) {
112-
pkgs <- unique(pkgs)
113-
lib_paths_org <- lib_paths <- .libPaths()
114-
on.exit(.libPaths(lib_paths_org))
118+
revdep_preinstall_libs <- function() {
119+
lib_paths <- .libPaths()
115120
lib_paths[1] <- sprintf("%s-revdepcheck", lib_paths[1])
116121
dir.create(lib_paths[1], recursive = TRUE, showWarnings = FALSE)
117-
.libPaths(lib_paths)
122+
lib_paths
123+
}
124+
125+
revdep_preinstall <- function(pkgs) {
126+
oopts <- options(Ncpus = available_cores())
127+
lib_paths_org <- .libPaths()
128+
on.exit({
129+
.libPaths(lib_paths_org)
130+
options(oopts)
131+
})
132+
.libPaths(revdep_preinstall_libs())
133+
134+
pkgs <- unique(pkgs)
118135
message(sprintf("Triggering crancache builds by pre-installing %d packages: %s", length(pkgs), paste(sQuote(pkgs), collapse = ", ")))
119136
message(".libPaths():")
120137
message(paste(paste0(" - ", .libPaths()), collapse = "\n"))
121138
## Install one-by-one to update cache sooner
122139
for (kk in seq_along(pkgs)) {
123140
pkg <- pkgs[kk]
124-
message(sprintf("Pre-installing package %d of %d: %s",
125-
kk, length(pkgs), pkg))
126-
crancache::install_packages(pkg)
141+
message(sprintf("Pre-installing package %d of %d: %s (Ncpus = %d)",
142+
kk, length(pkgs), pkg, getOption("Ncpus", 1L)))
143+
crancache::install_packages(pkg, dependencies = c("Depends", "Imports", "LinkingTo", "Suggests"))
127144
}
128145
}
129146

130-
args <- base::commandArgs()
147+
revdep_preinstall_update <- function() {
148+
oopts <- options(Ncpus = available_cores())
149+
lib_paths_org <- .libPaths()
150+
on.exit({
151+
.libPaths(lib_paths_org)
152+
options(oopts)
153+
})
154+
.libPaths(revdep_preinstall_libs())
155+
156+
message("Update crancache for all pre-installing packages:")
157+
message(".libPaths():")
158+
message(paste(paste0(" - ", .libPaths()), collapse = "\n"))
159+
message(sprintf("Ncpus=%d", getOption("Ncpus", 1L)))
160+
crancache::update_packages(ask = FALSE)
161+
}
162+
163+
164+
args <- base::commandArgs(trailingOnly = TRUE)
131165
if ("--reset" %in% args) {
132166
revdep_reset()
133167
} else if ("--todo-reset" %in% args) {
@@ -137,17 +171,25 @@ if ("--reset" %in% args) {
137171
todo()
138172
} else if ("--add" %in% args) {
139173
pos <- which("--add" == args)
174+
if (pos == length(args)) stop("Missing value for option '--add'")
140175
pkgs <- parse_pkgs(args[seq(from = pos + 1L, to = length(args))])
141176
revdep_add(packages = pkgs)
142177
todo()
143178
} else if ("--rm" %in% args) {
144179
pos <- which("--rm" == args)
180+
if (pos == length(args)) stop("Missing value for option '--rm'")
145181
pkgs <- parse_pkgs(args[seq(from = pos + 1L, to = length(args))])
146182
revdep_rm(packages = pkgs)
147183
todo()
148184
} else if ("--add-broken" %in% args) {
149185
revdep_add_broken()
150186
todo()
187+
} else if ("--add-error" %in% args) {
188+
# res <- revepcheck::revdep_summary()
189+
pkgs <- revdep_pkgs_with_status("error")
190+
str(pkgs)
191+
revdep_add(packages = pkgs)
192+
todo()
151193
} else if ("--add-all" %in% args) {
152194
revdep_init()
153195
pkgs <- revdep_children()
@@ -168,6 +210,7 @@ if ("--reset" %in% args) {
168210
todo()
169211
} else if ("--show-check" %in% args) {
170212
pos <- which("--show-check" == args)
213+
if (pos == length(args)) stop("Missing value for option '--show-check")
171214
pkgs <- parse_pkgs(args[seq(from = pos + 1L, to = length(args))])
172215
for (pkg in pkgs) {
173216
for (dir in c("old", "new")) {
@@ -188,20 +231,34 @@ if ("--reset" %in% args) {
188231
cat(sprintf("[n=%d] %s\n", length(pkgs), paste(pkgs, collapse = " ")))
189232
} else if ("--list-error" %in% args) {
190233
cat(paste(revdep_pkgs_with_status("error"), collapse = " "), "\n", sep="")
234+
} else if ("--list-failure" %in% args) {
235+
cat(paste(revdep_pkgs_with_status("failure"), collapse = " "), "\n", sep="")
191236
} else if ("--add-error" %in% args) {
192237
revdepcheck::revdep_add(packages = revdep_pkgs_with_status("error"))
238+
} else if ("--add-failure" %in% args) {
239+
revdepcheck::revdep_add(packages = revdep_pkgs_with_status("failure"))
240+
} else if ("--preinstall-update" %in% args) {
241+
revdep_preinstall_update()
193242
} else if ("--preinstall-children" %in% args) {
194243
pkg <- revdep_this_package()
195244
pkgs <- revdepcheck:::cran_revdeps(pkg)
196245
revdep_preinstall(pkgs)
197246
} else if ("--preinstall-error" %in% args) {
198247
res <- revdepcheck::revdep_summary()
199248
revdep_preinstall(revdep_pkgs_with_status("error"))
249+
} else if ("--preinstall-failure" %in% args) {
250+
res <- revdepcheck::revdep_summary()
251+
revdep_preinstall(revdep_pkgs_with_status("failure"))
252+
} else if ("--preinstall-todo" %in% args) {
253+
todo <- revdep_todo()
254+
revdep_preinstall(todo$package)
200255
} else if ("--preinstall" %in% args) {
201256
pos <- which("--preinstall" == args)
257+
if (pos == length(args)) stop("Missing value for option '--preinstall'")
202258
pkgs <- parse_pkgs(args[seq(from = pos + 1L, to = length(args))])
203259
revdep_preinstall(pkgs)
204260
} else {
261+
stopifnot(length(args) == 0L)
205262
check()
206263
revdep_report(all = TRUE)
207264
}

revdep/run.sge

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,15 @@
1414

1515
## SPECIAL: On Wynton HPC
1616
if [[ $SGE_CLUSTER_NAME == *wynton* ]]; then
17-
module load CBI
18-
module load r
19-
# module load r/4.0.0-alpha
20-
21-
## Some packages need a more modern version of gcc, e.g. 'balvaan'
22-
module load scl-devtoolset/4
23-
24-
## Some packages require non-default system libraries
25-
module load gdal geos gsl hdf5 jags
17+
module load CBI r
2618

2719
## Install all packages to toward $TMPDIR, if revdep/library doesn't already exist.
2820
## This will avoid some of the slowness on the global file system
29-
#if [[ ! -d revdep/library ]]; then
30-
# tmpdir=$(mktemp -d)
31-
# ln -fs "$tmpdir" revdep/library
32-
# [[ -d revdep/library ]] || { >&2 echo "ERROR: Failed to link revdep/library/ to $tmpdir"; exit 1; }
33-
#fi
21+
if [[ ! -d revdep/library ]]; then
22+
tmpdir=$(mktemp -d)
23+
ln -fs "$tmpdir" revdep/library
24+
[[ -d revdep/library ]] || { >&2 echo "ERROR: Failed to link revdep/library/ to $tmpdir"; exit 1; }
25+
fi
3426

3527
## To check in on revdep/library/ on the running host (see below), submit a job like:
3628
## echo "ls -lR revdep/library/" | qsub -cwd -j yes -l hostname=<hostname>

0 commit comments

Comments
 (0)