Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python 3.12 #3531

Merged
merged 21 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
73a5132
Update python version bounds and add classifier
agriyakhetarpal Nov 16, 2023
93915b3
Update installation instructions to add 3.12
agriyakhetarpal Nov 16, 2023
92a298b
Bump RTD docs to 3.12
agriyakhetarpal Nov 16, 2023
7e451a3
Bump Python version in workflows
agriyakhetarpal Nov 16, 2023
0db07c7
Add a custom `install_PyBaMM` callable
agriyakhetarpal Nov 16, 2023
8d6a16c
Check coverage on Python 3.11 for now, run unit tests on 3.12
agriyakhetarpal Nov 16, 2023
e38e0be
Undo custom install command function
agriyakhetarpal Nov 23, 2023
a59378b
Add a `sys.version_info()` condition instead
agriyakhetarpal Nov 23, 2023
850bb05
Merge branch 'develop' into support-python-3.12
agriyakhetarpal Nov 23, 2023
84f4007
Add EOL to workflow file, fix pre-commit
agriyakhetarpal Nov 23, 2023
49622d8
Install prerequisites not present in Python 3.12
agriyakhetarpal Nov 23, 2023
1763268
Merge branch 'develop' into support-python-3.12
agriyakhetarpal Dec 8, 2023
3aa0892
Check coverage on 3.11 for now
agriyakhetarpal Dec 8, 2023
b647035
Ignore pytest cache
agriyakhetarpal Dec 8, 2023
d681070
Mention unavailability of `[odes]` on Python 3.12
agriyakhetarpal Dec 8, 2023
d4a8e9f
Add Python 3.12 support and trove classifier
agriyakhetarpal Dec 8, 2023
3bc79c7
Remove references to and imports of `distutils`
agriyakhetarpal Dec 8, 2023
168fcb0
Add checks revolving Python 3.12 and `[odes]`
agriyakhetarpal Dec 8, 2023
5753dbb
Update CHANGELOG to reflect Python 3.12 support
agriyakhetarpal Dec 8, 2023
723998d
Merge branch 'develop' into support-python-3.12
agriyakhetarpal Dec 9, 2023
61cc1c8
Fix editable installation error
agriyakhetarpal Dec 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12

- name: Install dependencies
run: pip install --upgrade pip setuptools wheel build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run_periodic_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12

- name: Check style
run: |
Expand All @@ -50,7 +50,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
run: python -m nox -s coverage

- name: Upload coverage report
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.12
uses: codecov/[email protected]

- name: Run integration tests
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
32 changes: 17 additions & 15 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12

- name: Check style
run: |
Expand All @@ -37,8 +37,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# We check coverage on Ubuntu with Python 3.11, so we skip unit tests for it here
# TODO: check coverage with Python 3.12 when [odes] and [jax] support it
exclude:
- os: ubuntu-latest
python-version: "3.11"
Expand Down Expand Up @@ -115,6 +116,7 @@ jobs:
run: python -m nox -s unit

# Runs only on Ubuntu with Python 3.11
# TODO: check coverage with Python 3.12 when [odes] and [jax] support it
check_coverage:
needs: style
runs-on: ubuntu-latest
Expand Down Expand Up @@ -181,7 +183,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
name: Integration tests (${{ matrix.os }} / Python ${{ matrix.python-version }})

steps:
Expand Down Expand Up @@ -254,14 +256,14 @@ jobs:
- name: Run integration tests for ${{ matrix.os }} with Python ${{ matrix.python-version }}
run: python -m nox -s integration

# Runs only on Ubuntu with Python 3.11. Skips IDAKLU module compilation
# Runs only on Ubuntu with Python 3.12. Skips IDAKLU module compilation
# for speedups, which is already tested in other jobs.
run_doctests:
needs: style
runs-on: ubuntu-latest
strategy:
fail-fast: false
name: Doctests (ubuntu-latest / Python 3.11)
name: Doctests (ubuntu-latest / Python 3.12)

steps:
- name: Check out PyBaMM repository
Expand All @@ -281,11 +283,11 @@ jobs:
sudo dot -c
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng

- name: Set up Python 3.11
- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12
cache: 'pip'
cache-dependency-path: setup.py

Expand All @@ -299,13 +301,13 @@ jobs:
- name: Check if the documentation can be built for GNU/Linux with Python 3.11
run: python -m nox -s docs

# Runs only on Ubuntu with Python 3.11
# Runs only on Ubuntu with Python 3.12
run_example_tests:
needs: style
runs-on: ubuntu-latest
strategy:
fail-fast: false
name: Example notebooks (ubuntu-latest / Python 3.11)
name: Example notebooks (ubuntu-latest / Python 3.12)

steps:
- name: Check out PyBaMM repository
Expand All @@ -325,11 +327,11 @@ jobs:
sudo dot -c
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng

- name: Set up Python 3.11
- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12
cache: 'pip'
cache-dependency-path: setup.py

Expand All @@ -356,13 +358,13 @@ jobs:
- name: Install dev dependencies and run example tests for GNU/Linux with Python 3.11
run: python -m nox -s examples

# Runs only on Ubuntu with Python 3.11
# Runs only on Ubuntu with Python 3.12
run_scripts_tests:
needs: style
runs-on: ubuntu-latest
strategy:
fail-fast: false
name: Example scripts (ubuntu-latest / Python 3.11)
name: Example scripts (ubuntu-latest / Python 3.12)

steps:
- name: Check out PyBaMM repository
Expand All @@ -382,11 +384,11 @@ jobs:
sudo dot -c
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng

- name: Set up Python 3.11
- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12
cache: 'pip'
cache-dependency-path: setup.py

Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ build:
- "graphviz"
os: ubuntu-22.04
tools:
python: "3.11"
python: "3.12"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
Expand Down
4 changes: 2 additions & 2 deletions docs/source/user_guide/installation/GNU-linux.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GNU-Linux & MacOS
Prerequisites
-------------

To use and/or contribute to PyBaMM, you must have Python 3.8, 3.9, 3.10, or 3.11 installed.
To use and/or contribute to PyBaMM, you must have Python 3.8, 3.9, 3.10, 3.11, or 3.12 installed.

.. tab:: Debian-based distributions (Debian, Ubuntu, Linux Mint)

Expand Down Expand Up @@ -50,7 +50,7 @@ User install

We recommend to install PyBaMM within a virtual environment, in order
not to alter any distribution Python files.
First, make sure you are using Python 3.8, 3.9, 3.10, or 3.11.
First, make sure you are using Python 3.8, 3.9, 3.10, 3.11, or 3.12.
To create a virtual environment ``env`` within your current directory type:

.. code:: bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ or download the source archive on the repository's homepage.

To install PyBaMM, you will need:

- Python 3 (PyBaMM supports versions 3.8, 3.9, 3.10, and 3.11)
- Python 3 (PyBaMM supports versions 3.8, 3.9, 3.10, 3.11, and 3.12)
- The Python headers file for your current Python version.
- A BLAS library (for instance `openblas <https://www.openblas.net/>`_).
- A C compiler (ex: ``gcc``).
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_guide/installation/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Windows
Prerequisites
-------------

To use and/or contribute to PyBaMM, you must have Python 3.8, 3.9, 3.10, or 3.11 installed.
To use and/or contribute to PyBaMM, you must have Python 3.8, 3.9, 3.10, 3.11, or 3.12 installed.

To install Python 3 download the installation files from `Python’s
website <https://www.python.org/downloads/windows/>`__. Make sure to
Expand Down
41 changes: 29 additions & 12 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

def set_environment_variables(env_dict, session):
"""
Sets environment variables for a nox session object.
Sets environment variables for a nox Session object.

Parameters
-----------
Expand Down Expand Up @@ -60,10 +60,12 @@ def run_coverage(session):
"""Run the coverage tests and generate an XML report."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("coverage", silent=False)
# TODO: remove this when PyBaMM moves to pyproject.toml
session.install("--upgrade", "pip", "setuptools", "wheel", silent=False)
session.install("-e", ".[all]", silent=False)
if sys.platform != "win32":
session.install("-e", ".[odes]", silent=False)
session.install("-e", ".[jax]", silent=False)
if sys.platform != "win32" and sys.version_info < (3, 12):
# TODO: update this when JAX is bumped to support Python 3.12 and Windows
session.install("-e", ".[odes,jax]", silent=False)
session.run("coverage", "run", "--rcfile=.coveragerc", "run-tests.py", "--nosub")
session.run("coverage", "combine")
session.run("coverage", "xml")
Expand All @@ -73,8 +75,10 @@ def run_coverage(session):
def run_integration(session):
"""Run the integration tests."""
set_environment_variables(PYBAMM_ENV, session=session)
# TODO: remove this when PyBaMM moves to pyproject.toml
session.install("--upgrade", "pip", "setuptools", "wheel", silent=False)
session.install("-e", ".[all]", silent=False)
if sys.platform == "linux":
if sys.platform == "linux" and sys.version_info < (3, 12):
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
session.install("-e", ".[odes]", silent=False)
session.run("python", "run-tests.py", "--integration")

Expand All @@ -90,17 +94,21 @@ def run_doctests(session):
def run_unit(session):
"""Run the unit tests."""
set_environment_variables(PYBAMM_ENV, session=session)
# TODO: remove this when PyBaMM moves to pyproject.toml
session.install("--upgrade", "pip", "setuptools", "wheel", silent=False)
session.install("-e", ".[all]", silent=False)
if sys.platform == "linux":
session.install("-e", ".[odes]", silent=False)
session.install("-e", ".[jax]", silent=False)
if sys.platform == "linux" and sys.version_info < (3, 12):
# TODO: update this when JAX is bumped to support Python 3.12 and Windows
session.install("-e", ".[odes,jax]", silent=False)
session.run("python", "run-tests.py", "--unit")


@nox.session(name="examples")
def run_examples(session):
"""Run the examples tests for Jupyter notebooks."""
set_environment_variables(PYBAMM_ENV, session=session)
# TODO: remove this when PyBaMM moves to pyproject.toml
session.install("--upgrade", "pip", "setuptools", "wheel", silent=False)
session.install("-e", ".[all,dev]", silent=False)
notebooks_to_test = session.posargs if session.posargs else []
session.run("pytest", "--nbmake", *notebooks_to_test, external=True)
Expand All @@ -109,6 +117,8 @@ def run_examples(session):
@nox.session(name="scripts")
def run_scripts(session):
"""Run the scripts tests for Python scripts."""
# TODO: remove this when PyBaMM moves to pyproject.toml
session.install("--upgrade", "pip", "setuptools", "wheel", silent=False)
set_environment_variables(PYBAMM_ENV, session=session)
session.install("-e", ".[all]", silent=False)
session.run("python", "run-tests.py", "--scripts")
Expand All @@ -118,10 +128,13 @@ def run_scripts(session):
def set_dev(session):
"""Install PyBaMM in editable mode."""
set_environment_variables(PYBAMM_ENV, session=session)
# TODO: remove this when PyBaMM moves to pyproject.toml
session.install("--upgrade", "pip", "setuptools", "wheel", silent=False)
session.install("virtualenv", "cmake")
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
if sys.platform == "linux":
if sys.platform == "linux" and sys.version_info < (3, 12):
# TODO: update this when JAX is bumped to support Python 3.12 and Windows
session.run(python,
"-m",
"pip",
Expand All @@ -137,17 +150,21 @@ def set_dev(session):
def run_tests(session):
"""Run the unit tests and integration tests sequentially."""
set_environment_variables(PYBAMM_ENV, session=session)
# TODO: remove this when PyBaMM moves to pyproject.toml
session.install("--upgrade", "pip", "setuptools", "wheel", silent=False)
session.install("-e", ".[all]", silent=False)
if sys.platform == "linux" or sys.platform == "darwin":
session.install("-e", ".[odes]", silent=False)
session.install("-e", ".[jax]", silent=False)
if (sys.platform == "linux" or sys.platform == "darwin") and sys.version_info < (3, 12):
# TODO: update this when JAX is bumped to support Python 3.12 and Windows
session.install("-e", ".[odes,jax]", silent=False)
session.run("python", "run-tests.py", "--all")


@nox.session(name="docs")
def build_docs(session):
"""Build the documentation and load it in a browser tab, rebuilding on changes."""
envbindir = session.bin
# TODO: remove this when PyBaMM moves to pyproject.toml
session.install("--upgrade", "pip", "setuptools", "wheel", silent=False)
session.install("-e", ".[all,docs]", silent=False)
session.chdir("docs")
# Local development
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def compile_KLU():
},
package_data={"pybamm": pybamm_data},
# Python version
python_requires=">=3.8,<3.12",
python_requires=">=3.8,<3.13",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand All @@ -199,6 +199,7 @@ def compile_KLU():
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
],
# List of dependencies
Expand Down
Loading