diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..61ff1dd --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,78 @@ +name: R-CMD-check + +on: + pull_request: + branches: + - master + - dev + +permissions: + contents: read + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (R ${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: windows-latest, r: '4.6.1'} + - {os: macOS-latest, r: '4.6.1'} + - {os: ubuntu-latest, r: '4.6.1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + use-public-rspm: true + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Create animl_env and install animl-py + shell: bash + run: | + VENV_DIR="$HOME/.virtualenvs/animl_env" + python -m venv "$VENV_DIR" + + if [[ "$RUNNER_OS" == "Windows" ]]; then + PYTHON_BIN="$VENV_DIR/Scripts/python.exe" + else + PYTHON_BIN="$VENV_DIR/bin/python" + fi + + "$PYTHON_BIN" -m pip install --upgrade pip + "$PYTHON_BIN" -m pip install animl + + echo "WORKON_HOME=$HOME/.virtualenvs" >> "$GITHUB_ENV" + echo "RETICULATE_PYTHON=$PYTHON_BIN" >> "$GITHUB_ENV" + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - name: Check + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + ONNXRUNTIME_LOGLEVEL: 4 + run: | + rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran", "--no-tests"), error_on = "warning", check_dir = "check") + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results + path: check diff --git a/R/install.R b/R/install.R index fbd4941..0bc1959 100644 --- a/R/install.R +++ b/R/install.R @@ -1,6 +1,16 @@ # VARIABLE FOR VERSION ANIML_VERSION <- "3.3.1" +animl_module_installed <- function() { + tryCatch( + { + importlib_util <- reticulate::import("importlib.util") + !is.null(importlib_util$find_spec("animl")) + }, + error = function(e) FALSE + ) +} + #' Load animl-py if available #' #' @param envname name of python environment @@ -55,9 +65,20 @@ load_animl <- function(envname = "animl_env", } # env exists else { + if (!interactive) { + if (animl_module_installed()) { + assign( + "animl_py", + reticulate::import("animl", delay_load = TRUE), + envir = .animl_internal + ) + } + return(invisible()) + } + # check animl-py installed msg("\n2. Checking animl-py version...") - if (reticulate::py_module_available("animl")) { + if (animl_module_installed()) { animl_py <- reticulate::import("animl", delay_load = TRUE) animl_py_version <- animl_py$'__version__' @@ -71,8 +92,10 @@ load_animl <- function(envname = "animl_env", msg(sprintf("animl %s successfully loaded.", ANIML_VERSION)) assign("animl_py", animl_py, envir = .animl_internal) } - # 4) Check external dependencies - check_animl_py() + # 4) Check external dependencies when interactive + if (interactive) { + check_animl_py() + } } # animl_env exists but animl-py not installed else { @@ -322,12 +345,21 @@ animl_install_instructions <- function() { #' #' @export check_animl_py <- function(){ - if(reticulate::py_module_available("animl")){ + if(animl_module_installed()){ animl_py <- reticulate::import("animl", delay_load = TRUE) - exif <- animl_py$check_exiftool() - torch_cuda <- animl_py$check_torch_cuda() - torch_onnx <- animl_py$check_onnx_cuda() + exif <- tryCatch( + animl_py$check_exiftool(), + error = function(e) FALSE + ) + torch_cuda <- tryCatch( + animl_py$check_torch_cuda(), + error = function(e) FALSE + ) + torch_onnx <- tryCatch( + animl_py$check_onnx_cuda(), + error = function(e) FALSE + ) if(interactive()){ message(sprintf("Exiftool installed and available: %s", as.character(exif)))