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

Python 3.11 support #1406

Merged
merged 8 commits into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 37 additions & 30 deletions .github/workflows/main.yml
Expand Up @@ -25,7 +25,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
python-version: [ '3.7', '3.9', '3.10' ]
python-version: ['3.8', '3.10', '3.11']
os: ['ubuntu-20.04', 'ubuntu-22.04']
fail-fast: false
steps:
Expand All @@ -46,11 +46,9 @@ jobs:
- name: Upgrade pip
run: python3 -m pip install -U pip setuptools wheel
- name: Install Python dependencies
run: python3 -m pip install ruamel.yaml scons==3.1.2 numpy cython h5py pandas
pytest pytest-github-actions-annotate-failures
- name: Install typing_extensions for Python 3.7
if: matrix.python-version == '3.7'
run: python3 -m pip install typing_extensions
run: |
python3 -m pip install ruamel.yaml scons==3.1.2 numpy cython pandas pytest pytest-github-actions-annotate-failures
python3 -m pip install h5py || true
- name: Build Cantera
run: python3 `which scons` build env_vars=all -j2 debug=n --debug=time
- name: Upload shared library
Expand Down Expand Up @@ -101,8 +99,10 @@ jobs:
timeout-minutes: 90
strategy:
matrix:
python-version: [ '3.7', '3.9', '3.10' ]
python-version: ['3.8', '3.10', '3.11']
fail-fast: false
env:
PYTHON_CMD: "python${{ matrix.python-version }}"
steps:
# Attempt to fix intermittent cloning errors. The error message says something like
# error: RPC failed; curl 18 transfer closed with outstanding read data remaining
Expand All @@ -116,19 +116,33 @@ jobs:
name: Checkout the repository
with:
submodules: recursive
- name: Setup GH Python
uses: actions/setup-python@v4
with:
python-version: 3.11
if: matrix.python-version == '3.11'
- name: Install Brew dependencies
run: brew install boost libomp
- name: Setup Homebrew Python
# This path should work for future Python versions as well
if: matrix.python-version != '3.11'
run: |
brew install boost libomp scons python@${{ matrix.python-version }}
brew install python@${{ matrix.python-version }}
brew link --force --overwrite python@${{ matrix.python-version }}
brew install scons
- name: Upgrade pip
run: python3 -m pip install -U pip 'setuptools>=47.0.0,<48' wheel
run: $PYTHON_CMD -m pip install -U pip 'setuptools>=47.0.0,<48' wheel
- name: Install Python dependencies
run: python3 -m pip install ruamel.yaml numpy cython h5py pandas pytest
pytest-github-actions-annotate-failures
- name: Install typing_extensions for Python 3.7
if: matrix.python-version == '3.7'
run: python3 -m pip install typing_extensions
# h5py is optional; may fail if no wheel is present for a given OS/Python version
run: |
$PYTHON_CMD -m pip install ruamel.yaml numpy cython pandas pytest pytest-github-actions-annotate-failures
$PYTHON_CMD -m pip install h5py || true
- name: Install Python dependencies for GH Python
if: matrix.python-version == '3.11'
run:
$PYTHON_CMD -m pip install scons
- name: Build Cantera
run: scons build env_vars=all -j3 debug=n --debug=time
run: scons build env_vars=all -j3 python_cmd=$PYTHON_CMD debug=n --debug=time
- name: Upload shared library
uses: actions/upload-artifact@v3
if: matrix.python-version == '3.10'
Expand Down Expand Up @@ -311,7 +325,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
python-version: ['3.7', '3.9', '3.10']
python-version: ['3.8', '3.10', '3.11']
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -330,10 +344,9 @@ jobs:
- name: Upgrade pip
run: python3 -m pip install -U pip setuptools wheel
- name: Install Python dependencies
run: python3 -m pip install ruamel.yaml scons numpy cython h5py pandas matplotlib scipy
- name: Install typing_extensions for Python 3.7
if: matrix.python-version == '3.7'
run: python3 -m pip install typing_extensions
run: |
python3 -m pip install ruamel.yaml scons numpy cython pandas matplotlib scipy
python3 -m pip install h5py || true
- name: Build Cantera
# compile with GCC 9.4.0 on ubuntu-20.04 as an alternative to the default
# (GCC 7.5.0 is both default and oldest supported version)
Expand Down Expand Up @@ -369,7 +382,7 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
sundials-ver: [ 3, 4, 5.8, 6.2 ]
sundials-ver: [ 3, 4, 5.8, 6.4.1 ]
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -429,7 +442,7 @@ jobs:
matrix:
os: ["windows-2022"]
vs-toolset: ["14.1", "14.3"]
python-version: [ "3.7", "3.9", "3.10" ]
python-version: ["3.8", "3.10", "3.11"]
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -452,9 +465,6 @@ jobs:
run: |
mamba install -q '"scons>=4.4.0"' numpy cython ruamel.yaml boost-cpp eigen yaml-cpp h5py pandas pytest
shell: pwsh
- name: Install typing_extensions for Python 3.7
if: matrix.python-version == '3.7'
run: mamba install -q typing_extensions
- name: Build Cantera
run: scons build system_eigen=y system_yamlcpp=y logging=debug
msvc_toolset_version=${{ matrix.vs-toolset }} f90_interface=n debug=n --debug=time -j2
Expand Down Expand Up @@ -501,7 +511,7 @@ jobs:
strategy:
matrix:
vs-toolset: ['14.2']
python-version: [ "3.7", "3.9", "3.10" ]
python-version: ["3.8", "3.10", "3.11"]
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -516,10 +526,7 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install -U pip setuptools wheel
python -m pip install '"scons<4.4.0"' pypiwin32 numpy ruamel.yaml cython h5py pandas pytest pytest-github-actions-annotate-failures
- name: Install typing_extensions for Python 3.7
if: matrix.python-version == '3.7'
run: python -m pip install typing_extensions
python -m pip install '"scons<4.4.0"' pypiwin32 numpy ruamel.yaml cython pandas pytest pytest-github-actions-annotate-failures
- name: Restore Boost cache
uses: actions/cache@v2
id: cache-boost
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -102,8 +102,8 @@

* Style generally follows PEP8 (https://www.python.org/dev/peps/pep-0008/)
* Code in `.py` and `.pyx` files needs to be written to work with Python 3
* The minimum Python version that Cantera supports is Python 3.7, so code should only
use features added in Python 3.7 or earlier
* The minimum Python version that Cantera supports is Python 3.8, so code should only
use features added in Python 3.8 or earlier
* Indicate the version added for new functions and classes with an annotation like
`.. versionadded:: X.Y` where `X.Y` is the next Cantera version. Significant changes
in behavior should be indicated with `.. versionchanged:: X.Y`.
Expand Down
6 changes: 3 additions & 3 deletions SConstruct
Expand Up @@ -65,7 +65,7 @@ Additional command options:
# and simplest option that will reliably trigger an error in Python 2
# and provide actionable feedback for users.
f"""
Cantera must be built using Python 3.7 or higher. You can invoke SCons by executing
Cantera must be built using Python 3.8 or higher. You can invoke SCons by executing
python3 `which scons`
followed by any desired options.
"""
Expand Down Expand Up @@ -1462,7 +1462,7 @@ if env['system_sundials'] == 'y':
if sundials_ver < parse_version("3.0") or sundials_ver >= parse_version("7.0"):
logger.error(f"Sundials version {env['sundials_version']!r} is not supported.")
sys.exit(1)
elif sundials_ver > parse_version("6.2"):
elif sundials_ver > parse_version("6.4.1"):
logger.warning(f"Sundials version {env['sundials_version']!r} has not been tested.")

logger.info(f"Using system installation of Sundials version {sundials_version!r}.")
Expand Down Expand Up @@ -1578,7 +1578,7 @@ logger.debug("\n".join(debug_message), print_level=False)
env['python_cmd_esc'] = quoted(env['python_cmd'])

# Python Package Settings
python_min_version = parse_version("3.7")
python_min_version = parse_version("3.8")
# The string is used to set python_requires in setup.cfg.in
env['py_min_ver_str'] = str(python_min_version)
# Note: cython_min_version is redefined below if the Python version is 3.8 or higher
Expand Down
5 changes: 1 addition & 4 deletions interfaces/cython/cantera/ctml2yaml.py
Expand Up @@ -21,7 +21,7 @@
import warnings
import copy

from typing import Any, Dict, Union, Iterable, Optional, List, Tuple
from typing import Any, Dict, Union, Iterable, Optional, List, Tuple, TypedDict
from typing import TYPE_CHECKING

import numpy as np
Expand All @@ -47,9 +47,6 @@
)

if TYPE_CHECKING:
# This is available in the built-in typing module in Python 3.8
from typing_extensions import TypedDict

QUANTITY = Union[float, str]

RK_EOS_DICT = TypedDict(
Expand Down
8 changes: 1 addition & 7 deletions interfaces/cython/cantera/yaml2ck.py
Expand Up @@ -61,13 +61,7 @@
from textwrap import fill, dedent, TextWrapper
import cantera as ct
from email.utils import formatdate
from typing import Optional, Iterable

try:
from typing import Literal
except ImportError:
# Needed for Python 3.7 support
from typing_extensions import Literal
from typing import Optional, Iterable, Literal

if sys.version_info < (3, 9):
class BooleanOptionalAction(argparse.Action):
Expand Down
3 changes: 1 addition & 2 deletions interfaces/cython/setup.cfg.in
Expand Up @@ -23,10 +23,10 @@ classifiers =
Programming Language :: Cython
Programming Language :: Fortran
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
speth marked this conversation as resolved.
Show resolved Hide resolved
Programming Language :: Python :: Implementation :: CPython
Topic :: Scientific/Engineering :: Chemistry
Topic :: Scientific/Engineering :: Physics
Expand All @@ -42,7 +42,6 @@ include_package_data = True
install_requires =
numpy >= 1.12.0
ruamel.yaml >= 0.15.34
typing_extensions >=4.2.0,<4.3.0;python_version<'3.8'
python_requires = >=@py_min_ver_str@
packages =
cantera
Expand Down
5 changes: 2 additions & 3 deletions interfaces/python_minimal/setup.cfg.in
Expand Up @@ -19,10 +19,10 @@ classifiers =
Operating System :: Microsoft :: Windows
Operating System :: POSIX :: Linux
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Topic :: Scientific/Engineering :: Chemistry
Topic :: Scientific/Engineering :: Physics
project_urls =
Expand All @@ -36,7 +36,6 @@ zip_safe = True
install_requires =
numpy >= 1.12.0
ruamel.yaml >= 0.15.34
typing_extensions >=4.2.0,<4.3.0;python_version<'3.8'
python_requires = >=@py_min_ver_str@
packages =
cantera
Expand Down
5 changes: 2 additions & 3 deletions interfaces/python_sdist/setup.cfg.in
Expand Up @@ -23,10 +23,10 @@ classifiers =
Programming Language :: Cython
Programming Language :: Fortran
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: Implementation :: CPython
Topic :: Scientific/Engineering :: Chemistry
Topic :: Scientific/Engineering :: Physics
Expand All @@ -42,7 +42,6 @@ include_package_data = True
install_requires =
numpy >= 1.12.0
ruamel.yaml >= 0.15.34
typing_extensions >=4.2.0,<4.3.0;python_version<'3.8'
python_requires = >=@py_min_ver_str@
packages =
cantera
Expand Down
4 changes: 0 additions & 4 deletions site_scons/buildutils.py
Expand Up @@ -1327,10 +1327,6 @@ def setup_python_env(env):
env.Append(LIBS=f"python{py_version_nodot}")
if env['OS_BITS'] == 64:
env.Append(CPPDEFINES='MS_WIN64')
# Fix for https://bugs.python.org/issue11566. Fixed in 3.7.3 and higher.
# See https://github.com/python/cpython/pull/11283
if py_version_full < parse_version("3.7.3"):
env.Append(CPPDEFINES={"_hypot": "hypot"})

if "numpy_1_7_API" in env:
env.Append(CPPDEFINES="NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION")
Expand Down