Skip to content

Commit

Permalink
add conda_python() and virtualenv_python() functions for finding the …
Browse files Browse the repository at this point in the history
…python binary associated with an environment
  • Loading branch information
jjallaire committed Jul 27, 2018
1 parent 7869d13 commit e4bec3b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: reticulate
Type: Package
Title: Interface to 'Python'
Version: 1.9.0.9002
Version: 1.9.0.9003
Authors@R: c(
person("JJ", "Allaire", role = c("aut", "cre"), email = "jj@rstudio.com"),
person("Kevin", "Ushey", role = c("aut"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Expand Up @@ -79,6 +79,7 @@ export(conda_binary)
export(conda_create)
export(conda_install)
export(conda_list)
export(conda_python)
export(conda_remove)
export(conda_version)
export(dict)
Expand Down Expand Up @@ -145,6 +146,7 @@ export(use_virtualenv)
export(virtualenv_create)
export(virtualenv_install)
export(virtualenv_list)
export(virtualenv_python)
export(virtualenv_remove)
export(virtualenv_root)
importFrom(Matrix,sparseMatrix)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Expand Up @@ -19,6 +19,9 @@ Install the development version with: `install_github("rstudio/reticulate")`

- Support for iterating all types of Python iterable

- Add `conda_python()` and `virtualenv_python()` functions for finding the
python binary associated with an environment.


## reticulate 1.9 (CRAN)

Expand Down
10 changes: 10 additions & 0 deletions R/conda.R
Expand Up @@ -193,6 +193,16 @@ conda_version <- function(conda = "auto") {
system2(conda_bin, "--version", stdout = TRUE)
}

#' @rdname conda-tools
#' @export
conda_python <- function(envname, conda = "auto") {
env <- subset(conda_list(conda = conda), name == envname)
if (nrow(env) > 0)
path.expand(env$python[[1]])
else
stop("conda environment ", envname, " not found")
}



find_conda <- function() {
Expand Down
11 changes: 11 additions & 0 deletions R/virtualenv.R
Expand Up @@ -178,6 +178,17 @@ virtualenv_remove <- function(envname, packages = NULL, confirm = interactive())
invisible(NULL)
}

#' @rdname virtualenv-tools
#' @export
virtualenv_python <- function(envname) {
config <- virtualenv_config()
virtualenv_path <- file.path(config$root, envname)
if (utils::file_test("-d", virtualenv_path))
path.expand(file.path(virtualenv_path, "bin", "python"))
else
stop("virtualenv ", envname, " not found")
}


virtualenv_config <- function() {

Expand Down
3 changes: 3 additions & 0 deletions man/conda-tools.Rd

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

3 changes: 3 additions & 0 deletions man/virtualenv-tools.Rd

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

0 comments on commit e4bec3b

Please sign in to comment.