Skip to content

Commit

Permalink
feat: Add Python 3.11 to testing and default to using it (#2145)
Browse files Browse the repository at this point in the history
* Add Python 3.11 to testing in CI.
* Default to using Python 3.11 in GitHub Actions where possible.
* Update to using Python 3.11 in linting and validation tools.
* Update Binder runtime Python to Python 3.11.
* Update Dockerfile base image to python:3.11-slim-bullseye.
* Update the docs to advocate using Python 3.11 for development.
* Add ignore of DeprecationWarning of Python's sre_constants from TensorFlow
   - c.f. https://docs.python.org/3.11/whatsnew/3.11.html#modules
     > Undocumented modules sre_compile, sre_constants and sre_parse
     > are now deprecated. (Contributed by Serhiy Storchaka in bpo-47152.)
* Add Python 3.11 trove classifier to PyPI metadata.
  • Loading branch information
matthewfeickert authored Mar 23, 2023
1 parent c56a327 commit 28c6172
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ jobs:
echo ::set-output name=old_tag::v${current_tag}
- name: Set up Python 3.10
- name: Set up Python 3.11
if: success()
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Install Python dependencies
run: |
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10', '3.11']
include:
- os: macos-latest
python-version: '3.10'
python-version: '3.11'

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -80,30 +80,30 @@ jobs:
coverage xml
- name: Report contrib coverage with Codecov
if: github.event_name != 'schedule' && matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
if: github.event_name != 'schedule' && matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: contrib

- name: Test docstring examples with doctest
if: matrix.python-version == '3.10'
if: matrix.python-version == '3.11'
run: coverage run --data-file=.coverage-doctest --module pytest src/ README.rst

- name: Coverage report for doctest only
if: matrix.python-version == '3.10'
if: matrix.python-version == '3.11'
run: |
coverage report --data-file=.coverage-doctest
coverage xml --data-file=.coverage-doctest -o doctest-coverage.xml
- name: Report doctest coverage with Codecov
if: github.event_name != 'schedule' && matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
if: github.event_name != 'schedule' && matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
files: doctest-coverage.xml
flags: doctest

- name: Run benchmarks
if: github.event_name == 'schedule' && matrix.python-version == '3.10'
if: github.event_name == 'schedule' && matrix.python-version == '3.11'
run: |
pytest --benchmark-sort=mean tests/benchmarks/test_benchmark.py
12 changes: 6 additions & 6 deletions .github/workflows/dependencies-head.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v3
Expand All @@ -103,7 +103,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v3
Expand All @@ -128,7 +128,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Install Python dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
with:
fetch-depth: 0

- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Install python-build and twine
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10', '3.11']
include:
- os: macos-latest
python-version: '3.10'
python-version: '3.11'

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ repos:
['numpy', 'types-tqdm', 'click', 'types-jsonpatch', 'types-pyyaml', 'types-jsonschema', 'importlib_metadata', 'packaging']
args: ["--python-version=3.8"]
- <<: *mypy
name: mypy with Python 3.10
args: ["--python-version=3.10"]
name: mypy with Python 3.11
args: ["--python-version=3.11"]

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.3
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.10"
python: "3.11"
apt_packages:
- curl
- jq
Expand Down
2 changes: 1 addition & 1 deletion binder/runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.10
python-3.11
1 change: 1 addition & 0 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"runtimePlatform": [
"Python 3",
"Python 3 Only",
"Python 3.11",
"Python 3.10",
"Python 3.8",
"Python 3.9",
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BASE_IMAGE=python:3.10-slim-bullseye
ARG BASE_IMAGE=python:3.11-slim-bullseye
# hadolint ignore=DL3006
FROM ${BASE_IMAGE} as base

Expand Down
6 changes: 3 additions & 3 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ contrib module, or notebooks, and so instead to test the core codebase a develop

.. code-block:: console
nox --session tests --python 3.10
nox --session tests --python 3.11
Contrib module matplotlib image tests
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -107,7 +107,7 @@ To run the visualization tests for the ``contrib`` module with the ``pytest-mpl`

.. code-block:: console
nox --session tests --python 3.10 -- contrib
nox --session tests --python 3.11 -- contrib
If the image files need to be regenerated, run the tests with the
``--mpl-generate-path=tests/contrib/baseline`` option or just run
Expand Down Expand Up @@ -141,7 +141,7 @@ or pass ``coverage`` as a positional argument to the ``nox`` ``tests`` session

.. code-block:: console
nox --session tests --python 3.10 -- coverage
nox --session tests --python 3.11 -- coverage
Coverage Report
^^^^^^^^^^^^^^^
Expand Down
12 changes: 6 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import nox

ALL_PYTHONS = ["3.8", "3.9", "3.10"]
ALL_PYTHONS = ["3.8", "3.9", "3.10", "3.11"]

# Default sessions to run if no session handles are passed
nox.options.sessions = ["lint", "tests-3.10"]
nox.options.sessions = ["lint", "tests-3.11"]


DIR = Path(__file__).parent.resolve()
Expand All @@ -30,10 +30,10 @@ def tests(session):
Examples:
$ nox --session tests --python 3.10
$ nox --session tests --python 3.10 -- contrib # run the contrib module tests
$ nox --session tests --python 3.10 -- tests/test_tensor.py # run specific tests
$ nox --session tests --python 3.10 -- coverage # run with coverage but slower
$ nox --session tests --python 3.11
$ nox --session tests --python 3.11 -- contrib # run the contrib module tests
$ nox --session tests --python 3.11 -- tests/test_tensor.py # run specific tests
$ nox --session tests --python 3.11 -- coverage # run with coverage but slower
"""
session.install("--upgrade", "--editable", ".[test]")
session.install("--upgrade", "pytest")
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ classifiers = [
"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",
"Topic :: Scientific/Engineering :: Physics",
Expand Down Expand Up @@ -150,7 +151,7 @@ packages = ["src/pyhf"]

[tool.black]
line-length = 88
target-version = ['py38', 'py39', 'py310']
target-version = ['py38', 'py39', 'py310', 'py311']
skip-string-normalization = true
include = '\.pyi?$'
exclude = '''
Expand Down Expand Up @@ -210,6 +211,7 @@ filterwarnings = [
'ignore:[A-Z]+ is deprecated and will be removed in Pillow 10:DeprecationWarning', # keras
'ignore:Call to deprecated create function:DeprecationWarning', # protobuf via tensorflow
'ignore:`np.bool8` is a deprecated alias for `np.bool_`:DeprecationWarning', # numpy via tensorflow
"ignore:module 'sre_constants' is deprecated:DeprecationWarning", # tensorflow v2.12.0+ for Python 3.11+
]

[tool.coverage.run]
Expand All @@ -224,7 +226,7 @@ show_missing = true

[tool.mypy]
files = "src"
python_version = "3.10"
python_version = "3.11"
warn_unused_configs = true
strict = true
show_error_codes = true
Expand Down

0 comments on commit 28c6172

Please sign in to comment.