From 54a413d83d14cd13e3dbd31d3534634e23cabe62 Mon Sep 17 00:00:00 2001 From: Martin Petr Date: Tue, 19 Apr 2022 15:48:02 +0200 Subject: [PATCH] Update the handling of automatic Python env --- R/interface.R | 20 +++++++++++++++----- R/zzz.R | 2 +- man/setup_env.Rd | 9 +++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/R/interface.R b/R/interface.R index d35c7165e..ef87e53b3 100644 --- a/R/interface.R +++ b/R/interface.R @@ -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") || @@ -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) diff --git a/R/zzz.R b/R/zzz.R index fc44a2042..cfc3f8739 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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) { diff --git a/man/setup_env.Rd b/man/setup_env.Rd index a59b52699..874acb1c8 100644 --- a/man/setup_env.Rd +++ b/man/setup_env.Rd @@ -4,7 +4,7 @@ \alias{setup_env} \title{Setup a dedicated Python virtual environment for slendr} \usage{ -setup_env(quiet = FALSE, agree = FALSE, pip = TRUE) +setup_env(quiet = FALSE, agree = FALSE, pip = NULL) } \arguments{ \item{quiet}{Should informative messages be printed to the console? Default @@ -15,9 +15,10 @@ is \code{FALSE}.} \item{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.} } \description{ This function will automatically download a Python miniconda distribution