diff --git a/.github/workflows/R-CMD-check.yml b/.github/workflows/R-CMD-check.yml index 05d2553..9a9094c 100644 --- a/.github/workflows/R-CMD-check.yml +++ b/.github/workflows/R-CMD-check.yml @@ -33,11 +33,8 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install matplotlib numpy>=1.8 packaging parameterized pandas>=1.4 tqdm - # Install pyEpiabm in development mode to ensure it's in PYTHONPATH - git clone https://github.com/SABS-R3-Epidemiology/epiabm.git - cd epiabm - pip install -e . - cd .. + python -m pip install git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm\&subdirectory=pyEpiabm + - name: Set up R ${{ matrix.config.r }} uses: r-lib/actions/setup-r@v2 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index a4110eb..c09027e 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,10 +1,11 @@ -name: R Package Check +name: Lint on: push: branches: [ main ] pull_request: - branches: [ main ] + branches: + - '**' jobs: check: diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 41633c1..1a0d376 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -1,5 +1,6 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples -# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +# Workflow for building and deploying package documentation +name: pkgdown + on: push: branches: [main, master] @@ -7,35 +8,98 @@ on: types: [published] workflow_dispatch: -name: pkgdown - jobs: pkgdown: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_LIBS_USER: ${{ github.workspace }}/R/library + RETICULATE_PYTHON: ${{ github.workspace }}/.venv/bin/python + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + cache: 'pip' + + - name: Create Python virtual environment + run: | + python -m venv .venv + source .venv/bin/activate + python -m pip install --upgrade pip + pip install numpy>=1.8 pandas>=1.4 matplotlib packaging parameterized tqdm + pip install git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm\&subdirectory=pyEpiabm + + - name: Set up reticulate configuration + run: | + mkdir -p ~/.R + echo "RETICULATE_PYTHON='${{ github.workspace }}/.venv/bin/python'" >> ~/.R/Makevars - uses: r-lib/actions/setup-pandoc@v2 - uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true + extra-repositories: https://inla.r-inla-download.org/R/stable + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y libcurl4-openssl-dev libssl-dev libxml2-dev libharfbuzz-dev libfribidi-dev - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::pkgdown, local::., any::XML + extra-packages: | + any::pkgdown + any::XML + any::devtools + any::reticulate + local::. needs: website + - name: Check DESCRIPTION file format + run: | + echo "" >> DESCRIPTION # Ensure there's a newline at the end + Rscript -e 'if(length(readLines("DESCRIPTION")) == 0) stop("Empty DESCRIPTION file")' + + - name: Configure reticulate + run: | + Rscript -e 'Sys.setenv(RETICULATE_PYTHON = "${{ github.workspace }}/.venv/bin/python")' + Rscript -e 'reticulate::use_virtualenv("${{ github.workspace }}/.venv")' + - name: Build site - run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) - shell: Rscript {0} - + run: | + Rscript -e ' + options(pkgdown.internet = FALSE) + pkgdown::build_site_github_pages( + new_process = FALSE, + install = FALSE, + examples = TRUE, + run_dont_run = FALSE + )' + - name: Deploy to GitHub pages if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@4.1.4 + uses: JamesIves/github-pages-deploy-action@v4 with: clean: false branch: gh-pages folder: docs + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload documentation artifacts + if: failure() + uses: actions/upload-artifact@v3 + with: + name: pkgdown-artifacts + path: | + docs/ + pkgdown/ + .venv/ + *.Rcheck/ + *.log \ No newline at end of file diff --git a/.github/workflows/test_macos.yml b/.github/workflows/test_macos.yml index 40cab78..726c1c3 100644 --- a/.github/workflows/test_macos.yml +++ b/.github/workflows/test_macos.yml @@ -9,57 +9,95 @@ on: - '**' jobs: - test: name: tests on macOS with R ${{ matrix.R }} runs-on: macos-latest + env: + R_LIBS_USER: ${{ github.workspace }}/R/library + RETICULATE_PYTHON: ${{ github.workspace }}/.venv/bin/python + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} strategy: fail-fast: false matrix: R: [ '4.1.0' ] steps: - - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup R uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.R }} Ncpus: 2 - + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + cache: 'pip' + + - name: Create Python virtual environment + run: | + python -m venv .venv + source .venv/bin/activate + python -m pip install --upgrade pip + pip install numpy>=1.8 pandas>=1.4 matplotlib packaging parameterized tqdm + pip install git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm\&subdirectory=pyEpiabm + - name: Query dependencies run: | install.packages('remotes') saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) shell: Rscript {0} - - - name: cache R installed packages - uses: actions/cache@v2 + + - name: Restore R package cache + uses: actions/cache@v3 id: cache with: - path: | - ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-R${{ matrix.R }}-2-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-R${{ matrix.R }}-2- - - - name: Install packages + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-${{ matrix.R }}-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-r-${{ matrix.R }}- + + - name: Install system dependencies + run: | + brew install curl openssl libxml2 + + - name: Install R dependencies + if: steps.cache.outputs.cache-hit != 'true' run: | - install.packages(c("devtools")) + install.packages(c("devtools", "reticulate", "withr", "rappdirs")) remotes::install_deps(dependencies = TRUE) remotes::install_cran("rcmdcheck") shell: Rscript {0} + - name: Check DESCRIPTION file format + run: | + echo "" >> DESCRIPTION # Ensure there's a newline at the end + Rscript -e 'if(length(readLines("DESCRIPTION")) == 0) stop("Empty DESCRIPTION file")' + + - name: Set up reticulate configuration + run: | + mkdir -p ~/.R + echo "RETICULATE_PYTHON='${{ github.workspace }}/.venv/bin/python'" >> ~/.R/Makevars + - name: Check env: _R_CHECK_CRAN_INCOMING_REMOTE_: false run: | options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check") + Sys.setenv(RETICULATE_PYTHON = '${{ github.workspace }}/.venv/bin/python') + rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") shell: Rscript {0} - name: Show testthat output if: always() run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true shell: bash + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: ${{ runner.os }}-r${{ matrix.R }}-results + path: check \ No newline at end of file diff --git a/.github/workflows/test_ubuntu.yml b/.github/workflows/test_ubuntu.yml index cc6209c..d948b7e 100644 --- a/.github/workflows/test_ubuntu.yml +++ b/.github/workflows/test_ubuntu.yml @@ -9,62 +9,101 @@ on: - '**' jobs: - test: name: tests on Ubuntu with R ${{ matrix.R }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest + env: + R_LIBS_USER: ${{ github.workspace }}/R/library + RETICULATE_PYTHON: ${{ github.workspace }}/.venv/bin/python + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} strategy: fail-fast: false matrix: R: [ '4.1.0' ] steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Install build dependencies - run: | - sudo apt update - sudo apt install libcurl4-openssl-dev + uses: actions/checkout@v3 - name: Setup R uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.R }} Ncpus: 2 - + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + cache: 'pip' + + - name: Create Python virtual environment + run: | + python -m venv .venv + source .venv/bin/activate + python -m pip install --upgrade pip + pip install numpy>=1.8 pandas>=1.4 matplotlib packaging parameterized tqdm + pip install git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm\&subdirectory=pyEpiabm + - name: Query dependencies run: | install.packages('remotes') saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) shell: Rscript {0} - - - name: cache R installed packages - uses: actions/cache@v2 + + - name: Restore R package cache + uses: actions/cache@v3 id: cache with: - path: | - ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-R${{ matrix.R }}-2-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-R${{ matrix.R }}-2- - - - name: Install packages + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-${{ matrix.R }}-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-r-${{ matrix.R }}- + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + libcurl4-openssl-dev \ + libssl-dev \ + libxml2-dev \ + libharfbuzz-dev \ + libfribidi-dev + + - name: Install R dependencies + if: steps.cache.outputs.cache-hit != 'true' run: | - install.packages(c("devtools")) + install.packages(c("devtools", "reticulate", "withr", "rappdirs")) remotes::install_deps(dependencies = TRUE) remotes::install_cran("rcmdcheck") shell: Rscript {0} + - name: Check DESCRIPTION file format + run: | + echo "" >> DESCRIPTION # Ensure there's a newline at the end + Rscript -e 'if(length(readLines("DESCRIPTION")) == 0) stop("Empty DESCRIPTION file")' + + - name: Set up reticulate configuration + run: | + mkdir -p ~/.R + echo "RETICULATE_PYTHON='${{ github.workspace }}/.venv/bin/python'" >> ~/.R/Makevars + - name: Check env: _R_CHECK_CRAN_INCOMING_REMOTE_: false run: | options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check") + Sys.setenv(RETICULATE_PYTHON = '${{ github.workspace }}/.venv/bin/python') + rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") shell: Rscript {0} - name: Show testthat output if: always() run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true shell: bash + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: ${{ runner.os }}-r${{ matrix.R }}-results + path: check \ No newline at end of file diff --git a/.github/workflows/test_windows.yml b/.github/workflows/test_windows.yml index 3656a2c..4acbe87 100644 --- a/.github/workflows/test_windows.yml +++ b/.github/workflows/test_windows.yml @@ -9,57 +9,120 @@ on: - '**' jobs: - test: name: tests on Windows with R ${{ matrix.R }} runs-on: windows-latest + env: + R_LIBS_USER: ${{ github.workspace }}/R/library + RETICULATE_PYTHON: ${{ github.workspace }}/.venv/Scripts/python.exe + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + # Avoid longpaths issues on Windows + RETICULATE_PYTHON_VENV_PATH: ${{ github.workspace }}/.venv strategy: fail-fast: false matrix: R: [ '4.1.0' ] steps: + - name: Configure git line endings + run: | + git config --global core.autocrlf false + git config --global core.eol lf - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup R uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.R }} Ncpus: 2 - + windows-path-include-mingw: true + + - name: Setup Rtools + uses: r-lib/actions/setup-rtools@v2 + if: runner.os == 'Windows' + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + cache: 'pip' + architecture: 'x64' + + - name: Create Python virtual environment + shell: cmd + run: | + python -m venv .venv + call .venv\Scripts\activate.bat + python -m pip install --upgrade pip + pip install numpy>=1.8 pandas>=1.4 matplotlib packaging parameterized tqdm + pip install git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm&subdirectory=pyEpiabm + - name: Query dependencies + shell: Rscript {0} run: | install.packages('remotes') saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - shell: Rscript {0} - - - name: cache R installed packages - uses: actions/cache@v2.1.7 + + - name: Restore R package cache + uses: actions/cache@v3 id: cache with: - path: | - ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-R${{ matrix.R }}-2-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-R${{ matrix.R }}-2- - - - name: Install packages + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-${{ matrix.R }}-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-r-${{ matrix.R }}- + + - name: Install R dependencies + if: steps.cache.outputs.cache-hit != 'true' + shell: Rscript {0} run: | - install.packages(c("devtools")) + install.packages(c("devtools", "reticulate", "withr", "rappdirs")) remotes::install_deps(dependencies = TRUE) remotes::install_cran("rcmdcheck") - shell: Rscript {0} + + - name: Check DESCRIPTION file format + shell: cmd + run: | + echo. >> DESCRIPTION + Rscript -e "if(length(readLines('DESCRIPTION')) == 0) stop('Empty DESCRIPTION file')" + + - name: Set up reticulate configuration + shell: cmd + run: | + mkdir %USERPROFILE%\.R 2>NUL + echo RETICULATE_PYTHON='%GITHUB_WORKSPACE%\.venv\Scripts\python.exe' >> %USERPROFILE%\.R\Makevars.win - name: Check env: _R_CHECK_CRAN_INCOMING_REMOTE_: false + shell: Rscript {0} run: | options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check") - shell: Rscript {0} + Sys.setenv(RETICULATE_PYTHON = normalizePath(file.path('${{ github.workspace }}', '.venv', 'Scripts', 'python.exe'))) + rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - name: Show testthat output if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash + shell: cmd + run: | + IF EXIST check ( + for /R check %%f in (testthat.Rout*) do type "%%f" + ) + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: ${{ runner.os }}-r${{ matrix.R }}-results + path: check + + - name: Upload logs on failure + if: failure() + uses: actions/upload-artifact@v3 + with: + name: ${{ runner.os }}-r${{ matrix.R }}-logs + path: | + check/*.Rcheck/00check.log + check/*.Rcheck/00install.out + .venv/Scripts/pip-log.txt \ No newline at end of file diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..fc9c05c --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,37 @@ +url: https://SABS-R3-Epidemiology.github.io/rEpiabm/ + +template: + bootstrap: 5 + bootswatch: flatly + bslib: + primary: "#0054AD" + border-radius: 0.5rem + btn-border-radius: 0.25rem + +navbar: + structure: + left: [intro, reference, articles, tutorials, news] + right: [search, github] + +reference: +- title: Package Overview + desc: Main package documentation and getting started +- title: Core Functions + desc: Main functions for epidemic modeling +- title: Utility Functions + desc: Helper and utility functions +- title: Data + desc: Included datasets and data structures + +articles: +- title: Getting Started + navbar: ~ + contents: + - '`rEpiabm`' + - setup + - basic-usage + +news: + releases: + - text: "Version 0.0.2" + href: https://github.com/SABS-R3-Epidemiology/rEpiabm/releases/tag/v0.0.2 \ No newline at end of file