Skip to content

Commit

Permalink
added cutomized lib path and allow migrating packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Jan 31, 2024
1 parent 326f332 commit 14de218
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ravemanager
Title: Manage 'RAVE' Packages
Version: 1.0.37
Version: 1.0.38
Authors@R:
person("Zhengjia", "Wang", email = "[email protected]",
role = c("aut", "cre"))
Expand Down
45 changes: 44 additions & 1 deletion R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#' @param upgrade upgrade type
#' @param async whether to execute finalizing installation scripts in other
#' processes
#' @param migrate_packages whether to migrate (copy) packages installed in
#' the system path to the user library; used as alternative option when
#' there are existing packages installed in the system library path that could
#' be hard to resolve or out-dated; default is \code{FALSE}
#' @param lib_path library path where 'RAVE' should be installed; default is
#' automatically determined.
#' @param python whether to install python; default is false
#' @param reload whether to reload \code{ravemanager} after installation;
#' default is true. This tries to load the upgraded \code{ravemanager}
Expand Down Expand Up @@ -492,12 +498,49 @@ install_internal <- function(nightly = FALSE, upgrade_manager = FALSE,
#' @rdname RAVE-install
#' @export
install <- function(allow_cache = FALSE, upgrade_manager = FALSE,
finalize = TRUE, force = FALSE, python = FALSE, ...) {
finalize = TRUE, force = FALSE, python = FALSE,
migrate_packages = FALSE, lib_path = NA,
...) {

if(!allow_cache) {
pak_cache_remove()
}
if(length(lib_path) == 1L && !is.na(lib_path) && is.character(lib_path)) {
lib_path <- normalizePath(lib_path, mustWork = FALSE)
Sys.setenv("RAVE_LIB_PATH" = lib_path)
}

if(migrate_packages) {
# copy packages from system library path to user lib
libpaths <- get_libpaths(first = FALSE, check = TRUE)
if( length(libpaths) > 1 ) {
target_path <- libpaths[[1]]
syslib_paths <- libpaths[-1]

current_pkgs <- as.data.frame(utils::installed.packages(lib.loc = target_path))
current_pkgs <- current_pkgs$Package

lapply(syslib_paths, function(syslib_path) {
# syslib_path <- syslib_paths[[1]]
pkgs <- as.data.frame(utils::installed.packages(lib.loc = syslib_path, priority = NA_character_))
pkgs <- pkgs$Package[!pkgs$Package %in% current_pkgs]
if( length(pkgs) ) {
file.copy(
from = file.path(syslib_path, pkgs),
to = target_path,
recursive = TRUE,
overwrite = FALSE,
copy.mode = FALSE,
copy.date = TRUE
)

current_pkgs <<- c(current_pkgs, pkgs)
}
return()

})
}
}

nightly <- FALSE
tryCatch({
Expand Down
2 changes: 2 additions & 0 deletions R/python.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ configure_python <- function(python_ver = "3.9", verbose = TRUE) {
rpymat <- asNamespace("rpymat")

# Install conda and create a conda environment
# current_env <- Sys.getenv("R_RPYMAT_CONDA_PREFIX", unset = "")
# conda_exe <- Sys.getenv("R_RPYMAT_CONDA_EXE", unset = "")
if(!dir.exists(rpymat$env_path())) {
conda_bin <- rpymat$conda_bin()
standalone <- TRUE
Expand Down
12 changes: 12 additions & 0 deletions man/RAVE-install.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14de218

Please sign in to comment.