diff --git a/R/basiliskStart.R b/R/basiliskStart.R index 8452df0..2792555 100644 --- a/R/basiliskStart.R +++ b/R/basiliskStart.R @@ -79,6 +79,15 @@ #' \code{\link{getBasiliskFork}} and \code{\link{getBasiliskShared}}, to control various global options. #' #' @examples +#' ################################################## +#' # Creating virtualenvs in a temporary directory to +#' # avoid polluting the user's WORKON_HOME. +#' tmploc <- file.path(tempdir(), "basilisk") +#' dir.create(tmploc) +#' old <- Sys.getenv("WORKON_HOME") +#' Sys.setenv(WORKON_HOME=tmploc) +#' ################################################## +#' #' # Loading one virtual environment into our R session: #' setupVirtualEnv('my_package_A', c('pandas==0.25.3', #' "python-dateutil==2.8.1", "pytz==2019.3")) @@ -110,6 +119,11 @@ #' # Close persistent processes to avoid errors during CHECK. #' basiliskStop(cl, persist=FALSE) #' } +#' +#' ################################################## +#' # Restoring the old WORKON_HOME. +#' Sys.setenv(WORKON_HOME=old) +#' ################################################## #' @export #' @importFrom parallel makePSOCKcluster clusterCall makeForkCluster #' @importFrom reticulate py_config py_available diff --git a/R/setupVirtualEnv.R b/R/setupVirtualEnv.R index d19f1df..5ad3fc0 100644 --- a/R/setupVirtualEnv.R +++ b/R/setupVirtualEnv.R @@ -42,6 +42,15 @@ #' In such cases, the compatible versions of the core packages must again be explicitly listed in \code{packages}. #' #' @examples +#' ################################################## +#' # Creating virtualenvs in a temporary directory to +#' # avoid polluting the user's WORKON_HOME. +#' tmploc <- file.path(tempdir(), "basilisk") +#' dir.create(tmploc) +#' old <- Sys.getenv("WORKON_HOME") +#' Sys.setenv(WORKON_HOME=tmploc) +#' ################################################## +#' #' setupVirtualEnv('my_package_A', c('pandas==0.25.3', #' "python-dateutil==2.8.1", "pytz==2019.3")) #' useVirtualEnv("my_package_A") @@ -51,7 +60,11 @@ #' # No need to list versions of core packages, #' # or to list them at all if they are dependencies. #' setupVirtualEnv('my_package_A_alt', 'pandas') -#' +#' +#' ################################################## +#' # Restoring the old WORKON_HOME. +#' Sys.setenv(WORKON_HOME=old) +#' ################################################## #' @seealso #' \code{\link{listCorePackages}}, for a list of core Python packages with pinned versions. #' diff --git a/R/useVirtualEnv.R b/R/useVirtualEnv.R index 6f9fb5a..8066d40 100644 --- a/R/useVirtualEnv.R +++ b/R/useVirtualEnv.R @@ -25,9 +25,22 @@ #' @author Aaron Lun #' #' @examples +#' ################################################## +#' # Creating virtualenvs in a temporary directory to +#' # avoid polluting the user's WORKON_HOME. +#' tmploc <- file.path(tempdir(), "basilisk") +#' dir.create(tmploc) +#' old <- Sys.getenv("WORKON_HOME") +#' Sys.setenv(WORKON_HOME=tmploc) +#' ################################################## +#' #' setupVirtualEnv('my_package_A_alt', 'pandas') #' useVirtualEnv("my_package_A_alt") #' +#' ################################################## +#' # Restoring the old WORKON_HOME. +#' Sys.setenv(WORKON_HOME=old) +#' ################################################## #' @seealso #' \code{\link{basiliskStart}}, for how these virtual environments should be used. #' diff --git a/man/basiliskStart.Rd b/man/basiliskStart.Rd index a1b38ca..958a95b 100644 --- a/man/basiliskStart.Rd +++ b/man/basiliskStart.Rd @@ -112,6 +112,15 @@ This mostly refers to objects that contain custom pointers to memory, e.g., file } \examples{ +################################################## +# Creating virtualenvs in a temporary directory to +# avoid polluting the user's WORKON_HOME. +tmploc <- file.path(tempdir(), "basilisk") +dir.create(tmploc) +old <- Sys.getenv("WORKON_HOME") +Sys.setenv(WORKON_HOME=tmploc) +################################################## + # Loading one virtual environment into our R session: setupVirtualEnv('my_package_A', c('pandas==0.25.3', "python-dateutil==2.8.1", "pytz==2019.3")) @@ -143,6 +152,11 @@ basiliskStop(cl) # Close persistent processes to avoid errors during CHECK. basiliskStop(cl, persist=FALSE) } + +################################################## +# Restoring the old WORKON_HOME. +Sys.setenv(WORKON_HOME=old) +################################################## } \seealso{ \code{\link{setupVirtualEnv}}, to set up the virtual environments. diff --git a/man/setupVirtualEnv.Rd b/man/setupVirtualEnv.Rd index 7002fb8..ed55224 100644 --- a/man/setupVirtualEnv.Rd +++ b/man/setupVirtualEnv.Rd @@ -54,6 +54,15 @@ In such cases, the compatible versions of the core packages must again be explic } \examples{ +################################################## +# Creating virtualenvs in a temporary directory to +# avoid polluting the user's WORKON_HOME. +tmploc <- file.path(tempdir(), "basilisk") +dir.create(tmploc) +old <- Sys.getenv("WORKON_HOME") +Sys.setenv(WORKON_HOME=tmploc) +################################################## + setupVirtualEnv('my_package_A', c('pandas==0.25.3', "python-dateutil==2.8.1", "pytz==2019.3")) useVirtualEnv("my_package_A") @@ -64,6 +73,10 @@ X$`__version__` # or to list them at all if they are dependencies. setupVirtualEnv('my_package_A_alt', 'pandas') +################################################## +# Restoring the old WORKON_HOME. +Sys.setenv(WORKON_HOME=old) +################################################## } \seealso{ \code{\link{listCorePackages}}, for a list of core Python packages with pinned versions. diff --git a/man/useVirtualEnv.Rd b/man/useVirtualEnv.Rd index a183428..1b2d99f 100644 --- a/man/useVirtualEnv.Rd +++ b/man/useVirtualEnv.Rd @@ -35,9 +35,22 @@ A side-effect of \code{useVirtualEnv} with \code{dry=FALSE} is that the \code{"P This is a deliberate choice to avoid compromising the version guarantees if \code{\link{import}} is allowed to search other locations beyond the virtual environment. } \examples{ +################################################## +# Creating virtualenvs in a temporary directory to +# avoid polluting the user's WORKON_HOME. +tmploc <- file.path(tempdir(), "basilisk") +dir.create(tmploc) +old <- Sys.getenv("WORKON_HOME") +Sys.setenv(WORKON_HOME=tmploc) +################################################## + setupVirtualEnv('my_package_A_alt', 'pandas') useVirtualEnv("my_package_A_alt") +################################################## +# Restoring the old WORKON_HOME. +Sys.setenv(WORKON_HOME=old) +################################################## } \seealso{ \code{\link{basiliskStart}}, for how these virtual environments should be used.