Skip to content

Commit

Permalink
feat: add python 3.11 support (#392)
Browse files Browse the repository at this point in the history
* feat: add python 3.11 support

- adds testing for python 3.11
- moves from black and flake8 to ruff for linting
- Updates coverage output from tests

* fix: fix dev dependency group

* fix: add installing dev dependencies

* ci: add toml

* ci: simplify coverage

* ci: update coverage
  • Loading branch information
andrewthetechie committed Feb 21, 2023
1 parent 6ae5ece commit a752c42
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 532 deletions.
1 change: 1 addition & 0 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ nox-poetry==1.0.2
poetry==1.3.2
virtualenv==20.19.0
poetry-dynamic-versioning==0.21.3
toml==0.10.2
38 changes: 10 additions & 28 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ jobs:
# - { python: "3.9", os: "ubuntu-latest", session: "mypy" }
# - { python: "3.8", os: "ubuntu-latest", session: "mypy" }
# - { python: "3.7", os: "ubuntu-latest", session: "mypy" }
- { python: "3.11", os: "ubuntu-latest", session: "tests" }
- { python: "3.10", os: "ubuntu-latest", session: "tests" }
- { python: "3.9", os: "ubuntu-latest", session: "tests" }
- { python: "3.8", os: "ubuntu-latest", session: "tests" }
- { python: "3.7", os: "ubuntu-latest", session: "tests" }
# poetry fails to install on windows
# - { python: "3.10", os: "windows-latest", session: "tests" }
# - { python: "3.10", os: "macos-latest", session: "tests" }
# - { python: "3.10", os: "ubuntu-latest", session: "typeguard" }
- { python: "3.11", os: "macos-latest", session: "tests" }
- { python: "3.10", os: "ubuntu-latest", session: "xdoctest" }
- { python: "3.10", os: "ubuntu-latest", session: "docs-build" }

Expand Down Expand Up @@ -63,7 +64,7 @@ jobs:
- name: Install Nox
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry toml
nox --version
- name: Compute pre-commit cache key
Expand All @@ -73,13 +74,15 @@ jobs:
run: |
import hashlib
import sys
import os
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
print("::set-output name=result::{}".format(result))
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
fh.write(f"result={result}\n")
- name: Restore pre-commit cache
uses: actions/cache@v3.2.5
Expand Down Expand Up @@ -112,34 +115,13 @@ jobs:
runs-on: ubuntu-latest
needs: tests
steps:
- name: Check out the repository
uses: actions/checkout@v3.1.0

- name: Set up Python
uses: actions/setup-python@v4.5.0
with:
python-version: "3.10"

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
nox --version
- name: Download coverage data
uses: actions/download-artifact@v3.0.2
with:
name: coverage-data

- name: Upload coverage report
uses: codecov/codecov-action@v3.1.1
with:
files: .coverage.xml
verbose: true
22 changes: 11 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.249"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types: [python]
- repo: local
hooks:
- id: black
name: black
entry: black
- id: bandit
name: bandit
entry: bandit
language: system
types: [python]
require_serial: true
args: ["-c", "bandit.yml"]
- id: check-added-large-files
name: Check for added large files
entry: check-added-large-files
Expand All @@ -27,14 +35,6 @@ repos:
language: system
types: [text]
stages: [commit, push, manual]
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
exclude: "^(test/*|examples/*|noxfile.py)"
require_serial: true
args: ["--config=.flake8"]
- id: pyupgrade
name: pyupgrade
description: Automatically upgrade syntax for newer versions.
Expand Down
3 changes: 3 additions & 0 deletions bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exclude_dirs: ["test", "examples"]
assert_used:
skips: ["*/test_*.py", "noxfile.py"]
45 changes: 9 additions & 36 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from textwrap import dedent

import nox
import toml

try:
from nox_poetry import Session
Expand All @@ -22,7 +23,7 @@


package = "healthchecks_io"
python_versions = ["3.10", "3.9", "3.8", "3.7"]
python_versions = ["3.10", "3.11", "3.9", "3.8", "3.7"]
nox.needs_version = ">= 2021.6.6"
nox.options.sessions = (
"pre-commit",
Expand All @@ -43,6 +44,9 @@
"pytest-asyncio",
"pytest-lazy-fixture",
)
mypy_type_packages = ()
pyproject = toml.load("pyproject.toml")
test_requirements = pyproject["tool"]["poetry"]["group"]["dev"]["dependencies"].keys()


def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
Expand All @@ -61,8 +65,7 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
# quoting rules for Python and bash, but strip the outermost quotes so we
# can detect paths within the bindir, like <bindir>/python.
bindirs = [
bindir[1:-1] if bindir[0] in "'\"" else bindir
for bindir in (repr(session.bin), shlex.quote(session.bin))
bindir[1:-1] if bindir[0] in "'\"" else bindir for bindir in (repr(session.bin), shlex.quote(session.bin))
]

virtualenv = session.env.get("VIRTUAL_ENV")
Expand Down Expand Up @@ -99,10 +102,7 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None:

text = hook.read_text()

if not any(
Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text
for bindir in bindirs
):
if not any(Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text for bindir in bindirs):
continue

lines = text.splitlines()
Expand Down Expand Up @@ -144,9 +144,7 @@ def safety(session: Session) -> None:
session.install("safety")
# ignore https://github.com/pytest-dev/py/issues/287
# its an irresposnbily filed CVE causing nose
session.run(
"safety", "check", "--full-report", f"--file={requirements}", "--ignore=51457"
)
session.run("safety", "check", "--full-report", f"--file={requirements}", "--ignore=51457")


@session(python=python_versions)
Expand All @@ -171,32 +169,7 @@ def tests(session: Session) -> None:
"""Run the test suite."""
session.install(".")
session.install(*test_requirements)
try:
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
finally:
if session.interactive:
session.notify("coverage", posargs=[])


@session(python=python_versions[0])
def coverage(session: Session) -> None:
"""Produce the coverage report."""
args = session.posargs or ["report"]

session.install("coverage[toml]")

if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine")

session.run("coverage", *args)


@session(python=python_versions)
def typeguard(session: Session) -> None:
"""Runtime type checking using Typeguard."""
session.install(".")
session.install("pytest", "typeguard", "pygments")
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
session.run("poetry", "run", "pytest", *session.posargs)


@session(python=python_versions)
Expand Down
Loading

0 comments on commit a752c42

Please sign in to comment.