Skip to content

Commit

Permalink
Add using_conda() for detecting Conda environments (closes #7)
Browse files Browse the repository at this point in the history
- Also fix typo in `using_nix_shell()` tests
  • Loading branch information
briandconnelly committed Sep 30, 2023
1 parent 7e826ea commit 6b9eb6f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(using_arm_cpu)
export(using_ci)
export(using_circle_ci)
export(using_codebuild)
export(using_conda)
export(using_config)
export(using_container)
export(using_covr)
Expand Down
17 changes: 17 additions & 0 deletions R/conda.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' @rdname conda
#' @title Determine whether Conda environment is being used
#'
#' @param env Optional environment name to compare against
#'
#' @return A logical value
#' @export
#'
#' @examples
#' # Check if Conda is being used (regardless of environment name)
#' using_conda()
#'
#' # Check if the 'dev' Conda environment is being used
#' using_conda(env = "dev")
using_conda <- function(env = NULL) {
using_envvar("CONDA_DEFAULT_ENV", value = env)
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ reference:
- using_rstudio_dark_theme
- using_vscode
- using_interactive_session
- using_conda

- title: Continuous Integration
desc: Determine whether code is being run in a continuous integration environment
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CMD
CircleCI
CodeBuild
Codecov
Conda
Databricks
GitLab
Lifecycle
Expand Down
24 changes: 24 additions & 0 deletions man/conda.Rd

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

18 changes: 18 additions & 0 deletions tests/testthat/test-conda.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
test_that("using_conda validates input properly", {
expect_error(using_conda(env = NA_character_))
expect_error(using_conda(env = 1))
expect_error(using_conda(env = c("dev", "prod")))
})

test_that("using_conda works as expected when `CONDA_DEFAULT_ENV` not set", {
withr::local_envvar(list("CONDA_DEFAULT_ENV" = NA))
expect_false(using_conda())
expect_false(using_conda(env = "dev"))
})

test_that("using_conda works as expected in 'dev' environment", {
withr::local_envvar(list("CONDA_DEFAULT_ENV" = "dev"))
expect_true(using_conda())
expect_true(using_conda(env = "dev"))
expect_false(using_conda(env = "prod"))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-nix.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("using_nix_shell validates input properly", {
expect_error(using_nix_shell(pure = NA_character_))
expect_error(using_nix_shell(pure = 1))
expect_error(using_nux_shell(pure = "pure"))
expect_error(using_nix_shell(pure = "pure"))
expect_error(using_nix_shell(pure = c(TRUE, TRUE)))
})

Expand Down

0 comments on commit 6b9eb6f

Please sign in to comment.