Skip to content

Commit fba4729

Browse files
authored
Merge pull request #320 from rstudio/zh-launcher-submit-job-resource-profile
Add support for setting resource profile in `rstudioapi::launcherSubmitJob`
2 parents 68b315e + 2db61ea commit fba4729

File tree

10 files changed

+117
-125
lines changed

10 files changed

+117
-125
lines changed

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

Lines changed: 21 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
# NOTE: This workflow is overkill for most R packages
2-
# check-standard.yaml is likely a better choice
3-
# usethis::use_github_action("check-standard") will install it.
4-
#
5-
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
6-
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
73
on:
84
push:
9-
branches:
10-
- main
11-
- master
5+
branches: [main, master]
126
pull_request:
13-
branches:
14-
- main
15-
- master
167

17-
name: R-CMD-check
8+
name: R-CMD-check.yaml
9+
10+
permissions: read-all
1811

1912
jobs:
2013
R-CMD-check:
@@ -26,87 +19,33 @@ jobs:
2619
fail-fast: false
2720
matrix:
2821
config:
29-
- {os: macOS-latest, r: 'release'}
22+
- {os: macos-latest, r: 'release'}
3023
- {os: windows-latest, r: 'release'}
31-
- {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"}
32-
- {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.0.0 (ubuntu-18.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
33-
- {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
34-
- {os: ubuntu-18.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
35-
- {os: ubuntu-18.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
36-
- {os: ubuntu-18.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
37-
- {os: ubuntu-18.04, r: '3.4', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
24+
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
25+
- {os: ubuntu-latest, r: 'release'}
26+
- {os: ubuntu-latest, r: 'oldrel-1'}
3827

3928
env:
40-
RSPM: ${{ matrix.config.rspm }}
4129
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
30+
R_KEEP_PKG_SOURCE: yes
4231

4332
steps:
44-
- uses: actions/checkout@v2
33+
- uses: actions/checkout@v4
34+
35+
- uses: r-lib/actions/setup-pandoc@v2
4536

4637
- uses: r-lib/actions/setup-r@v2
47-
id: install-r
4838
with:
4939
r-version: ${{ matrix.config.r }}
5040
http-user-agent: ${{ matrix.config.http-user-agent }}
41+
use-public-rspm: true
5142

52-
- uses: r-lib/actions/setup-pandoc@v1
53-
54-
- name: Install pak and query dependencies
55-
run: |
56-
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
57-
saveRDS(pak::pkg_deps("local::.", dependencies = TRUE), ".github/r-depends.rds")
58-
shell: Rscript {0}
59-
60-
- name: Restore R package cache
61-
uses: actions/cache@v2
43+
- uses: r-lib/actions/setup-r-dependencies@v2
6244
with:
63-
path: |
64-
${{ env.R_LIBS_USER }}/*
65-
!${{ env.R_LIBS_USER }}/pak
66-
key: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('.github/r-depends.rds') }}
67-
restore-keys: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-
68-
69-
- name: Install system dependencies
70-
if: runner.os == 'Linux'
71-
run: |
72-
pak::local_system_requirements(execute = TRUE)
73-
pak::pkg_system_requirements("rcmdcheck", execute = TRUE)
74-
shell: Rscript {0}
45+
extra-packages: any::rcmdcheck
46+
needs: check
7547

76-
- name: Install dependencies
77-
run: |
78-
pak::local_install_dev_deps(upgrade = TRUE)
79-
pak::pkg_install("rcmdcheck")
80-
shell: Rscript {0}
81-
82-
- name: Session info
83-
run: |
84-
options(width = 100)
85-
pkgs <- installed.packages()[, "Package"]
86-
sessioninfo::session_info(pkgs, include_base = TRUE)
87-
shell: Rscript {0}
88-
89-
- name: Check
90-
env:
91-
_R_CHECK_CRAN_INCOMING_: false
92-
run: |
93-
options(crayon.enabled = TRUE)
94-
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
95-
shell: Rscript {0}
96-
97-
- name: Show testthat output
98-
if: always()
99-
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
100-
shell: bash
101-
102-
- name: Upload check results
103-
if: failure()
104-
uses: actions/upload-artifact@main
48+
- uses: r-lib/actions/check-r-package@v2
10549
with:
106-
name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results
107-
path: check
108-
109-
- name: Don't use tar from old Rtools to store the cache
110-
if: ${{ runner.os == 'Windows' && startsWith(steps.install-r.outputs.installed-r-version, '3.6' ) }}
111-
shell: bash
112-
run: echo "C:/Program Files/Git/usr/bin" >> $GITHUB_PATH
50+
upload-snapshots: true
51+
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
13
on:
24
push:
3-
branches:
4-
- main
5-
- master
5+
branches: [main, master]
66
pull_request:
7-
branches:
8-
- main
9-
- master
107

11-
name: test-coverage
8+
name: test-coverage.yaml
9+
10+
permissions: read-all
1211

1312
jobs:
1413
test-coverage:
15-
runs-on: ubuntu-18.04
14+
runs-on: ubuntu-latest
1615
env:
17-
RSPM: https://packagemanager.rstudio.com/cran/__linux__/bionic/latest
1816
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1917

2018
steps:
21-
- uses: actions/checkout@v2
22-
23-
- uses: r-lib/actions/setup-r@v1
24-
id: install-r
19+
- uses: actions/checkout@v4
2520

26-
- name: Install pak and query dependencies
27-
run: |
28-
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
29-
saveRDS(pak::pkg_deps("local::.", dependencies = TRUE), ".github/r-depends.rds")
30-
shell: Rscript {0}
21+
- uses: r-lib/actions/setup-r@v2
22+
with:
23+
use-public-rspm: true
3124

32-
- name: Restore R package cache
33-
uses: actions/cache@v2
25+
- uses: r-lib/actions/setup-r-dependencies@v2
3426
with:
35-
path: |
36-
${{ env.R_LIBS_USER }}/*
37-
!${{ env.R_LIBS_USER }}/pak
38-
key: ubuntu-18.04-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('.github/r-depends.rds') }}
39-
restore-keys: ubuntu-18.04-${{ steps.install-r.outputs.installed-r-version }}-1-
40-
41-
- name: Install system dependencies
42-
if: runner.os == 'Linux'
27+
extra-packages: any::covr, any::xml2
28+
needs: coverage
29+
30+
- name: Test coverage
4331
run: |
44-
pak::local_system_requirements(execute = TRUE)
45-
pak::pkg_system_requirements("covr", execute = TRUE)
32+
cov <- covr::package_coverage(
33+
quiet = FALSE,
34+
clean = FALSE,
35+
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
36+
)
37+
print(cov)
38+
covr::to_cobertura(cov)
4639
shell: Rscript {0}
4740

48-
- name: Install dependencies
41+
- uses: codecov/codecov-action@v5
42+
with:
43+
# Fail if error if not on PR, or if on PR and token is given
44+
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
45+
files: ./cobertura.xml
46+
plugins: noop
47+
disable_search: true
48+
token: ${{ secrets.CODECOV_TOKEN }}
49+
50+
- name: Show testthat output
51+
if: always()
4952
run: |
50-
pak::local_install_dev_deps(upgrade = TRUE)
51-
pak::pkg_install("covr")
52-
shell: Rscript {0}
53+
## --------------------------------------------------------------------
54+
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
55+
shell: bash
5356

54-
- name: Test coverage
55-
run: covr::codecov()
56-
shell: Rscript {0}
57+
- name: Upload test results
58+
if: failure()
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: coverage-test-failures
62+
path: ${{ runner.temp }}/package

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ URL: https://rstudio.github.io/rstudioapi/,
1616
https://github.com/rstudio/rstudioapi
1717
BugReports: https://github.com/rstudio/rstudioapi/issues
1818
Roxygen: list(markdown = TRUE)
19-
RoxygenNote: 7.3.2
19+
RoxygenNote: 7.3.3
2020
Suggests:
2121
testthat,
2222
knitr,

R/code.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ callFun <- function(fname, ...) {
126126
# drop arguments that aren't accepted by RStudio
127127
# (ensure backwards-compatibility with older versions of RStudio)
128128
args <- list(...)
129-
if (!"..." %in% names(formals(f)))
129+
if (!"..." %in% names(formals(f))) {
130+
args <- checkApiArguments(fname, f, args)
130131
if (length(args) > length(formals(f)))
131132
length(args) <- length(formals(f))
133+
}
132134

133135
# invoke the function
134136
do.call(f, args)
@@ -183,7 +185,7 @@ usingTools <- function() {
183185
}
184186

185187
toolsName <- function(name) {
186-
paste(".rs.api.", name, sep="")
188+
paste(".rs.api.", name, sep = "")
187189
}
188190

189191
toolsEnv <- function() {

R/launcher-functions.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ launcherNfsMount <- function(host,
296296
#' @param resourceLimits A list of resource limits. See
297297
#' \code{\link[=launcherResourceLimit]{launcherResourceLimit()}} for more
298298
#' information.
299+
#'
300+
#' @param resourceProfile A resource profile name to be used for the job. The
301+
#' resource profile must be defined in the cluster configuration.
299302
#'
300303
#' @param queues A list of available submission queues for the cluster. Only
301304
#' applicable to batch systems like LSF.
@@ -329,6 +332,7 @@ launcherSubmitJob <- function(name,
329332
mounts = NULL,
330333
placementConstraints = NULL,
331334
resourceLimits = NULL,
335+
resourceProfile = NULL,
332336
queues = NULL,
333337

334338
config = NULL,
@@ -351,6 +355,7 @@ launcherSubmitJob <- function(name,
351355
placementConstraints = placementConstraints,
352356
queues = queues,
353357
resourceLimits = resourceLimits,
358+
resourceProfile = resourceProfile,
354359
stderrFile = stderrFile,
355360
stdin = stdin,
356361
stdoutFile = stdoutFile,

R/utils.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,38 @@ renderTemplate <- function(template, data) {
1717
rendered
1818

1919
}
20+
21+
checkApiArguments <- function(fname, f, args) {
22+
23+
# allow opt-out just in case
24+
enabled <- getOption("rstudioapi.checkApiArguments", default = TRUE)
25+
if (identical(enabled, FALSE))
26+
return(args)
27+
28+
# check for arguments supplied by the user that aren't available
29+
# in the current version of RStudio
30+
unsupportedArgNames <- setdiff(names(args), names(formals(f)))
31+
if (length(unsupportedArgNames) == 0L)
32+
return(args)
33+
34+
# check which of these arguments is NULL; if all arguments are NULL,
35+
# then we accept the call
36+
isNullArg <- vapply(args[unsupportedArgNames], is.null, FUN.VALUE = logical(1))
37+
badArgNames <- names(isNullArg)[!isNullArg]
38+
if (length(badArgNames) == 0L) {
39+
args[unsupportedArgNames] <- NULL
40+
return(args)
41+
}
42+
43+
# if we get here, the user tried to supply a value for a parameter that isn't
44+
# supported in this version of RStudio; emit an error
45+
fmt <- ifelse(
46+
length(badArgNames) == 1L,
47+
"Parameter %s is not supported by %s in this version of RStudio.",
48+
"Parameters %s are not supported by %s in this version of RStudio."
49+
)
50+
51+
msg <- sprintf(fmt, paste(shQuote(badArgNames), collapse = ", "), shQuote(fname))
52+
stop(msg, call. = FALSE)
53+
54+
}

README.Rmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ knitr::opts_chunk$set(
1919
<!-- badges: start -->
2020
[![CRAN status](https://www.r-pkg.org/badges/version/rstudioapi)](https://CRAN.R-project.org/package=rstudioapi)
2121
[![Codecov test coverage](https://codecov.io/gh/rstudio/rstudioapi/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rstudio/rstudioapi?branch=main)
22-
[![R-CMD-check](https://github.com/rstudio/rstudioapi/workflows/R-CMD-check/badge.svg)](https://github.com/rstudio/rstudioapi/actions)
22+
[![R-CMD-check](https://github.com/rstudio/rstudioapi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rstudio/rstudioapi/actions/workflows/R-CMD-check.yaml)
23+
[![Codecov test coverage](https://codecov.io/gh/rstudio/rstudioapi/graph/badge.svg)](https://app.codecov.io/gh/rstudio/rstudioapi)
2324
<!-- badges: end -->
2425

2526
The `rstudioapi` package is designed to make it easy to conditionally access the

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
status](https://www.r-pkg.org/badges/version/rstudioapi)](https://CRAN.R-project.org/package=rstudioapi)
1010
[![Codecov test
1111
coverage](https://codecov.io/gh/rstudio/rstudioapi/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rstudio/rstudioapi?branch=main)
12-
[![R-CMD-check](https://github.com/rstudio/rstudioapi/workflows/R-CMD-check/badge.svg)](https://github.com/rstudio/rstudioapi/actions)
12+
[![R-CMD-check](https://github.com/rstudio/rstudioapi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rstudio/rstudioapi/actions/workflows/R-CMD-check.yaml)
1313
<!-- badges: end -->
1414

1515
The `rstudioapi` package is designed to make it easy to conditionally

man/launcherSubmitJob.Rd

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/r-session.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Interacting with the R Session"
2+
title: "Interact with the R Session"
33
output: rmarkdown::html_vignette
44
vignette: >
55
%\VignetteIndexEntry{Interact with the R Session}

0 commit comments

Comments
 (0)