Skip to content

Commit 738d143

Browse files
committed
add conda to ci; clean up public API
1 parent 9037a18 commit 738d143

File tree

6 files changed

+60
-62
lines changed

6 files changed

+60
-62
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,67 @@ on:
33
branches: [main, master]
44
pull_request:
55
branches: [main, master]
6+
67
name: R-CMD-check
8+
79
jobs:
810
R-CMD-check:
911
runs-on: ${{ matrix.os }}
10-
name: ${{ matrix.os }} (${{ matrix.r }})
12+
name: ${{ matrix.os }} (${{ matrix.r }}) - ${{ matrix.backend }}
13+
1114
strategy:
1215
fail-fast: false
1316
matrix:
1417
include:
15-
- { os: "ubuntu-latest", python: "3.13", r: "release" }
16-
- { os: "windows-latest", python: "3.13", r: "release" }
17-
- { os: "macOS-latest", python: "3.13", r: "release" }
18-
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-1" }
19-
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-2" }
20-
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-3" }
18+
- { os: "ubuntu-latest", python: "3.13", r: "release", backend: "venv" }
19+
- { os: "ubuntu-latest", python: "3.13", r: "release", backend: "conda" }
20+
21+
- { os: "windows-latest", python: "3.13", r: "release", backend: "venv" }
22+
- { os: "windows-latest", python: "3.13", r: "release", backend: "conda" }
23+
24+
- { os: "macOS-latest", python: "3.13", r: "release", backend: "venv" }
25+
- { os: "macOS-latest", python: "3.13", r: "release", backend: "conda" }
26+
27+
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-1", backend: "venv" }
28+
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-2", backend: "venv" }
29+
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-3", backend: "venv" }
30+
2131
env:
2232
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
2333
R_KEEP_PKG_SOURCE: yes
2434
MPLBACKEND: Agg
35+
ACRO_USE_CONDA: ${{ matrix.backend == 'conda' && 'true' || 'false' }}
36+
2537
steps:
2638
- name: Checkout ACRO
2739
uses: actions/checkout@v4
40+
41+
- name: Setup Miniconda
42+
if: matrix.backend == 'conda'
43+
uses: conda-incubator/setup-miniconda@v3
44+
with:
45+
python-version: ${{ matrix.python }}
46+
auto-activate-base: false
47+
2848
- name: Setup Python
2949
uses: actions/setup-python@v6
3050
with:
3151
python-version: ${{ matrix.python }}
52+
3253
- name: Setup pandoc
3354
uses: r-lib/actions/setup-pandoc@v2
55+
3456
- name: Setup R
3557
uses: r-lib/actions/setup-r@v2
3658
with:
3759
r-version: ${{ matrix.r }}
60+
3861
- name: Install R dependencies
3962
uses: r-lib/actions/setup-r-dependencies@v2
4063
with:
4164
extra-packages: any::rcmdcheck
4265
needs: check
66+
4367
- name: Check R Package
4468
uses: r-lib/actions/check-r-package@v2
4569
with:

R/acro_init.R

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ acro_pkg <- "acro==0.4.11"
44
ch <- "conda-forge"
55

66

7-
#' Resolve Python executable
8-
#'
9-
#' @return String path to a Python executable.
7+
# Internal helper: resolve Python executable
108
## nocov start
119
get_python <- function() {
1210
python <- Sys.which("python3")
@@ -21,9 +19,7 @@ get_python <- function() {
2119
## nocov end
2220

2321

24-
#' Install ACRO in a conda environment
25-
#'
26-
#' @param envname Name of the conda environment
22+
# Internal helper: install ACRO in a Conda environment
2723
## nocov start
2824
install_conda <- function(envname) { # nocov
2925
if (!reticulate::condaenv_exists(envname = envname, conda = "auto")) {
@@ -34,9 +30,7 @@ install_conda <- function(envname) { # nocov
3430
## nocov end
3531

3632

37-
#' Initialise ACRO in a Python virtual environment
38-
#'
39-
#' @param envname Name of the virtual environment
33+
# Internal helper: install ACRO in a Python virtual environment
4034
install_venv <- function(envname = acro_venv) {
4135
if (!reticulate::virtualenv_exists(envname)) {
4236
python <- get_python()
@@ -53,15 +47,35 @@ install_venv <- function(envname = acro_venv) {
5347
}
5448

5549

50+
# Internal helper: resolve whether Conda should be used
51+
get_use_conda <- function(use_conda = NULL) {
52+
if (is.null(use_conda)) {
53+
use_conda <- tolower(Sys.getenv("ACRO_USE_CONDA")) %in% c("1", "true", "yes")
54+
}
55+
use_conda <- isTRUE(use_conda) # default FALSE
56+
57+
if (use_conda && is.null(reticulate::conda_binary())) { # nocov
58+
stop("Conda requested but no Miniconda installation found", call. = FALSE) # nocov
59+
}
60+
61+
return(use_conda)
62+
}
63+
64+
5665
#' Initialise an ACRO object
5766
#'
5867
#' @param suppress Whether to automatically apply suppression.
5968
#' @param envname Name of the Python environment to use.
60-
#' @param use_conda Whether to use a Conda environment (`TRUE`) or venv (`FALSE`).
69+
#' @param use_conda Whether to use a Conda environment.
70+
#' If `NULL`, looks for environment variable `ACRO_USE_CONDA`,
71+
#' defaults to `FALSE` if unset.
6172
#'
6273
#' @return Invisibly returns the ACRO object, which is used internally.
6374
#' @export
64-
acro_init <- function(suppress = FALSE, envname = acro_venv, use_conda = FALSE) {
75+
acro_init <- function(suppress = FALSE, envname = acro_venv, use_conda = NULL) {
76+
# define the environment
77+
use_conda <- get_use_conda(use_conda)
78+
6579
# initialise the environment
6680
if (!reticulate::py_available(initialize = FALSE)) {
6781
if (use_conda) { # nocov

man/acro_init.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_python.Rd

Lines changed: 0 additions & 14 deletions
This file was deleted.

man/install_conda.Rd

Lines changed: 0 additions & 14 deletions
This file was deleted.

man/install_venv.Rd

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)