Skip to content

Commit

Permalink
Fix 45 checks on macos (#46)
Browse files Browse the repository at this point in the history
* **Bug-fix (#45: The
failing tests on macOS is on the side of Python on imbalanced class-wise
classification. Commit a9bddd5 confirms
this. *Upgrading Python did not make a difference.*

**Fix:** Add guards similar to `fbeta()` to capture unpredictable
behavior.

* **Streamlined and split workflows:** All reticulate relatetd workflows
uses a composite action to minimize the amount of coding and updating
python related workflows. MacOS have been removed from the primary
package check as this is most prone to error. They have been split
between clang and gcc compilers for future guides on OpenMP enabled
Macbooks and tests.

* **Updated Python Version:** Python is now 3.12

---------

Signed-off-by: Serkan Korkmaz <[email protected]>
  • Loading branch information
serkor1 committed Jan 6, 2025
1 parent 55e5e13 commit b6ef067
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 96 deletions.
61 changes: 61 additions & 0 deletions .github/actions/setup-reticulate/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Setup {reticulate} environment"

description: "Sets up Python and Reticulate virtual environment for R projects."
inputs:
python-version:
description: "Python version to install"
required: true
default: "3.12.x"

outputs:
reticulate-python:
description: "Path to the Reticulate Python environment"

runs:
using: "composite"
steps:
- name: Install system dependencies (Ubuntu only)
if: runner.os == 'Linux'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y python3-venv
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

- name: Setup venv with {Reticulate}
shell: Rscript {0}
env:
PYTHON_VERSION: ${{ inputs.python-version }}
run: |
# 1) get python version
# NOTE: it's on the form 3.12.x
python_version <- paste0(">=",gsub(
pattern = ".x",
replacement = "",
x = Sys.getenv("PYTHON_VERSION")
))
# 2) create virtual environment
# with specified version
path_to_python <- reticulate::virtualenv_create(
envname = "r-reticulate",
python_version = python_version,
packages = c(
"numpy",
"scipy",
"torch",
"torchmetrics",
"scikit-learn",
"imblearn"
)
)
writeLines(
sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV")
)
73 changes: 14 additions & 59 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [development, documentation, OpenMP]
branches: [development]
pull_request:
branches: [development, documentation, OpenMP]
branches: [development]

name: R-CMD-check

Expand All @@ -20,7 +20,6 @@ jobs:
fail-fast: false
matrix:
config:
# - {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -31,74 +30,30 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2
- name: Setup pandoc
uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@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: Install system dependencies (Ubuntu only)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y python3-venv
- uses: r-lib/actions/setup-r-dependencies@v2
- name: Installing {pkgs}
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck reticulate
needs: check

- uses: actions/setup-python@v4
with:
python-version: "3.10.x"

- name: Setup venv with {reticulate}
shell: Rscript {0}
run: |
path_to_python <- reticulate::virtualenv_create(
envname = "r-reticulate",
python = Sys.which("python"), # placed on PATH by the setup-python action
packages = c(
"numpy",
"scipy",
"torch",
"torchmetrics",
"scikit-learn",
"imblearn"
)
)
writeLines(
sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV")
)
- 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
# Optionally, add GCC to PATH
echo "$(brew --prefix gcc)/bin" >> $GITHUB_PATH
- name: Setup Python and {reticulate}
uses: ./.github/actions/setup-reticulate

- uses: r-lib/actions/check-r-package@v2
- 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")'
4 changes: 2 additions & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
workflow_dispatch:
push:
branches: [development, quarto-docs]
branches: [development]
paths: ['docs/**', '.github/workflows/build-docs.yml']

name: Build Docs
Expand All @@ -18,7 +18,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- name: Check out repository
- name: Checkout
uses: actions/checkout@v4

- name: Set up Quarto
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/macos-check-clang.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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-clang

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: macOS-clang

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: 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")'
75 changes: 75 additions & 0 deletions .github/workflows/macos-check-gcc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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")'
44 changes: 9 additions & 35 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,22 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install system dependencies (Ubuntu only)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y python3-venv
- uses: r-lib/actions/setup-r-dependencies@v2
- name: Installing {pkgs}
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2, any::reticulate
extra-packages: any::covr, any::xml2, reticulate
needs: coverage

- uses: actions/setup-python@v4
with:
python-version: "3.10.x"

- name: Setup venv with {reticulate}
shell: Rscript {0}
run: |
path_to_python <- reticulate::virtualenv_create(
envname = "r-reticulate",
python = Sys.which("python"), # placed on PATH by the setup-python action
packages = c(
"numpy",
"scipy",
"torch",
"torchmetrics",
"scikit-learn",
"imblearn"
)
)
writeLines(
sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV")
)
- name: Setup Python and {reticulate}
uses: ./.github/actions/setup-reticulate

- name: Test coverage
run: |
Expand Down
Loading

0 comments on commit b6ef067

Please sign in to comment.