Skip to content

Commit

Permalink
Add force=TRUE when installing local repo [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Oct 11, 2023
1 parent c0dabce commit 059489c
Show file tree
Hide file tree
Showing 16 changed files with 614 additions and 549 deletions.
954 changes: 477 additions & 477 deletions .Rhistory

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Suggests:
jsonlite,
BiocStyle,
BiocPkgTools,
biocViews
biocViews,
reticulate
VignetteBuilder: knitr
License: GPL-3
Config/testthat/edition: 3
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@
- `channels`
- New function to construct conda env yaml files:
- `construct_conda_yml`
- New unit tests to test `construct_conda_yml` and building conda envs
from the generated yamls.
* `fill_yaml`
- Add subfunction `is_default`

## Bug fixes

* `no visible global function definition for internal function check_miniconda_args`
- This weird error only came up during Rstudio R CMD checks.
The function `check_miniconda_args` was clearly defined in its own file.
The only way to fix it was copying the function into the same one where it
was called `fill_yaml`.
- Thought it might be a permissions issues with *check_miniconda_args.R* but
the permissions are identical with all the others.

# rworkflows 0.99.13

## New features
Expand Down
43 changes: 0 additions & 43 deletions R/check_miniconda_args.R

This file was deleted.

4 changes: 4 additions & 0 deletions R/conda_installed.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
conda_installed <- function(){
requireNamespace("reticulate")
utils::getFromNamespace("conda_installed","reticulate")()
}
4 changes: 4 additions & 0 deletions R/condaenv_exists.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
condaenv_exists <- function(...){
requireNamespace("reticulate")
utils::getFromNamespace("condaenv_exists","reticulate")(...)
}
14 changes: 10 additions & 4 deletions R/construct_conda_yml.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#' @export
#' @importFrom yaml read_yaml
#' @examples
#' yml <- construct_conda_yml(name="sc_env",
#' yml <- construct_conda_yml(name="myenv",
#' dependencies=c("anndata","scanpy"),
#' return_path = FALSE)
#' return_path = FALSE,
#' ## Writing to temp only for example
#' save_path=tempfile(fileext="myenv_conda.yml"))
construct_conda_yml <- function(name = "test",
channels = list("conda-forge",
"nodefaults"),
Expand All @@ -34,13 +36,16 @@ construct_conda_yml <- function(name = "test",
){
# devoptera::args2vars(construct_conda_yml)

if(is.vector(dependencies)) dependencies <- as.list(dependencies)
if(is.vector(pip)) pip <- as.list(pip)
yml <- list(
name=name,
channels=channels,
dependencies=dependencies
)
if(!is.null(pip)){
yml[["pip"]] <- pip
yml[["dependencies"]] <- c(unique(c(yml[["dependencies"]],"pip")),
list(list(pip=pip)))
}
#### Preview ####
if(isTRUE(preview)){
Expand All @@ -50,6 +55,7 @@ construct_conda_yml <- function(name = "test",
path_or_yaml <- return_yaml(yml=yml,
path=save_path,
return_path=return_path,
verbose=verbose)
verbose=verbose,
indent.mapping.sequence = TRUE)
return(path_or_yaml)
}
47 changes: 47 additions & 0 deletions R/fill_yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,50 @@ fill_yaml <- function(## function-level args
}
return(yml)
}


#' Check Miniconda arguments
#'
#' Check Miniconda arguments for compatibility with one another.
#' @inheritParams use_workflow
#' @returns Named list of updated args.
#'
#' @keywords internal
check_miniconda_args <- function(runners,
miniforge_variant,
miniforge_version,
activate_environment,
environment_file,
channels,
verbose=TRUE){

for(a in c("miniforge_version",
"environment_file",
"activate_environment")){
if(!is_default(arg=a, val=get(a), func="use_workflow") &&
isFALSE(miniforge_variant)){
messager(a,"supplied. Enabling miniforge.", v=verbose)
miniforge_variant <- TRUE
}
}
#### Check if python-version set ####
if(isTRUE(miniforge_variant)) {
#### Check runners ####
for(r in runners){
if(is.null(r$`python-version`)){
messager("python-version not set for runner",
paste0("os=",shQuote(r$os),"."),
"Using default.",v=verbose)
}
}
}
if(isTRUE(miniforge_variant)) miniforge_variant <- ""
return(list(
miniforge_variant=miniforge_variant,
miniforge_version=miniforge_version,
activate_environment=activate_environment,
environment_file=environment_file,
channels=channels
))
}

8 changes: 6 additions & 2 deletions R/return_yaml.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
return_yaml <- function(yml,
path,
return_path,
verbose=TRUE){
handlers=NULL,
verbose=TRUE,
...){
if(!is.null(path)){
save_yaml(yml=yml,
path=path,
verbose=verbose)
handlers=handlers,
verbose=verbose,
...)
#### Return ####
if(isTRUE(return_path)){
return(path)
Expand Down
14 changes: 8 additions & 6 deletions R/save_yaml.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
save_yaml <- function(yml,
path,
verbose=TRUE){
handlers=NULL,
verbose=TRUE,
...){

dir.create(dirname(path),showWarnings = FALSE, recursive = TRUE)
messager("Saving yaml ==>",path,v=verbose)
#### Write bools as true/false rather than yes/no (default) ####
handlers2 <- list('bool#yes' = function(x){"${{ true }}"},
'bool#no' = function(x){"${{ false }}"})
yml2 <- yaml::yaml.load(yaml::as.yaml(yml),
handlers = handlers2)
yaml::write_yaml(x = yml2,
if(!is.null(handlers)){
yml <- yaml::yaml.load(yaml::as.yaml(yml),
handlers = handlers)
}
yaml::write_yaml(x = yml,
file = path)
}
3 changes: 3 additions & 0 deletions R/use_workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,12 @@ use_workflow <- function(## action-level args
preview_yaml(yml=yml)
}
#### Save yaml ####
handlers <- list('bool#yes' = function(x){"${{ true }}"},
'bool#no' = function(x){"${{ false }}"})
path_or_yaml <- return_yaml(yml=yml,
path=path,
return_path=return_path,
handlers=handlers,
verbose=verbose)
return(path_or_yaml)
}
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ runs:
install.packages(c("rmarkdown","BiocManager"), dependencies = TRUE)
message(paste('****', Sys.time(), 'pass number 1 at installing dependencies****'))
repos <- BiocManager::repositories()
remotes::install_local(repos=repos, dependencies=TRUE, build_vignettes=FALSE, upgrade=TRUE)
remotes::install_local(repos=repos, dependencies=TRUE, build_vignettes=FALSE, upgrade=TRUE, force=TRUE)
continue-on-error: true
shell: Rscript {0}

Expand All @@ -314,7 +314,7 @@ runs:
options(crayon.enabled = TRUE, timeout=Sys.getenv("timeout"))
message(paste('****', Sys.time(), 'pass number 2 at installing dependencies****'))
repos <- BiocManager::repositories()
remotes::install_local(repos=repos, dependencies=TRUE, build_vignettes=FALSE, upgrade=TRUE)
remotes::install_local(repos=repos, dependencies=TRUE, build_vignettes=FALSE, upgrade=TRUE, force=TRUE)
shell: Rscript {0}

- name: Install RUnit (via BiocGenerics) 🛠
Expand Down
6 changes: 3 additions & 3 deletions man/check_miniconda_args.Rd

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

6 changes: 4 additions & 2 deletions man/construct_conda_yml.Rd

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

39 changes: 31 additions & 8 deletions tests/testthat/test-construct_conda_yml.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
test_that("construct_conda_yml works", {

path1 <- construct_conda_yml(name="sc_env",
save_path <- tempfile(fileext = "myenv_conda.yml")
path1 <- construct_conda_yml(name="myenv",
dependencies=c("anndata","scanpy"),
return_path = TRUE)
return_path = TRUE,
save_path = save_path)
testthat::expect_true(file.exists(path1))

yml1 <- construct_conda_yml(name="sc_env",
yml1 <- construct_conda_yml(name="myenv",
dependencies=c("anndata","scanpy"),
return_path = FALSE)
return_path = FALSE,
save_path = save_path)
testthat::expect_true(all(c("name","channels","dependencies") %in% names(yml1)))

yml2 <- construct_conda_yml(name="sc_env",
yml2 <- construct_conda_yml(name="myenv",
dependencies=c("anndata>=1.0","scanpy<20.1.1"),
pip = c("pip","mytool1","mtool2"),
return_path = FALSE)
return_path = FALSE,
save_path = save_path)
testthat::expect_true(all(c("name","channels","dependencies","pip") %in% names(yml2)))

yml3 <- construct_conda_yml(name="sc_env",
yml3 <- construct_conda_yml(name="myenv",
dependencies=c("anndata","scanpy"),
save_path = NULL,
return_path = TRUE)
preview = TRUE,
return_path = TRUE,
save_path = save_path)
testthat::expect_true(all(c("name","channels","dependencies") %in% names(yml3)))


#### Construct an actual conda env ####
if(conda_installed() && is_gha()){
envname <- "testenv"
if(condaenv_exists(envname)){
reticulate::conda_remove(envname = envname)
}
path2 <- construct_conda_yml(name=envname,
dependencies=list("python"),
pip=list("requests"),
preview = TRUE,
return_path = TRUE,
save_path = save_path)
out <- reticulate::conda_create(environment = path2)
}

})
2 changes: 1 addition & 1 deletion tests/testthat/test-infer_biocviews.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("infer_biocviews works", {
)
} else {
testthat::expect_equal(infer_biocviews(include_branch = FALSE),
"WorkflowManagement")
c("`Software","WorkflowManagement"))
}
biocviews_manual = c("Software","Genetics","Transcriptomics")
if(testthat::is_testing() && !is_gha()){
Expand Down

0 comments on commit 059489c

Please sign in to comment.