Skip to content

Commit

Permalink
Merge pull request #13 from ncss-tech/install-system
Browse files Browse the repository at this point in the history
install_rosetta `system` argument
  • Loading branch information
brownag authored Dec 27, 2023
2 parents 2efe081 + 01894cb commit 512f3f4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions R/find_python.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ find_python <- function(envname = NULL,
options(rosettaPTF.python_path = PYEXE_PATH)
options(rosettaPTF.arcpy_path = arcpy_path)

subres
}, silent = TRUE)
subres[grep("envs/arcgispro-py3", subres, fixed = TRUE)]
}, silent = FALSE)

# User can/should use regular reticulate methods for this

Expand Down
25 changes: 21 additions & 4 deletions R/install_rosetta.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#' @param method `"auto"`, `"virtualenv"`, or `"conda"`; Default: `"auto"`
#' @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 @@ -17,18 +20,32 @@ install_rosetta <- function(envname = NULL,
method = "auto",
conda = "auto",
pip = TRUE,
user = FALSE,
system = FALSE,
arcpy_path = getOption("rosettaPTF.arcpy_path")) {

# use heuristics to find python executable
if (!is.null(arcpy_path) && dir.exists(arcpy_path)) {
find_python(envname = envname, arcpy_path = arcpy_path)
}

# get rosetta-soil (and numpy if needed)
try(reticulate::py_install("rosetta-soil", envname = envname, method = method, conda = conda, pip = pip),
silent = TRUE)
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, pip_options = ifelse(user, "--user", "")), silent = TRUE)
} else {
reticulate::use_python(p, required = TRUE)
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)
# load modules globally in package (prevents having to reload rosettaPTF library in session)
.loadModules()

}
6 changes: 6 additions & 0 deletions man/install_rosetta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-install_rosetta.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test_that("rosetta-soil module can be installed", {
cat("\n\n")

# use pip (if available) or use ArcGIS Pro Conda environment (if available)
res <- try(install_rosetta(pip = TRUE, arcpy_path = "C:/Program Files/ArcGIS/Pro/bin/Python/"))
res <- try(install_rosetta(system = TRUE, arcpy_path = "C:/Program Files/ArcGIS/Pro/bin/Python/"))

if (inherits(res, 'try-error'))
skip("Unable to install")
Expand Down

0 comments on commit 512f3f4

Please sign in to comment.