Skip to content

Commit

Permalink
Update the handling of automatic Python env
Browse files Browse the repository at this point in the history
  • Loading branch information
bodkan committed Apr 19, 2022
1 parent e4aca4b commit 54a413d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
20 changes: 15 additions & 5 deletions R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -1259,12 +1259,13 @@ seconds, but if you don't want to wait, you can set `snapshots = N` manually.")
#' @param pip Should pip be used instead of conda for installing slendr's Python
#' dependencies? Note that this will still use the conda distribution to
#' install Python itself, but will change the repository from which slendr
#' will install its Python dependencies. This option is set to \code{TRUE} by
#' default, because in testing across different platforms, in all situations
#' in which conda failed to satisfy a dependency, pip had worked every time.
#' will install its Python dependencies. Unless explicitly set to \code{TRUE},
#' Python dependencies will be installed from conda repositories by default,
#' expect for the case of osx-arm64 Mac architecture, for which conda
#' dependencies are broken.
#'
#' @export
setup_env <- function(quiet = FALSE, agree = FALSE, pip = TRUE) {
setup_env <- function(quiet = FALSE, agree = FALSE, pip = NULL) {
if (check_env_present()) {
reticulate::use_condaenv(PYTHON_ENV, required = TRUE)
if (!reticulate::py_module_available("msprime") ||
Expand Down Expand Up @@ -1305,7 +1306,16 @@ setup_env <- function(quiet = FALSE, agree = FALSE, pip = TRUE) {
# parse the Python env name back to the list of dependencies
# (the environment is defined in .onAttach(), and this makes sure the
# dependencies are defined all in one place)
deps <- PYTHON_ENV %>% gsub("-", "==", .) %>% strsplit("_") %>% .[[1]]
version_deps <- PYTHON_ENV %>% gsub("-", "==", .) %>% strsplit("_") %>% .[[1]]
other_deps <- c("pandas", "radian")
deps <- c(version_deps, other_deps)

# msprime/tskit conda dependency is broken on M1 Mac architecture, fallback
# to pip in cases like this (otherwise use conda to avoid any potential
# compilation issues such as missing libgsl)
if (is.null(pip))
pip <- all(Sys.info()[c("sysname", "machine")] == c("Darwin", "arm64"))

reticulate::conda_install(envname = PYTHON_ENV, packages = deps, pip = pip)

if (!quiet)
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msp <- NULL

# define slendr's required Python dependencies and compose an environment name
# that will be used specifically for them
deps <- c("msprime==1.1.1", "tskit==0.4.1", "pyslim==0.700", "pandas")
deps <- c("msprime==1.1.1", "tskit==0.4.1", "pyslim==0.700")
PYTHON_ENV <- paste(gsub("==", "-", deps), collapse = "_")

.onAttach <- function(libname, pkgname) {
Expand Down
9 changes: 5 additions & 4 deletions man/setup_env.Rd

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

0 comments on commit 54a413d

Please sign in to comment.