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

Introduce tox #244

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/actions/setup-python-uv/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ inputs:
uv-version:
description: "The uv version to set up"
required: true
default: "0.4.18"
default: "0.5.8"

runs:
using: "composite"
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- uses: astral-sh/setup-uv@v3
- uses: astral-sh/setup-uv@v5
with:
version: ${{ inputs.uv-version }}
enable-cache: true
cache-dependency-glob: "uv.lock"
- run: |
uv sync --frozen --all-extras --dev
echo "$(pwd)/.venv/bin" >> $GITHUB_PATH
uv pip install --system tox tox-uv
shell: bash
38 changes: 24 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ jobs:
- uses: ./.github/actions/setup-python-uv
with:
python-version: ${{ matrix.python-version }}
- run: uv run coverage run --source=. --parallel-mode -m pytest tests
- run: tox run -e py
- name: Upload coverage results
uses: actions/upload-artifact@v4
if: matrix.os == 'ubuntu-latest' # Cross-platform coverage combination doesn't work
with:
name: coverage-results-${{ matrix.python-version }}
path: coverage/
path: .coverage*
Tutorial-tests:
runs-on: ubuntu-latest
name: Tutorial tests
Expand All @@ -58,13 +58,15 @@ jobs:
python-version: "3.10"
- name: Install cadwyn with instructions from docs
run: sh docs_src/quickstart/setup/block001.sh
- run: pip install pytest coverage dirty-equals
- run: coverage run --source=. --parallel-mode -m pytest docs_src
- run: |
pip install uv
uv pip install --system pytest coverage dirty-equals
coverage run -m pytest docs_src
- name: Upload coverage results
uses: actions/upload-artifact@v4
with:
name: coverage-results-docs
path: coverage/
path: .coverage*
Coverage:
needs: [Tests, Tutorial-tests]
runs-on: ubuntu-latest
Expand All @@ -75,32 +77,40 @@ jobs:
with:
pattern: coverage-results-*
merge-multiple: true
path: coverage/
path: .
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: pip install 'coverage[toml]'
- run: coverage combine
- run: coverage xml
- run: |
pip install uv
uv pip install --system tox tox-uv
tox run -e coverage_report-ci
- name: Upload to Codecov
uses: codecov/codecov-action@v4
env:
fail_ci_if_error: true
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- run: coverage report --fail-under=100 --show-missing

Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pre-commit/action@v3.0.0
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: |
python -m pip install uv
uv pip install --system pre-commit pre-commit-uv
pre-commit run --all-files

Typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python-uv

- uses: jakebailey/pyright-action@v1
with:
pylance-version: latest-release
# When this version is updated,
# update the pyright `base_python` version in `tox.ini`, too.
python-version: "3.10"
- run: |
tox run -e pyright
2 changes: 1 addition & 1 deletion .github/workflows/daily_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- run: uv sync --refresh --all-extras --dev --upgrade
- run: pytest .
- run: tox run -e py
- uses: jakebailey/pyright-action@v1
with:
pylance-version: latest-release
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/validate_links.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python-uv
- run: |
OUTPUT=$(uv run mkdocs build 2>&1)
echo "$OUTPUT"

if echo "$OUTPUT" | grep -q "ERROR"; then
exit 1
fi
tox run -e docs

markdown-link-check:
runs-on: ubuntu-latest
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ lint:
pre-commit run --all-files

test:
rm -r coverage; \
uv run coverage run --source=. -m pytest .; \
uv run coverage combine; \
uv run coverage report --fail-under=100 --show-missing;
uv run --with tox --with tox-uv tox
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ dev-dependencies = [
"pytest-cov >=4.0.0",
"dirty-equals >=0.6.0",
"uvicorn ~=0.23.0",
# type checking
"pyright>=1.1.390",
# docs
"mkdocs >=1.5.2",
"mkdocs-material >=9.3.1",
Expand All @@ -99,6 +101,7 @@ parallel = true
branch = true

[tool.coverage.report]
fail_under = 100
skip_covered = true
skip_empty = true
# Taken from https://coverage.readthedocs.io/en/7.1.0/excluding.html#advanced-exclusion
Expand Down
12 changes: 2 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import textwrap

import pytest
Expand All @@ -9,7 +8,7 @@


def code(c: str) -> str:
return textwrap.dedent(c.strip())
return "\n".join(line.rstrip() for line in textwrap.dedent(c.strip()).splitlines())


def test__render_module():
Expand Down Expand Up @@ -70,14 +69,7 @@ def test__render_model__with_syntax_highlighting(): # pragma: no cover
],
)
assert result.exit_code == 0

if sys.platform.startswith("win32"):
# Windows rendering is weird
return

assert code(result.stdout) == (
"1 class A(BaseModel): \n 2 pass"
)
assert code(result.stdout) == "1 class A(BaseModel):\n 2 pass"


@pytest.mark.parametrize("arg", ["-V", "--version"])
Expand Down
61 changes: 61 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[tox]
envlist =
coverage_erase
# When updating Python versions, use search-and-replace
# against the entire list of of versions
# to ensure consistency throughout this file.
py{3.13, 3.12, 3.11, 3.10}
coverage_report
docs
pyright


[testenv]
runner = uv-venv-lock-runner
with_dev = true
extras =
standard
package = wheel
wheel_build_env = build_wheel
depends =
py{3.13, 3.12, 3.11, 3.10}: coverage_erase
commands = coverage run -m pytest {posargs}


[testenv:coverage_erase]
skip_install = true
commands = coverage erase


[testenv:coverage_report]
skip_install = true
depends =
py{3.13, 3.12, 3.11, 3.10}
commands_pre =
# Ignore the exit code of `coverage combine`
# (in case the reports are already combined).
- coverage combine
commands =
coverage report --show-missing


[testenv:coverage_report-ci]
# Inherit everything from the `coverage_report` environment,
# but generate an XML report and ignore exit codes.
base = coverage_report
commands =
- coverage xml --fail-under=0
- coverage report --show-missing


[testenv:docs]
base_python = py3.10
skip_install = true
commands = mkdocs build --strict


[testenv:pyright]
# When the Python version is updated here,
# update the version used in the CI `Typecheck` job, too.
base_python = py3.10
commands = pyright
24 changes: 24 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading