Skip to content

Commit

Permalink
Add option (and warning statement") about installing to user site pac…
Browse files Browse the repository at this point in the history
…kages with `--user` flag for #10

 - this is one of those "necessary footguns"
  • Loading branch information
brownag committed Dec 27, 2023
1 parent d1a5137 commit 83a4373
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions R/install_rosetta.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#' @param conda Default: `"auto"`
#' @param pip _logical_. Use `pip` for package installation? Default: `TRUE`. This is only relevant when Conda environments are used, as otherwise packages will be installed from the Conda repositories.
#' @param system _logical_. Default: `FALSE`. If `TRUE`, try installing to system (user) site library with `system()` and set reticulate to use system Python.
#' @param user _logical_. Default: `FALSE`. Pass `--user` flag. This should only be done if other installation methods fail and it is impossible to use a virtual environment.
#' @param arcpy_path Argument passed to `find_python()`. Path to ArcGIS Pro Python installation e.g. ``. Set as `NULL` (default) to prevent use of ArcGIS Pro instance.
#'
#' @details From `reticulate::py_install()`: On Linux and OS X the "virtualenv" method will be used by default ("conda" will be used if virtualenv isn't available). On Windows, the "conda" method is always used.
#'
#' @export
Expand All @@ -18,6 +20,7 @@ install_rosetta <- function(envname = NULL,
method = "auto",
conda = "auto",
pip = TRUE,
user = FALSE,
system = FALSE,
arcpy_path = getOption("rosettaPTF.arcpy_path")) {

Expand All @@ -26,14 +29,20 @@ install_rosetta <- function(envname = NULL,
find_python(envname = envname, arcpy_path = arcpy_path)
}

if (!is.null(arcpy_path) && dir.exists(arcpy_path)) {
p <- find_python(envname = envname, arcpy_path = arcpy_path)
system <- TRUE
} else {
p <- Sys.which("python")
}

if (isFALSE(system)) {
# get rosetta-soil (and numpy if needed)
try(reticulate::py_install("rosetta-soil", envname = envname, method = method, conda = conda, pip = pip),
silent = TRUE)
try(reticulate::py_install("rosetta-soil", envname = envname, method = method,
conda = conda, pip = pip, pip_options = ifelse(user, "--user", "")), silent = TRUE)
} else {
p <- Sys.which("python")
reticulate::use_python(p, required = TRUE)
system(paste(shQuote(p), "-m pip install --upgrade --user rosetta-soil"))
try(system(paste(shQuote(p), "-m pip install --upgrade --user rosetta-soil")), silent = TRUE)
}

# load modules globally in package (prevents having to reload rosettaPTF library in session)
Expand Down

0 comments on commit 83a4373

Please sign in to comment.