diff --git a/NAMESPACE b/NAMESPACE index a3dbf2245..c7acc1be2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,6 +31,7 @@ export(record) export(refresh) export(rehash) export(remove) +export(remove_python) export(repair) export(restore) export(revert) diff --git a/R/remove_python.R b/R/remove_python.R new file mode 100644 index 000000000..24bd1293a --- /dev/null +++ b/R/remove_python.R @@ -0,0 +1,53 @@ +#' Disable tracking python dependencies and remove associated files +#' +#' `remove_python` disables `renv` python dependency tracking and removes the +#' associated directories and files used by `renv`. +#' +#' @inherit renv-params +#' @param python_dir Remove the directory containing the Python environment and packages? +#' @param requirements_file Remove the Python requirements file? +#' @param prompt Prompt user before performing each action? +#' +#' @examples +#' \dontrun{ +#' remove_python() +#' } +#' +#' +#' @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) + } + +} diff --git a/man/remove_python.Rd b/man/remove_python.Rd new file mode 100644 index 000000000..2b2c5c009 --- /dev/null +++ b/man/remove_python.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/remove_python.R +\name{remove_python} +\alias{remove_python} +\title{Disable tracking python dependencies and remove associated files.} +\usage{ +remove_python( + project = NULL, + python_dir = TRUE, + requirements_file = TRUE, + prompt = interactive() +) +} +\arguments{ +\item{project}{The project directory. If \code{NULL}, then the active project will +be used. If no project is currently active, then the current working +directory is used instead.} + +\item{python_dir}{Remove the directory containing the Python environment and packages?} + +\item{requirements_file}{Remove the Python requirements file?} + +\item{prompt}{Prompt user before performing each action?} +} +\value{ +The project directory, invisibly. Note that this function is normally +called for its side effects. +} +\description{ +\code{remove_python} disables \code{renv} python dependency tracking and removes the +associated directories and files used by \code{renv}. +} +\examples{ +\dontrun{ + remove_python() +} + + +}