-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ci] consolidate R package installs into a CI script #6808
Open
jameslamb
wants to merge
16
commits into
master
Choose a base branch
from
ci/r-deps-scripts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−34
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5cfd192
[ci] consolidate R package installs into a CI script
jameslamb d033e2a
use CRAN_MIRROR and R_LIB_PATH consistently
jameslamb 142d699
shorter lines and fix reference
jameslamb 16c8ab4
fix type option
jameslamb fb2d4c7
add extension
jameslamb 5737073
fix invocations on Windows
jameslamb aaa228c
more fixes
jameslamb 27ff6f7
binary
jameslamb ec43edf
use package_type binary on Windows
jameslamb ae10dca
Merge branch 'master' of github.com:microsoft/LightGBM into ci/r-deps…
jameslamb 061e69f
Update .ci/test-r-package-windows.ps1
jameslamb ea988db
more fixes
jameslamb d0427d1
Merge branch 'master' into ci/r-deps-scripts
jameslamb 21a607b
Apply suggestions from code review
jameslamb 8cd2627
Merge branch 'ci/r-deps-scripts' of github.com:microsoft/LightGBM int…
jameslamb dae117f
make install-r-deps more flexible
jameslamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# install R dependencies, using only base R | ||
# | ||
# Supported arguments: | ||
# | ||
# --all Install all the 'Depends', 'Imports', 'LinkingTo', and 'Suggests' dependencies. | ||
# (automatically implies --build --test). | ||
# | ||
# --build install the packages needed to build | ||
# | ||
# --exclude=<pkg1,pkg2,...> Comma-delimited list of packages to NOT install. | ||
# | ||
# --include=<pkg1,pkg2,...> Comma-delimited list of additional packages to install. | ||
# These will always be installed, unless also used in "--exclude". | ||
# | ||
# --test install packages needed to run tests | ||
# | ||
|
||
|
||
# [description] Parse command line arguments into an R list. | ||
# Returns a list where keys are arguments and values | ||
# are either TRUE (for flags) or a vector of values passed via a | ||
# comma-delimited list. | ||
.parse_args <- function(args) { | ||
out <- list( | ||
"--all" = FALSE | ||
, "--build" = FALSE | ||
, "--exclude" = character(0L) | ||
, "--include" = character(0L) | ||
, "--test" = FALSE | ||
) | ||
for (arg in args) { | ||
print(sprintf("arg: '%s'", arg)) | ||
parsed_arg <- unlist(strsplit(arg, "=", fixed = TRUE)) | ||
arg_name <- parsed_arg[[1L]] | ||
if (!(arg_name %in% names(out))) { | ||
stop(sprintf("Unrecognized argument: '%s'", arg_name)) | ||
} | ||
if (length(parsed_arg) == 2L) { | ||
# lists, like "--include=roxygen2,testthat" | ||
values <- unlist(strsplit(parsed_arg[[2L]], ",", fixed = TRUE)) | ||
out[[arg_name]] <- values | ||
} else { | ||
# flags, like "--build" | ||
out[[arg]] <- TRUE | ||
} | ||
} | ||
return(out) | ||
} | ||
|
||
args <- .parse_args( | ||
commandArgs(trailingOnly = TRUE) | ||
) | ||
|
||
# which dependencies to install | ||
ALL_DEPS <- isTRUE(args[["--all"]]) | ||
BUILD_DEPS <- ALL_DEPS || isTRUE(args[["--build"]]) | ||
TEST_DEPS <- ALL_DEPS || isTRUE(args[["--test"]]) | ||
|
||
# force downloading of binary packages on macOS | ||
COMPILE_FROM_SOURCE <- "both" | ||
PACKAGE_TYPE <- getOption("pkgType") | ||
|
||
# CRAN has precompiled binaries for macOS and Windows... prefer those, | ||
# for faster installation. | ||
if (Sys.info()[["sysname"]] == "Darwin" || .Platform$OS.type == "windows") { | ||
COMPILE_FROM_SOURCE <- "never" | ||
PACKAGE_TYPE <- "binary" | ||
} | ||
options( | ||
install.packages.check.source = "no" | ||
, install.packages.compile.from.source = COMPILE_FROM_SOURCE | ||
) | ||
|
||
# always use the same CRAN mirror | ||
CRAN_MIRROR <- Sys.getenv("CRAN_MIRROR", unset = "https://cran.r-project.org") | ||
|
||
# we always want these | ||
deps_to_install <- c( | ||
"data.table" | ||
, "jsonlite" | ||
, "Matrix" | ||
, "R6" | ||
) | ||
|
||
if (isTRUE(BUILD_DEPS)) { | ||
deps_to_install <- c( | ||
deps_to_install | ||
, "knitr" | ||
, "markdown" | ||
) | ||
} | ||
|
||
if (isTRUE(TEST_DEPS)) { | ||
deps_to_install <- c( | ||
deps_to_install | ||
, "RhpcBLASctl" | ||
, "testthat" | ||
) | ||
} | ||
|
||
# add packages passed through '--include' | ||
deps_to_install <- unique(c( | ||
deps_to_install | ||
, args[["--include"]] | ||
)) | ||
|
||
# remove packages passed through '--exclude' | ||
deps_to_install <- setdiff( | ||
x = deps_to_install | ||
, args[["--exclude"]] | ||
) | ||
|
||
msg <- sprintf( | ||
"[install-r-deps] installing R packages: %s\n" | ||
, toString(sort(deps_to_install)) | ||
) | ||
cat(msg) | ||
|
||
install.packages( # nolint[undesirable_function] | ||
pkgs = deps_to_install | ||
, dependencies = c("Depends", "Imports", "LinkingTo") | ||
, lib = Sys.getenv("R_LIB_PATH", unset = .libPaths()[[1L]]) | ||
, repos = CRAN_MIRROR | ||
, type = PACKAGE_TYPE | ||
, Ncpus = parallel::detectCores() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should allow installation of arbitrary R package by this script? For example, late
testthat
installation orprocessx
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree! I implemented this in dae117f
Proposing adding two arguments,
--include
and--exclude
, which are applied to the list of dependencies calculated after processing coarser arguments like--all
,--build
, and--test
.