Skip to content

Commit 26cbdce

Browse files
Merge branch 'release/0.8.0'
2 parents ede01c2 + 8b3001a commit 26cbdce

16 files changed

+274
-151
lines changed

.travis.yml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#----------------------------------------------------------------
2-
# Travis-CI Configuration for R Packages
3-
# https://docs.travis-ci.com/user/languages/r
2+
# Travis-CI configuration for R packages
3+
#
4+
# REFERENCES:
5+
# * Travis CI: https://docs.travis-ci.com/user/languages/r
6+
# * covr: https://github.com/jimhester/covr
7+
#
8+
# YAML validated using http://www.yamllint.com/
49
#----------------------------------------------------------------
510
language: r
611
sudo: false
@@ -22,9 +27,12 @@ matrix:
2227
- os: linux
2328
r: devel
2429
env:
25-
- R_KEEP_PKG_SOURCE=yes
26-
- _R_S3_METHOD_LOOKUP_BASEENV_AFTER_GLOBALENV_=true
27-
- _R_S3_METHOD_LOOKUP_USE_TOPENV_AS_DEFENV_=true
30+
- R_KEEP_PKG_SOURCE=yes
31+
- _R_S3_METHOD_LOOKUP_BASEENV_AFTER_GLOBALENV_=true
32+
- _R_S3_METHOD_LOOKUP_USE_TOPENV_AS_DEFENV_=true
33+
- _R_CHECK_CONNECTIONS_LEFT_OPEN_=true
34+
- _R_CHECK_LENGTH_1_CONDITION_=true
35+
- _R_CHECK_LENGTH_1_LOGIC2_=true
2836
- os: linux
2937
r: devel
3038
r_github_packages:
@@ -33,9 +41,6 @@ matrix:
3341
- NB='w/ batchtools devel' ## Just a label
3442
- os: osx
3543
r: oldrel
36-
before_install:
37-
- Rscript -e 'c(physical = parallel::detectCores(logical = FALSE), logical = parallel::detectCores())'
38-
- Rscript -e 'install.packages(c("future", "future.apply"), type = "source")'
3944
- os: osx
4045
r: release
4146
- os: linux
@@ -46,14 +51,6 @@ matrix:
4651
after_success:
4752
- Rscript -e 'covr::codecov(quiet=FALSE)'
4853
env: NB='w/ covr' ## Just a label
49-
- os: linux
50-
r: release
51-
r_packages:
52-
- lintr
53-
r_check_args: --no-codoc --no-examples --no-tests --ignore-vignettes
54-
after_success:
55-
- Rscript -e 'library(lintr); lint_package(linters = with_defaults(commented_code_linter = NULL, closed_curly_linter = closed_curly_linter(allow_single_line = TRUE), open_curly_linter = open_curly_linter(allow_single_line = TRUE)))'
56-
env: NB='w/ lintr' ## Just a label
5754

5855
before_install:
5956
- Rscript -e 'c(physical = parallel::detectCores(logical = FALSE), logical = parallel::detectCores())'

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Package: future.batchtools
2-
Version: 0.7.2
2+
Version: 0.8.0
33
Depends:
44
R (>= 3.2.0),
5-
future (>= 1.10.0)
5+
future (>= 1.12.0)
66
Imports:
7-
batchtools (>= 0.9.8)
7+
batchtools (>= 0.9.11)
88
Suggests:
99
future.apply,
1010
listenv,

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
include .make/Makefile
2+
3+
future.tests/%:
4+
$(R_SCRIPT) -e "future.tests::check" --args --test-plan=$*
5+
6+
future.tests: future.tests/future.batchtools\:\:batchtools_local

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export(status)
3030
importFrom(batchtools,batchExport)
3131
importFrom(batchtools,batchMap)
3232
importFrom(batchtools,clearRegistry)
33+
importFrom(batchtools,findTemplateFile)
3334
importFrom(batchtools,getErrorMessages)
3435
importFrom(batchtools,getLog)
3536
importFrom(batchtools,getStatus)

NEWS

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
Package: future.batchtools
22
==========================
33

4+
Version: 0.8.0 [2019-05-04]
5+
6+
NEW FEATURES:
7+
8+
* Setting option 'future.delete' to FALSE will now prevent removal of the
9+
batchtools registry folders.
10+
11+
* When a batchtools job expires, for instance when the scheduler terminates
12+
it because the job was running out of its allocated resources, then a
13+
BatchtoolsFutureError is produced which by default outputs the tail of the
14+
output logged by batchtools. The default number of lines displayed from
15+
the end is now increased to from six to 48 - a number which now can be set
16+
via option 'future.batchtools.expiration.tail'.
17+
18+
* Now a more informative error message is produced if a batchtools *.tmpl
19+
template file was not found.
20+
21+
* Debug messages are now prepended with a timestamp.
22+
23+
BUG FIXES:
24+
25+
* Argument 'workers' could not be a function.
26+
27+
* Argument 'workers' of type character was silently accepted and effectively
28+
interpreted as workers = length(workers).
29+
30+
431
Version: 0.7.2 [2018-12-03]
532

633
DOCUMENTATION:

R/BatchtoolsFuture-class.R

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ BatchtoolsFuture <- function(expr = NULL, envir = parent.frame(),
5959
stop_if_not(is.list(cluster.functions))
6060
}
6161

62+
if (is.function(workers)) workers <- workers()
6263
if (!is.null(workers)) {
6364
stop_if_not(length(workers) >= 1)
6465
if (is.numeric(workers)) {
6566
stop_if_not(!anyNA(workers), all(workers >= 1))
66-
} else if (is.character(workers)) {
6767
} else {
68-
stop_if_not("Argument 'workers' should be either numeric or character: ",
69-
mode(workers))
68+
stop("Argument 'workers' should be either a numeric or a function: ",
69+
mode(workers))
7070
}
7171
}
7272

@@ -321,8 +321,6 @@ run.BatchtoolsFuture <- function(future, ...) {
321321
stop(sprintf("A future ('%s') can only be launched once.", label))
322322
}
323323

324-
mdebug <- import_future("mdebug")
325-
326324
## Assert that the process that created the future is
327325
## also the one that evaluates/resolves/queries it.
328326
assertOwner <- import_future("assertOwner")
@@ -350,7 +348,7 @@ run.BatchtoolsFuture <- function(future, ...) {
350348
## (ii) Attach packages that needs to be attached
351349
packages <- future$packages
352350
if (length(packages) > 0) {
353-
mdebug("Attaching %d packages (%s) ...",
351+
mdebugf("Attaching %d packages (%s) ...",
354352
length(packages), hpaste(sQuote(packages)))
355353

356354
## Record which packages in 'pkgs' that are loaded and
@@ -364,7 +362,7 @@ run.BatchtoolsFuture <- function(future, ...) {
364362
reg$packages <- packages
365363
saveRegistry(reg = reg)
366364

367-
mdebug("Attaching %d packages (%s) ... DONE",
365+
mdebugf("Attaching %d packages (%s) ... DONE",
368366
length(packages), hpaste(sQuote(packages)))
369367
}
370368
## Not needed anymore
@@ -388,7 +386,7 @@ run.BatchtoolsFuture <- function(future, ...) {
388386

389387
## 2. Update
390388
future$config$jobid <- jobid
391-
mdebug("Created %s future #%d", class(future)[1], jobid$job.id)
389+
mdebugf("Created %s future #%d", class(future)[1], jobid$job.id)
392390

393391
## WORKAROUND: (For multicore and macOS only)
394392
if (reg$cluster.functions$name == "Multicore") {
@@ -419,7 +417,7 @@ run.BatchtoolsFuture <- function(future, ...) {
419417

420418
batchtools::submitJobs(reg = reg, ids = jobid, resources = resources)
421419

422-
mdebug("Launched future #%d", jobid$job.id)
420+
mdebugf("Launched future #%d", jobid$job.id)
423421

424422
invisible(future)
425423
} ## run()
@@ -458,7 +456,6 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE,
458456
1.0),
459457
alpha = getOption("future.wait.alpha", 1.01),
460458
...) {
461-
mdebug <- import_future("mdebug")
462459
stop_if_not(is.finite(timeout), timeout >= 0)
463460
stop_if_not(is.finite(alpha), alpha > 0)
464461

@@ -480,9 +477,9 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE,
480477

481478
res <- waitForJobs(ids = jobid, timeout = timeout, sleep = sleep_fcn,
482479
stop.on.error = FALSE, reg = reg)
483-
mdebug("- batchtools::waitForJobs(): %s", res)
480+
mdebugf("- batchtools::waitForJobs(): %s", res)
484481
stat <- status(future)
485-
mdebug("- status(): %s", paste(sQuote(stat), collapse = ", "))
482+
mdebugf("- status(): %s", paste(sQuote(stat), collapse = ", "))
486483
mdebug("batchtools::waitForJobs() ... done")
487484

488485
finished <- is_na(stat) || any(c("finished", "error", "expired") %in% stat)
@@ -515,11 +512,11 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE,
515512
output <- loggedOutput(future)
516513
hint <- unlist(strsplit(output, split = "\n", fixed = TRUE))
517514
hint <- hint[nzchar(hint)]
518-
hint <- tail(hint, n = 6L)
515+
hint <- tail(hint, n = getOption("future.batchtools.expiration.tail", 48L))
519516
if (length(hint) > 0) {
520517
hint <- paste(hint, collapse = "\n")
521-
msg <- sprintf("%s. The last few lines of the logged output:\n%s",
522-
msg, hint)
518+
msg <- paste(msg, ". The last few lines of the logged output:\n",
519+
hint, sep="")
523520
} else {
524521
msg <- sprintf("%s. No logged output exist.", msg)
525522
}
@@ -576,8 +573,6 @@ delete.BatchtoolsFuture <- function(future,
576573
delta = getOption("future.wait.interval", 1.0),
577574
alpha = getOption("future.wait.alpha", 1.01),
578575
...) {
579-
mdebug <- import_future("mdebug")
580-
581576
onRunning <- match.arg(onRunning)
582577
onMissing <- match.arg(onMissing)
583578
onFailure <- match.arg(onFailure)
@@ -593,7 +588,7 @@ delete.BatchtoolsFuture <- function(future,
593588
if (is.null(path) || !file_test("-d", path)) {
594589
if (onMissing %in% c("warning", "error")) {
595590
msg <- sprintf("Cannot remove batchtools registry, because directory does not exist: %s", sQuote(path)) #nolint
596-
mdebug("delete(): %s", msg)
591+
mdebugf("delete(): %s", msg)
597592
if (onMissing == "warning") {
598593
warning(msg)
599594
} else if (onMissing == "error") {
@@ -611,7 +606,7 @@ delete.BatchtoolsFuture <- function(future,
611606
label <- future$label
612607
if (is.null(label)) label <- "<none>"
613608
msg <- sprintf("Will not remove batchtools registry, because is appears to hold a non-resolved future (%s; state = %s; batchtools status = %s): %s", sQuote(label), sQuote(future$state), paste(sQuote(status), collapse = ", "), sQuote(path)) #nolint
614-
mdebug("delete(): %s", msg)
609+
mdebugf("delete(): %s", msg)
615610
if (onRunning == "warning") {
616611
warning(msg)
617612
return(invisible(TRUE))
@@ -627,24 +622,31 @@ delete.BatchtoolsFuture <- function(future,
627622

628623
## To simplify post mortem troubleshooting in non-interactive sessions,
629624
## should the batchtools registry files be removed or not?
630-
mdebug("delete(): Option 'future.delete = %s",
625+
mdebugf("delete(): Option 'future.delete = %s",
631626
sQuote(getOption("future.delete", "<NULL>")))
632627
if (!getOption("future.delete", interactive())) {
633628
status <- status(future)
634629
res <- future$result
635630
if (inherits(res, "FutureResult")) {
636631
if (result_has_errors(res)) status <- unique(c("error", status))
637632
}
638-
mdebug("delete(): status(<future>) = %s",
633+
mdebugf("delete(): status(<future>) = %s",
639634
paste(sQuote(status), collapse = ", "))
640635
if (any(c("error", "expired") %in% status)) {
641636
msg <- sprintf("Will not remove batchtools registry, because the status of the batchtools was %s and option 'future.delete' is FALSE or running in an interactive session: %s", paste(sQuote(status), collapse = ", "), sQuote(path)) #nolint
642-
mdebug("delete(): %s", msg)
637+
mdebugf("delete(): %s", msg)
643638
warning(msg)
644639
return(invisible(FALSE))
645640
}
646641
}
647642

643+
## Have user disabled deletions?
644+
if (!getOption("future.delete", TRUE)) {
645+
msg <- sprintf("Option 'future.delete' is FALSE - will not delete batchtools registry: %s", sQuote(path))
646+
mdebugf("delete(): %s", msg)
647+
return(invisible(FALSE))
648+
}
649+
648650
## Control batchtools info output
649651
oopts <- options(batchtools.verbose = debug)
650652
on.exit(options(oopts))
@@ -664,7 +666,7 @@ delete.BatchtoolsFuture <- function(future,
664666
if (file_test("-d", path)) {
665667
if (onFailure %in% c("warning", "error")) {
666668
msg <- sprintf("Failed to remove batchtools registry: %s", sQuote(path))
667-
mdebug("delete(): %s", msg)
669+
mdebugf("delete(): %s", msg)
668670
if (onMissing == "warning") {
669671
warning(msg)
670672
} else if (onMissing == "error") {
@@ -674,7 +676,7 @@ delete.BatchtoolsFuture <- function(future,
674676
return(invisible(FALSE))
675677
}
676678

677-
mdebug("delete(): batchtools registry deleted: %s", sQuote(path))
679+
mdebugf("delete(): batchtools registry deleted: %s", sQuote(path))
678680

679681
invisible(TRUE)
680682
} # delete()

R/batchtools_template.R

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class(batchtools_torque) <- c("batchtools_torque", "batchtools_template",
118118
"batchtools", "multiprocess", "future",
119119
"function")
120120

121-
121+
#' @importFrom batchtools findTemplateFile
122122
#' @importFrom batchtools makeClusterFunctionsLSF
123123
#' @importFrom batchtools makeClusterFunctionsOpenLava
124124
#' @importFrom batchtools makeClusterFunctionsSGE
@@ -148,24 +148,28 @@ batchtools_by_template <- function(expr, envir = parent.frame(),
148148
template <- formals(make_cfs)$template
149149
}
150150

151-
stop_if_not(is.character(template), length(template) == 1, nzchar(template))
151+
stop_if_not(is.character(template), length(template) == 1L,
152+
!is.na(template), nzchar(template))
152153

153154
## Tweaked search for template file
154-
findTemplateFile <- import_batchtools("findTemplateFile", default = NA)
155-
if (!identical(findTemplateFile, NA)) {
156-
template <- tryCatch({
157-
findTemplateFile(template)
158-
}, error = function(ex) {
159-
## Try to find it in this package?
160-
if (grepl("Argument 'template'", conditionMessage(ex))) {
161-
pathname <- system.file("templates", sprintf("%s.tmpl", template),
162-
package = "future.batchtools")
163-
if (file_test("-f", pathname)) return(pathname)
164-
}
165-
stop(ex)
166-
})
155+
pathname <- tryCatch({
156+
findTemplateFile(template)
157+
}, error = function(ex) {
158+
## Try to find it in this package?
159+
if (grepl("Argument 'template'", conditionMessage(ex))) {
160+
pathname <- system.file("templates", sprintf("%s.tmpl", template),
161+
package = "future.batchtools")
162+
if (file_test("-f", pathname)) return(pathname)
163+
}
164+
stop(ex)
165+
})
166+
if (is.na(pathname)) {
167+
stop(sprintf("Failed to locate a batchtools template file: *%s.tmpl",
168+
template))
167169
}
168170

171+
template <- pathname
172+
169173
cluster.functions <- make_cfs(template)
170174
attr(cluster.functions, "template") <- template
171175

0 commit comments

Comments
 (0)