Skip to content

Commit

Permalink
add support for python 3.12 and 3.13 (#363)
Browse files Browse the repository at this point in the history
* add support for python 3.12 and 3.13

This also changes the projects default python version to 3.12

* streamline environment setup by consolidating installation steps for Poetry, Nox, and nox-poetry

* update Nox command to specify Python version in CI
  • Loading branch information
shadycuz committed Nov 5, 2024
1 parent 5c0f599 commit 11fbddf
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 165 deletions.
10 changes: 6 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

# Install the required python versions (this takes a bit usually) so we do lots of cacheing
RUN --mount=type=cache,target=/home/vscode/.pyenv/cache,uid=1000 \
pyenv install -s 3.8.13 && \
pyenv install -s 3.9.12 && \
pyenv install -s 3.10.4 && \
pyenv global 3.9.12 3.10.4 3.8.13 && \
pyenv install -s 3.9.20 && \
pyenv install -s 3.10.15 && \
pyenv install -s 3.11.10 && \
pyenv install -s 3.12.7 && \
pyenv install -s 3.13.0 && \
pyenv global 3.12.7 3.13.0 3.11.10 3.10.15 3.9.20 && \
pyenv rehash

# Install poetry to manage our python project
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Python 3.9
- name: Setup Python 3.12
uses: actions/[email protected]
with:
python-version: '3.9'
python-version: '3.12'
architecture: x64

- name: Install dependencies
Expand Down Expand Up @@ -74,10 +74,10 @@ jobs:
- name: Checkout Code
uses: actions/[email protected]

- name: Setup Python 3.9
- name: Setup Python 3.12
uses: actions/[email protected]
with:
python-version: '3.9'
python-version: '3.12'
architecture: x64

- name: Setup Poetry
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Latest Python
uses: actions/[email protected]
with:
python-version: 3.9
python-version: 3.12
architecture: x64

- name: Setup Poetry
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9']
python-version: ['3.9', '3.10', '3.11', '3.13']
name: Python ${{ matrix.python-version }}
steps:
- name: Checkout Code
Expand All @@ -61,11 +61,10 @@ jobs:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Setup Nox
run: pip install nox==2020.8.22

- name: Setup Poetry
run: pip install poetry==1.4.2
# Install Poetry Nox and nox-poetry
- name: Setup Environment
run: |
pip install poetry nox nox-poetry
- name: Run Tests
run: nox
run: nox -p ${{ matrix.python-version }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ See the [open issues](https://github.com/DontShaveTheYak/cloud-radar/issues) for

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

This project uses poetry to manage dependencies and pre-commit to run formatting, linting and tests. You will need to have both installed to your system as well as python 3.9.
This project uses poetry to manage dependencies and pre-commit to run formatting, linting and tests. You will need to have both installed to your system as well as python 3.12.

1. Fork the Project
2. Setup environment (`poetry install`)
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[mypy]
allow_redefinition = True
[mypy-nox.*,taskcat.*,pytest]
[mypy-nox.*,taskcat.*,pytest,nox_poetry]
ignore_missing_imports = True
98 changes: 54 additions & 44 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,71 @@
import tempfile
"""Nox sessions."""

import sys
from textwrap import dedent

import nox

nox.options.sessions = "lint", "mypy", "tests"
try:
from nox_poetry import Session, session
except ImportError:
message = f"""\
Nox failed to import the 'nox-poetry' package.
locations = "src", "tests", "noxfile.py"
Please install it using the following command:
{sys.executable} -m pip install nox-poetry"""
raise SystemExit(dedent(message)) from None

def install_with_constraints(session, *args, **kwargs):
with tempfile.NamedTemporaryFile() as requirements:
session.run(
"poetry",
"export",
"--only",
"dev",
"--format=requirements.txt",
"--without-hashes",
f"--output={requirements.name}",
external=True,
)
session.install("-r", requirements.name, *args, **kwargs)
nox.options.sessions = "mypy", "tests"

locations = "src", "tests", "noxfile.py"

@nox.session(python="3.9")
def coverage(session):
"""Upload coverage data."""
install_with_constraints(session)
session.run("coverage", "xml", "--fail-under=0")
session.run("codecov", *session.posargs)
default_python = "3.12"

python_versions = ["3.9", "3.10", "3.11", "3.12", "3.13"]

@nox.session(python=["3.9", "3.8"])
def tests(session):
args = session.posargs or ["--cov", "-m", "not e2e"]
session.run("poetry", "install", "--only", "main", external=True)
install_with_constraints(
session,
)
session.run("pytest", *args)

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

@nox.session(python=["3.9", "3.8"])
def lint(session):
args = session.posargs or locations
install_with_constraints(session)
session.run("flake8", *args)
# session.install("coverage[toml]")

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

@nox.session(python=["3.9", "3.8"])
def mypy(session):
args = session.posargs or locations
install_with_constraints(session)
session.run("mypy", *args)
# session.run("coverage", *args)


@session(python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
session.install(".")
session.install("coverage[toml]", "pytest", "pygments", "pytest-mock")
try:
session.run(
"coverage",
"run",
"--parallel",
"-m",
"pytest",
"-m",
"not e2e",
"tests",
*session.posargs,
)
finally:
pass
# if session.interactive:
# session.notify("coverage", posargs=[])


@nox.session(python="3.9")
def black(session):
@session(python=python_versions)
def mypy(session: Session) -> None:
"""Type-check using mypy."""
args = session.posargs or locations
install_with_constraints(session)
session.run("black", *args)
session.run_always("poetry", "install", external=True)
session.run("mypy", *args)
if not session.posargs:
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
Loading

0 comments on commit 11fbddf

Please sign in to comment.