Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: renv::remove_python #1850

Open
warnes opened this issue Mar 13, 2024 · 4 comments · May be fixed by #1851
Open

Feature Request: renv::remove_python #1850

warnes opened this issue Mar 13, 2024 · 4 comments · May be fixed by #1851

Comments

@warnes
Copy link

warnes commented Mar 13, 2024

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
@warnes
Copy link
Author

warnes commented Mar 13, 2024

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

@warnes
Copy link
Author

warnes commented Mar 13, 2024

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)
  }

}

@warnes warnes linked a pull request Mar 13, 2024 that will close this issue
@kevinushey
Copy link
Collaborator

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

@warnes
Copy link
Author

warnes commented Mar 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants