Feature Request: `renv::remove_python`
warnes opened this issue · comments
Gregory R. Warnes commented
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:
- Remove the "Python" JSON block from the top level of
renv.lock
. - Remove the directory
renv/python
and its contents. - Remove
requirements.txt
Gregory R. Warnes commented
It looks like exposing renv:::renv_python_deactivate(project)
would enable (1)
Gregory R. Warnes commented
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)
}
}
Kevin Ushey commented
I think renv::use_python(FALSE)
does something close to what you want here? Unfortunately it looks like it's not documented.
Gregory R. Warnes commented
Thanks. It does look like renv::use_python(FALSE)
accomplishes #1.