rstudio / renv

renv: Project environments for R.

Home Page:https://rstudio.github.io/renv/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: `renv::remove_python`

warnes opened this issue · comments

I have a project where I used renv::use_python() to start tracking python dependencies. Later, I no longer need to use python, but there doesn't seem to be a clean way to remove the python virtual environment and dependency tracking.

It looks like the steps to remove python are:

  1. Remove the "Python" JSON block from the top level of renv.lock.
  2. Remove the directory renv/python and its contents.
  3. Remove requirements.txt

It looks like exposing renv:::renv_python_deactivate(project) would enable (1)

Something like:

#'
#' @export
remove_python <- function(
    project = NULL,
    python_dir = TRUE,
    requirements_file = TRUE,
    prompt = interactive()
)
{
  flag <- !prompt || askYesNo("Stop renv from tracking Python version and packages?")
  if(is.na(flag))
    return()
  else if (isTRUE(flag))
  {
    renv_python_deactivate(project)
  }

  if(python_dir)
  {
    python_path <- renv_paths_renv('python') |> renv_path_canonicalize()
    flag <- !prompt || askYesNo(paste0("Remove '", python_path, "' and its contents?"))
    if(is.na(flag))
      return()
    else if (isTRUE(flag))
      unlink(python_path, recursive = TRUE)
  }

  if(requirements_file)
  {
    req_path <- renv_paths_renv('../requirements.txt') |> renv_path_canonicalize()
    flag <- !prompt || askYesNo(paste0("Remove '", req_path, "'?"))
    if(is.na(flag))
      return()
    else if (isTRUE(flag))
      unlink(python_path, recursive = TRUE)
  }

}

I think renv::use_python(FALSE) does something close to what you want here? Unfortunately it looks like it's not documented.

Thanks. It does look like renv::use_python(FALSE) accomplishes #1.