Skip to content

Commit ba1ec91

Browse files
committed
Merge branch 'fix-basilisk-api' of https://github.com/neurogenomics/echoconda
# Conflicts: # NAMESPACE # R/activate_env_basilisk.R # R/basilisk.R # R/find_conda.R # R/install_conda_basilisk.R # R/remove_env.R
2 parents c59edf5 + 9baabb2 commit ba1ec91

File tree

6 files changed

+26
-53
lines changed

6 files changed

+26
-53
lines changed

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export(which_env)
1919
export(yaml_to_env)
2020
import(R.utils)
2121
importFrom(basilisk,BasiliskEnvironment)
22+
importFrom(basilisk,isWindows)
2223
importFrom(basilisk,listPackages)
23-
importFrom(basilisk.utils,condaBinary)
2424
importFrom(basilisk.utils,defaultCacheDirectory)
2525
importFrom(basilisk.utils,download)
26+
importFrom(basilisk.utils,find)
2627
importFrom(data.table,":=")
2728
importFrom(data.table,fread)
2829
importFrom(data.table,rbindlist)

R/activate_env_basilisk.R

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
activate_env_basilisk <- function(conda_env,
2-
loc=basilisk.utils::defaultCacheDirectory(),
2+
loc=NULL,
33
verbose=TRUE){
4-
5-
messager("Activating conda env via basilisk:",
4+
## Note: basilisk.utils::activateEnvironment was removed in newer versions.
5+
## Now using reticulate-based activation instead.
6+
messager("Activating conda env:",
67
paste0("'",conda_env,"'"),v = verbose)
7-
## Supplying the full path to the env dir
8-
## is much more robust than simply supplying the env name.
9-
envs <- list_envs(conda_env = conda_env,
10-
method = "basilisk")
11-
## activateEnvironment was removed from basilisk.utils.
12-
## Set environment variables directly to activate the conda env.
13-
envpath <- envs$dir
14-
if(length(envpath) > 0 && nchar(envpath[1]) > 0){
15-
conda_x <- basilisk.utils::condaBinary(loc = loc)
16-
Sys.setenv(CONDA_PREFIX = envpath[1])
17-
old_path <- Sys.getenv("PATH")
18-
bin_dir <- if(.Platform$OS.type == "windows"){
19-
envpath[1]
20-
} else {
21-
file.path(envpath[1], "bin")
22-
}
23-
Sys.setenv(PATH = paste(bin_dir, old_path, sep = .Platform$path.sep))
24-
}
25-
return(invisible(envpath))
8+
activate_env_reticulate(conda_env = conda_env,
9+
verbose = verbose)
2610
}

R/basilisk.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ create_env_basilisk <- function(yaml_path,
3939
simplify = TRUE)[,1]
4040
#### Remove deps that aren't available on Windows ####
4141
## (at least, for specific versions)
42-
if(.Platform$OS.type == "windows"){
42+
if(basilisk::isWindows()){
4343
deps <- deps[!deps %in% c("wget","gzip","htslib","axel")]
4444
}
4545
#### Subset to only core packages ####

R/find_conda.R

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#' Find conda
2-
#'
3-
#' Find conda executable from multiple installations:
1+
#' Find conda
2+
#'
3+
#' Find conda executable from multiple installations:
44
#' \pkg{reticulate}, \pkg{basilisk}
5-
#'
5+
#'
66
#' @param method Method to use:
77
#' \itemize{
88
#' \item \code{"basilisk"}
@@ -11,16 +11,14 @@
1111
#' @inheritParams reticulate::conda_binary
1212
#'
1313
#' @export
14-
#' @importFrom basilisk.utils condaBinary defaultCacheDirectory
14+
#' @importFrom basilisk.utils find
1515
find_conda <- function(conda="auto",
1616
method=c("basilisk","reticulate")){
1717
method <- tolower(method)[1]
1818
if(method=="basilisk"){
19-
conda_x <- basilisk.utils::condaBinary(
20-
loc = basilisk.utils::defaultCacheDirectory()
21-
)
19+
conda_x <- basilisk.utils::find()
2220
#### If it fails, use the other method ####
23-
if(!file.exists(conda_x)){
21+
if(is.null(conda_x) || !file.exists(conda_x)){
2422
conda_x <- reticulate::conda_binary(conda = conda)
2523
}
2624
} else if(method=="reticulate"){
@@ -29,9 +27,7 @@ find_conda <- function(conda="auto",
2927
conda_x <- reticulate::conda_binary(conda = conda)
3028
#### If it fails, use the other method ####
3129
if(!file.exists(conda_x)){
32-
conda_x <- basilisk.utils::condaBinary(
33-
loc = basilisk.utils::defaultCacheDirectory()
34-
)
30+
conda_x <- basilisk.utils::find()
3531
}
3632
} else {
3733
stop("method not recognized.")

R/install_conda_basilisk.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
install_conda_basilisk <- function(verbose=TRUE){
99
# Sys.setenv("BASILISK_USE_SYSTEM_DIR"=1)
1010
cache_dir <- basilisk.utils::defaultCacheDirectory()
11-
conda_path <- basilisk.utils::condaBinary(loc = cache_dir)
12-
if(!file.exists(conda_path)){
13-
messager("echoconda:: Installing conda via basilisk.",v=verbose)
14-
basilisk.utils::download(cache.dir = cache_dir)
15-
} else {
16-
messager("echoconda:: conda already installed.",v=verbose)
11+
messager("echoconda:: Installing/checking conda via basilisk.", v=verbose)
12+
conda_path <- basilisk.utils::download()
13+
if(!is.null(conda_path) && dir.exists(conda_path)){
14+
messager("echoconda:: conda available at:", conda_path, v=verbose)
1715
}
1816
}

R/remove_env.R

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#' Remove conda environment
2-
#'
2+
#'
33
#' Actually remove conda environments,
44
#' unlike \code{reticulate}::\link[reticulate]{conda_remove}.
5-
#'
6-
#' @param conda_env Name of the conda environment.
7-
#' @param verbose Print messages.
8-
#'
5+
#'
6+
#' @param conda_env Name of the conda environment.
7+
#' @param verbose Print messages.
8+
#'
99
#' @inheritParams find_conda
1010
#' @inheritParams reticulate::conda_list
1111
#' @export
@@ -24,12 +24,6 @@ remove_env <- function(conda_env,
2424
#### Remove multiple ways ####
2525
for(env in envs){
2626
messager("Removing env:",env,v=verbose)
27-
## deactivateEnvironment was removed from basilisk.utils.
28-
## Clean up environment variables if this env is currently active.
29-
current_prefix <- Sys.getenv("CONDA_PREFIX", unset = "")
30-
if(nchar(current_prefix) > 0 && grepl(env, current_prefix, fixed = TRUE)){
31-
Sys.unsetenv("CONDA_PREFIX")
32-
}
3327
tryCatch({
3428
reticulate::conda_remove(envname = env,
3529
conda = conda_x)

0 commit comments

Comments
 (0)