From 5553a5c3f43e6e6c0e17ddd9b6678749a57e5952 Mon Sep 17 00:00:00 2001 From: serkor1 <77464572+serkor1@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:48:59 +0100 Subject: [PATCH] Robust setup-reticulate :hammer: * Added tryCatch for fallbacks * Updated action version --- .github/actions/setup-reticulate/action.yml | 51 ++++++++++---- .github/workflows/macos-check-gcc.yaml | 75 --------------------- README.md | 1 + README.qmd | 1 + 4 files changed, 40 insertions(+), 88 deletions(-) delete mode 100644 .github/workflows/macos-check-gcc.yaml diff --git a/.github/actions/setup-reticulate/action.yml b/.github/actions/setup-reticulate/action.yml index fada204..be0e7c0 100644 --- a/.github/actions/setup-reticulate/action.yml +++ b/.github/actions/setup-reticulate/action.yml @@ -22,7 +22,7 @@ runs: sudo apt-get install -y python3-venv - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ inputs.python-version }} @@ -32,21 +32,46 @@ runs: PYTHON_VERSION: ${{ inputs.python-version }} run: | - # 2) create virtual environment + # 1) create virtual environment # with specified version - path_to_python <- reticulate::virtualenv_create( - envname = "r-reticulate", - python_version = Sys.getenv("PYTHON_VERSION"), - packages = c( - "numpy", - "scipy", - "torch", - "torchmetrics", - "scikit-learn", - "imblearn" - ) + + path_to_python <- tryCatch( + expr = { + + reticulate::virtualenv_create( + envname = "r-reticulate", + python = Sys.which("python"), + packages = c( + "numpy", + "scipy", + "torch", + "torchmetrics", + "scikit-learn", + "imblearn" + ) + ) + + }, + error = function(cond) { + + reticulate::virtualenv_create( + envname = "r-reticulate", + python_version = Sys.getenv("PYTHON_VERSION"), + packages = c( + "numpy", + "scipy", + "torch", + "torchmetrics", + "scikit-learn", + "imblearn" + ) + ) + + } ) + # 2) write path to + # environment writeLines( sprintf("RETICULATE_PYTHON=%s", path_to_python), Sys.getenv("GITHUB_ENV") diff --git a/.github/workflows/macos-check-gcc.yaml b/.github/workflows/macos-check-gcc.yaml deleted file mode 100644 index 52f3534..0000000 --- a/.github/workflows/macos-check-gcc.yaml +++ /dev/null @@ -1,75 +0,0 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples -# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help -on: - push: - branches: [development] - pull_request: - branches: [development] - -name: macOS-gcc - -permissions: read-all - -jobs: - R-CMD-check: - runs-on: ${{ matrix.config.os }} - - name: macOS-gcc - - strategy: - fail-fast: false - matrix: - config: - - {os: macos-latest, r: 'release'} - - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - R_KEEP_PKG_SOURCE: yes - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install GCC on macOS - if: runner.os == 'macOS' - run: | - brew update - brew install gcc - - - name: Set GCC as Default Compiler on macOS - if: runner.os == 'macOS' - run: | - # Identify the installed GCC version - GCC_VERSION=$(brew list gcc | grep bin/gcc- | head -n1 | sed 's#.*/gcc-##') - echo "Detected GCC version: $GCC_VERSION" - - # Set CC and CXX environment variables - echo "CC=$(brew --prefix gcc)/bin/gcc-$GCC_VERSION" >> $GITHUB_ENV - echo "CXX=$(brew --prefix gcc)/bin/g++-$GCC_VERSION" >> $GITHUB_ENV - - echo "$(brew --prefix gcc)/bin" >> $GITHUB_PATH - - - name: Setup pandoc - uses: r-lib/actions/setup-pandoc@v2 - - - name: Setup R - uses: r-lib/actions/setup-r@v2 - with: - r-version: ${{ matrix.config.r }} - http-user-agent: ${{ matrix.config.http-user-agent }} - use-public-rspm: true - - - name: Installing {pkgs} - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::rcmdcheck reticulate - needs: check - - - name: Setup Python and {reticulate} - uses: ./.github/actions/setup-reticulate - - - name: R CMD check - uses: r-lib/actions/check-r-package@v2 - with: - upload-snapshots: true - build_args: 'c("--no-manual", "--compact-vignettes=gs+qpdf")' diff --git a/README.md b/README.md index 22b9194..682dd7d 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ downloads](https://cranlogs.r-pkg.org/badges/last-month/SLmetrics?color=blue)](h [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![R-CMD-check](https://github.com/serkor1/SLmetrics/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/serkor1/SLmetrics/actions/workflows/R-CMD-check.yaml) +[![macOS-clang](https://github.com/serkor1/SLmetrics/actions/workflows/macos-check-clang.yaml/badge.svg)](https://github.com/serkor1/SLmetrics/actions/workflows/macos-check-clang.yaml) [![codecov](https://codecov.io/gh/serkor1/SLmetrics/branch/development/graph/badge.svg?token=X2osJDSRlN)](https://app.codecov.io/gh/serkor1/SLmetrics) [![CodeFactor](https://www.codefactor.io/repository/github/serkor1/slmetrics/badge)](https://www.codefactor.io/repository/github/serkor1/slmetrics) diff --git a/README.qmd b/README.qmd index 72a558d..fdac879 100644 --- a/README.qmd +++ b/README.qmd @@ -51,6 +51,7 @@ lattice::trellis.par.set( [![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/last-month/SLmetrics?color=blue)](https://r-pkg.org/pkg/SLmetrics) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![R-CMD-check](https://github.com/serkor1/SLmetrics/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/serkor1/SLmetrics/actions/workflows/R-CMD-check.yaml) +[![macOS-clang](https://github.com/serkor1/SLmetrics/actions/workflows/macos-check-clang.yaml/badge.svg)](https://github.com/serkor1/SLmetrics/actions/workflows/macos-check-clang.yaml) [![codecov](https://codecov.io/gh/serkor1/SLmetrics/branch/development/graph/badge.svg?token=X2osJDSRlN)](https://app.codecov.io/gh/serkor1/SLmetrics) [![CodeFactor](https://www.codefactor.io/repository/github/serkor1/slmetrics/badge)](https://www.codefactor.io/repository/github/serkor1/slmetrics)