diff --git a/.github/workflows/test_macos.yml b/.github/workflows/test_macos.yml index 15013bf..cd131a3 100644 --- a/.github/workflows/test_macos.yml +++ b/.github/workflows/test_macos.yml @@ -16,6 +16,7 @@ jobs: fail-fast: false matrix: R: ['4.1.0'] + python-version: ['3.10'] # Explicitly define Python version in matrix steps: - name: Checkout repository @@ -30,7 +31,8 @@ jobs: - name: Setup Python uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: ${{ matrix.python-version }} + cache: 'pip' - name: Query dependencies run: | @@ -38,7 +40,7 @@ jobs: saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) shell: Rscript {0} - - name: cache R installed packages + - name: Cache R packages uses: actions/cache@v2 id: cache with: @@ -54,61 +56,38 @@ jobs: remotes::install_cran("rcmdcheck") shell: Rscript {0} - - name: setup r-reticulate venv + - name: Setup Python environment shell: Rscript {0} run: | library(reticulate) - - reticulate::py_run_string(" - import sys - import subprocess - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip']) - ") - # Install required packages - reticulate::py_run_string(" - import sys - import subprocess + # Use the GitHub Actions Python + Sys.setenv(RETICULATE_PYTHON = Sys.which("python")) - # Install basic packages - packages = ['numpy', 'pandas', 'matplotlib'] - for package in packages: - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', package]) + # Install pip packages + system2("pip", c("install", "--upgrade", "pip")) + system2("pip", c("install", "--upgrade", "numpy", "pandas", "matplotlib")) + system2("pip", c("install", "--upgrade", "git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm&subdirectory=pyEpiabm")) - # Install pyEpiabm from GitHub - subprocess.check_call([ - sys.executable, '-m', 'pip', 'install', '--upgrade', - 'git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm&subdirectory=pyEpiabm' - ]) - ") + # Verify Python configuration + py_config <- reticulate::py_config() + message("Python configuration:") + message(paste("Python version:", py_config$version)) + message(paste("Python path:", py_config$python)) - env_name <- "r-py-env" - python_version = "3.9" - tryCatch({ - # Check if virtualenv package is available - if (!reticulate::virtualenv_exists(env_name)) { - message(sprintf("Creating new Python virtual environment: %s", env_name)) - - # Create virtual environment with system site packages to help with SSL - reticulate::virtualenv_create( - envname = env_name, - version = python_version, - packages = "pip", - system_site_packages = TRUE - ) - } - - # Activate the environment - reticulate::use_virtualenv(env_name, required = TRUE) - return(TRUE) - }, error = function(e) { - warning(sprintf("Failed to create/activate Python environment: %s", e$message)) - return(FALSE) - }) + # Test imports + reticulate::py_run_string(" + import numpy + import pandas + import matplotlib + import pyEpiabm + print('All required Python packages successfully imported') + ") - name: Check env: _R_CHECK_CRAN_INCOMING_REMOTE_: false + RETICULATE_PYTHON: ${{ env.pythonLocation }}/python run: | options(crayon.enabled = TRUE) rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check") @@ -116,5 +95,4 @@ jobs: - name: Show testthat output if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash \ No newline at end of file + run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true \ No newline at end of file