Skip to content

Commit

Permalink
Support Python 3.12; prevent unnecessary builds (#872)
Browse files Browse the repository at this point in the history
* Support Python 3.12; prevent unnecessary builds

* Fix openapi schema validation to be python 3.12-compatible

prance doesn't work with Python 3.12, and isn't needed anyway
also remove unnecessary 'validation' extra from setup.py

* Remove lint errors

* Update changelog
  • Loading branch information
sloria committed Jan 10, 2024
1 parent 89151df commit 6651e86
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 46 deletions.
39 changes: 22 additions & 17 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
name: build
on:
push:
branches: ["dev"]
branches: ["dev", "*.x-line"]
tags: ["*"]
pull_request:
# Run builds nightly to catch incompatibilities with new marshmallow releases
schedule:
- cron: "0 0 * * *"
jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: python -m pip install --upgrade pip wheel
- run: pip install tox
- run: tox -elint
tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
Expand All @@ -31,16 +22,16 @@ jobs:
tox: py38-marshmallow3,
}
- {
name: "3.11-ma3",
python: "3.11",
name: "3.12-ma3",
python: "3.12",
os: ubuntu-latest,
tox: py311-marshmallow3,
tox: py312-marshmallow3,
}
- {
name: "3.11-madev",
python: "3.11",
name: "3.12-madev",
python: "3.12",
os: ubuntu-latest,
tox: py311-marshmallowdev,
tox: py312-marshmallowdev,
}
steps:
- uses: actions/checkout@v2
Expand All @@ -50,8 +41,22 @@ jobs:
- run: python -m pip install --upgrade pip wheel
- run: pip install tox
- run: tox -e${{ matrix.tox }}
# this duplicates pre-commit.ci, so only run it on tags
# it guarantees that linting is passing prior to a release
lint-pre-release:
name: lint
if: startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/setup-python@v4.3.0
with:
python-version: "3.11"
- run: python -m pip install --upgrade pip
- run: python -m pip install tox
- run: python -m tox -elint
release:
needs: [lint, tests]
needs: [tests, lint-pre-release]
name: PyPI release
if: startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Changelog

Other changes:

- Support Python 3.12.
- Drop support for Python 3.7, which is EOL.
- Remove `[validation]` from extras, as it is no longer used.


6.3.1 (2023-12-21)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[tool.black]
line-length = 88
target-version = ['py38', 'py39', 'py310', 'py311']
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
EXTRAS_REQUIRE = {
"marshmallow": ["marshmallow>=3.18.0"],
"yaml": ["PyYAML>=3.10"],
"validation": ["prance[osv]>=0.11"],
"lint": [
"flake8==7.0.0",
"flake8-bugbear==22.12.6",
Expand All @@ -22,11 +21,11 @@
"sphinx-rtd-theme==2.0.0",
],
}
EXTRAS_REQUIRE["tests"] = (
EXTRAS_REQUIRE["yaml"]
+ EXTRAS_REQUIRE["validation"]
+ ["marshmallow>=3.13.0", "pytest"]
)
EXTRAS_REQUIRE["tests"] = EXTRAS_REQUIRE["yaml"] + [
"marshmallow>=3.13.0",
"openapi-spec-validator==0.7.1",
"pytest",
]
EXTRAS_REQUIRE["dev"] = EXTRAS_REQUIRE["tests"] + EXTRAS_REQUIRE["lint"] + ["tox"]


Expand Down Expand Up @@ -78,6 +77,7 @@ def read(fname):
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
],
test_suite="tests",
Expand Down
25 changes: 5 additions & 20 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utilities to get elements of generated spec"""
import json
import openapi_spec_validator
from openapi_spec_validator.exceptions import OpenAPISpecValidatorError

from apispec.core import APISpec
from apispec import exceptions
Expand Down Expand Up @@ -52,28 +53,12 @@ def validate_spec(spec: APISpec) -> bool:
"""Validate the output of an :class:`APISpec` object against the
OpenAPI specification.
Note: Requires installing apispec with the ``[validation]`` extras.
::
pip install 'apispec[validation]'
:raise: apispec.exceptions.OpenAPIError if validation fails.
"""
try:
import prance
except ImportError as error: # re-raise with a more verbose message
exc_class = type(error)
raise exc_class(
"validate_spec requires prance to be installed. "
"You can install all validation requirements using:\n"
" pip install 'apispec[validation]'"
) from error
parser_kwargs = {}
if spec.openapi_version.major == 3:
parser_kwargs["backend"] = "openapi-spec-validator"
try:
prance.BaseParser(spec_string=json.dumps(spec.to_dict()), **parser_kwargs)
except prance.ValidationError as err:
# Coerce to dict to satisfy Pyright
openapi_spec_validator.validate(dict(spec.to_dict()))
except OpenAPISpecValidatorError as err:
raise exceptions.OpenAPIError(*err.args) from err
else:
return True
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
envlist=
lint
py{38,39,310,311}-marshmallow3
py311-marshmallowdev
py{38,39,310,311,312}-marshmallow3
py312-marshmallowdev
docs

[testenv]
Expand Down

0 comments on commit 6651e86

Please sign in to comment.