Skip to content

Commit

Permalink
Merge pull request #3231 from agriyakhetarpal/nox-fix
Browse files Browse the repository at this point in the history
Add `pip` caches, remove `nox` caches, and remove `requirements.txt`
  • Loading branch information
Saransh-cpp authored Aug 5, 2023
2 parents 8662763 + 72038ec commit f0cc984
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 89 deletions.
71 changes: 16 additions & 55 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- id: setup-python
name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Check out PyBaMM repository
uses: actions/checkout@v3

# Install and cache apt packages
- name: Install Linux system dependencies
Expand All @@ -68,73 +64,59 @@ jobs:
sudo dot -c
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
# Added fixes to homebrew installs:
# rm -f /usr/local/bin/2to3
# (see https://github.com/actions/virtual-environments/issues/2322)
- name: Install macOS system dependencies
if: matrix.os == 'macos-latest'
env:
# Homebrew environment variables
HOMEBREW_NO_INSTALL_CLEANUP: 1
HOMEBREW_NO_ANALYTICS: 1
HOMEBREW_NO_GOOGLE_ANALYTICS: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_COLOR: 1
# Speed up CI
NONINTERACTIVE: 1
run: |
rm -f /usr/local/bin/2to3*
rm -f /usr/local/bin/idle3*
rm -f /usr/local/bin/pydoc3*
rm -f /usr/local/bin/python3*
brew analytics off
brew update
brew install graphviz openblas
- name: Install Windows system dependencies
if: matrix.os == 'windows-latest'
run: choco install graphviz --version=8.0.5

- name: Install standard Python dependencies
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: setup.py

- name: Install PyBaMM dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install nox
pip install --upgrade pip wheel setuptools nox
pip install -e .[all,docs]
- name: Cache pybamm-requires nox environment for GNU/Linux
uses: actions/cache@v3
if: matrix.os == 'ubuntu-latest'
with:
path: |
# Repository files
${{ github.workspace }}/.nox/pybamm-requires/
${{ github.workspace }}/pybind11/
${{ github.workspace }}/install_KLU_Sundials/
# Headers and dynamic library files for SuiteSparse and SUNDIALS
${{ env.HOME }}/.local/lib/
${{ env.HOME }}/.local/include/
${{ env.HOME }}/.local/examples/
key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/noxfile.py', '**/install_KLU_Sundials.py') }}
key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }}

- name: Install SuiteSparse and SUNDIALS on GNU/Linux
if: matrix.os == 'ubuntu-latest'
run: nox -s pybamm-requires

- name: Cache unit tests nox environment for GNU/Linux with Python 3.8, 3.9, and 3.10, and for macOS and Windows with all Python versions
uses: actions/cache@v3
if: (matrix.os == 'ubuntu-latest' && matrix.python-version != 3.11) || (matrix.os != 'ubuntu-latest')
with:
path: ${{ github.workspace }}/.nox/unit/
key: ${{ runner.os }}-nox-unit-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/noxfile.py', '**/setup.py') }}

- name: Run unit tests for GNU/Linux with Python 3.8, 3.9, and 3.10 and for macOS and Windows with all Python versions
if: (matrix.os == 'ubuntu-latest' && matrix.python-version != 3.11) || (matrix.os != 'ubuntu-latest')
run: nox -s unit

- name: Cache coverage nox environment for GNU/Linux with Python 3.11
uses: actions/cache@v3
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
with:
path: ${{ github.workspace }}/.nox/coverage/
key: ${{ runner.os }}-nox-coverage-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/noxfile.py', '**/setup.py', '**/.coveragerc') }}

- name: Run unit tests for GNU/Linux with Python 3.11 and generate coverage report
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
run: nox -s coverage
Expand All @@ -143,35 +125,14 @@ jobs:
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
uses: codecov/[email protected]

- name: Cache integration tests nox environment for GNU/Linux with Python 3.11
uses: actions/cache@v3
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
with:
path: ${{ github.workspace }}/.nox/integration/
key: ${{ runner.os }}-nox-integration-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/noxfile.py', '**/setup.py') }}

- name: Run integration tests for GNU/Linux with Python 3.11
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
run: nox -s integration

- name: Cache doctests nox environment for GNU/Linux with Python 3.11
uses: actions/cache@v3
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
with:
path: ${{ github.workspace }}/.nox/doctests/
key: ${{ runner.os }}-nox-doctests-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/noxfile.py', '**/setup.py', '**/docs/requirements.txt') }}

- name: Install docs dependencies and run doctests for GNU/Linux with Python 3.11
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
run: nox -s doctests

- name: Cache examples nox environment for GNU/Linux with Python 3.11
uses: actions/cache@v3
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
with:
path: ${{ github.workspace }}/.nox/examples/
key: ${{ runner.os }}-nox-examples-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/noxfile.py', '**/setup.py') }}

- name: Install dev dependencies and run example tests for GNU/Linux with Python 3.11
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
run: nox -s examples
35 changes: 20 additions & 15 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
# Do not stdout ANSI colours on GitHub Actions
if os.getenv("CI") == "true":
os.environ["NO_COLOR"] = "1"
# The setup-python action installs and caches dependencies by default, so we skip
# installing them again in nox environments. The dev and docs sessions will still
# require a virtual environment, but we don't run them in the CI
nox.options.default_venv_backend = "none"


def set_environment_variables(env_dict, session):
Expand All @@ -42,7 +46,7 @@ def run_pybamm_requires(session):
"""Download, compile, and install the build-time requirements for Linux and macOS: the SuiteSparse and SUNDIALS libraries.""" # noqa: E501
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
session.install("wget", "cmake")
session.run_always("pip", "install", "wget", "cmake")
session.run("python", "scripts/install_KLU_Sundials.py")
if not os.path.exists("./pybind11"):
session.run(
Expand All @@ -60,11 +64,11 @@ def run_pybamm_requires(session):
def run_coverage(session):
"""Run the coverage tests and generate an XML report."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("coverage")
session.install("-e", ".[all]")
session.run_always("pip", "install", "coverage")
session.run_always("pip", "install", "-e", ".[all]")
if sys.platform != "win32":
session.install("-e", ".[odes]")
session.install("-e", ".[jax]")
session.run_always("pip", "install", "-e", ".[odes]")
session.run_always("pip", "install", "-e", ".[jax]")
session.run("coverage", "run", "--rcfile=.coveragerc", "run-tests.py", "--nosub")
session.run("coverage", "combine")
session.run("coverage", "xml")
Expand All @@ -74,34 +78,35 @@ def run_coverage(session):
def run_integration(session):
"""Run the integration tests."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("-e", ".[all]")
session.run_always("pip", "install", "-e", ".[all]")
if sys.platform == "linux":
session.install("-e", ".[odes]")
session.run_always("pip", "install", "-e", ".[odes]")
session.run("python", "run-tests.py", "--integration")


@nox.session(name="doctests")
def run_doctests(session):
"""Run the doctests and generate the output(s) in the docs/build/ directory."""
session.install("-e", ".[all,docs]")
session.run_always("pip", "install", "-e", ".[all,docs]")
session.run("python", "run-tests.py", "--doctest")


@nox.session(name="unit")
def run_unit(session):
"""Run the unit tests."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("-e", ".[all]")
session.run_always("pip", "install", "-e", ".[all]")
if sys.platform == "linux":
session.install("-e", ".[odes]")
session.install("-e", ".[jax]")
session.run_always("pip", "install", "-e", ".[odes]")
session.run_always("pip", "install", "-e", ".[jax]")
session.run("python", "run-tests.py", "--unit")


@nox.session(name="examples")
def run_examples(session):
"""Run the examples tests for Jupyter notebooks and Python scripts."""
session.install("-e", ".[all]")
set_environment_variables(PYBAMM_ENV, session=session)
session.run_always("pip", "install", "-e", ".[all]")
session.run("python", "run-tests.py", "--examples")


Expand All @@ -127,10 +132,10 @@ def set_dev(session):
def run_tests(session):
"""Run the unit tests and integration tests sequentially."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("-e", ".[all]")
session.run_always("pip", "install", "-e", ".[all]")
if sys.platform == "linux" or sys.platform == "darwin":
session.install("-e", ".[odes]")
session.install("-e", ".[jax]")
session.run_always("pip", "install", "-e", ".[odes]")
session.run_always("pip", "install", "-e", ".[jax]")
session.run("python", "run-tests.py", "--all")


Expand Down
19 changes: 0 additions & 19 deletions requirements.txt

This file was deleted.

0 comments on commit f0cc984

Please sign in to comment.