Skip to content

Commit

Permalink
Merge pull request #1457 from rstudio/report-broken-venvs
Browse files Browse the repository at this point in the history
Better error message for broken venvs
  • Loading branch information
t-kalinowski authored Aug 19, 2023
2 parents 41377f1 + b75ecc7 commit 69a240a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 19 additions & 2 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,30 @@ python_munge_path <- function(python) {

python_config_impl <- function(python) {

if(!file.exists(python)) {
# Test if `python` is broken symlink, which can happen with a venv if the
# venv starter is moved/removed
msg <- paste0("Error running ", shQuote(python), ": No such file.")
info <- python_info(python)
if (info$type == "virtualenv") {
msg <- paste0(sep = "", c(msg, "\n",
"The Python installation used to create the virtualenv has been moved or removed",
if(is.null(info$starter)) "." else ":\n ", shQuote(info$starter)
))
}
stop(msg)
}

script <- system.file("config/config.py", package = "reticulate")
config <- system2(
config <- tryCatch(system2(
command = python,
args = shQuote(script),
stdout = TRUE,
stderr = FALSE
)
), error = function(e) {
e$message <- paste(e$message, shQuote(python))
stop(e)
})

# check for error
status <- attr(config, "status")
Expand Down
9 changes: 8 additions & 1 deletion R/python-tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,19 @@ python_info_virtualenv <- function(path) {
python <- file.path(path, suffix)

# return details
list(
out <- list(
python = python,
type = "virtualenv",
root = path
)

if (file.exists(cfg <- file.path(out$root, "pyvenv.cfg"))) {
starter <- grep("^home = ", readLines(cfg), value = TRUE)
if(length(starter))
out$starter <- str_drop_prefix(starter, "home = ")
}

out
}

python_info_condaenv <- function(path) {
Expand Down

0 comments on commit 69a240a

Please sign in to comment.