Skip to content

Commit

Permalink
build: switch to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Dec 31, 2024
1 parent c8a26c2 commit 30c695b
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 10 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,30 @@ jobs:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', pypy3.9, pypy3.10]
os: [ubuntu-latest, windows-latest, macos-13]
extra_deps: ['"--with=pytest==8.3.3" "--with=pydantic<2"', '"--with=pytest>=8.3.4" "--with=pydantic>2"']
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{matrix.python-version}}
architecture: x64
allow-prereleases: true
- run: pip install hatch

- run: |
hatch test -cp -py ${{matrix.python-version}}
mv .coverage .coverage.${{ matrix.python-version }}.${{matrix.os}}
if: matrix.os == 'ubuntu-latest'

- run: hatch test -p -py ${{matrix.python-version}}
if: matrix.os != 'ubuntu-latest'

- run: |
uv run ${{matrix.extra_deps}} --group=optional duty test ${{ matrix.os == 'ubuntu-latest' && 'coverage=True' }}
mv .coverage .coverage.${{ matrix.python-version }}-${{matrix.os}}-${{github.run_id}}
- name: Upload coverage data
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: coverage-data-${{ matrix.python-version }}-${{matrix.os}}
name: coverage-data-${{ matrix.python-version }}-${{matrix.os}}-${{github.run_id}}
path: .coverage.*
include-hidden-files: true
if-no-files-found: ignore
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ repos:
# - id: docformatter

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
rev: v0.23
hooks:
- id: validate-pyproject
# Optional extra validations from SchemaStore:
Expand Down
73 changes: 73 additions & 0 deletions duties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import os
from pathlib import Path

from duty import duty

root = Path(__file__).resolve().parent


@duty
def test(ctx, coverage=False, parallel=True, coverage_name=None, review=False):
cmd = ["pytest"]
if review:
parallel = False
cmd += ["--inline-snapshot=review"]

if parallel:
cmd += ["-n=auto"]
if coverage:
cmd = ["python", "-m", "coverage", "run", "-m", *cmd]
os.environ["TOP"] = str(root)
os.environ["COVERAGE_PROCESS_START"] = str(root / "pyproject.toml")
else:
cmd = ["python", "-Im", *cmd]

ctx.run(cmd, title="Run tests", capture=False)

if coverage:
ctx.run("python -Im coverage combine", title="combine coverage")

if coverage_name is None:
ctx.run(
"python -Im coverage html --skip-empty",
title="generate html report htmlcov/index.html",
)
else:
ctx.run(f"mv .coverage .coverage.{coverage_name}")


@duty
def test_all(ctx):
for python in ["3.12", "3.8", "3.11", "pypy3.10"]:
for deps_n, extra_args in enumerate(
[
("--with=pytest==8.3.3", "--with=pydantic<2"),
("--with=pytest>=8.3.4", "--with=pydantic>2"),
]
):
coverage_name = python.replace(".", "") + "_" + str(deps_n)
ctx.run(
[
"uv",
"run",
"-p",
python,
*extra_args,
"--reinstall",
"--group=optional",
"duty",
"test",
"coverage=True",
f"coverage_name={coverage_name}",
]
)

os.environ["TOP"] = str(Path.cwd())
print("TOP:", os.environ["TOP"])
ctx.run("python -Im coverage combine", title="combine coverage")
ctx.run(
"python -Im coverage html --skip-empty",
title="generate coverage report",
)

ctx.run("coverage report")
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,24 @@ version = "command: cz bump --get-next"

[tool.pytest.ini_options]
markers=["no_rewriting: marks tests which need no code rewriting and can be used with pypy"]

[dependency-groups]
dev = [
"duty>=1.4.2",
"hypothesis>=6.75.5",
"mypy>=1.2.0",
"pyright>=1.1.359",
"pytest-subtests>=0.11.0",
"pytest-freezer>=0.4.8",
"pytest-mock>=3.14.0",
"pytest-xdist>=3.6.1",
"coverage[toml]>=7.6.1",
"coverage-enable-subprocess>=1.0",
"pytest>=8.3.4",
]
optional=[
"dirty-equals>=0.7.0",
"attrs>=24.3.0",
"pydantic>=1",

]

0 comments on commit 30c695b

Please sign in to comment.