Skip to content

Commit

Permalink
set python version in nox sessions when syncing uv (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidthomas authored Oct 10, 2024
1 parent b2641f9 commit 4998781
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
25 changes: 7 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ concurrency:
env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"
UV_VERSION: "0.4.x"

jobs:
generate-matrix:
Expand All @@ -26,10 +27,7 @@ jobs:
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
version: "0.4.x"

- name: Install Python
run: uv python install 3.10
version: ${{ env.UV_VERSION }}

- id: set-matrix
run: |
Expand All @@ -49,10 +47,7 @@ jobs:
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
version: "0.4.x"

- name: Install Python
run: uv python install ${{ matrix.python-version }}
version: ${{ env.UV_VERSION }}

- name: Run tests
run: |
Expand All @@ -79,12 +74,9 @@ jobs:
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
version: "0.4.x"
version: ${{ env.UV_VERSION }}

- name: Install Python
run: uv python install 3.13

- name: Run mypy
- name: Run type checks
run: |
uv run nox --session "types"
Expand All @@ -97,11 +89,8 @@ jobs:
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
version: "0.4.x"

- name: Install Python
run: uv python install 3.10
version: ${{ env.UV_VERSION }}

- name: Run mypy
- name: Generate code coverage
run: |
uv run nox --session "coverage"
24 changes: 16 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ def tests(session, django):
session.run_install(
"uv",
"sync",
"--frozen",
"--extra",
"tests",
"--frozen",
"--inexact",
"--no-install-package",
"django",
"--python",
session.python,
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)

Expand All @@ -86,7 +88,7 @@ def tests(session, django):
else:
session.install(f"django=={django}")

command = ["pytest"]
command = ["python", "-m", "pytest"]
if session.posargs and all(arg for arg in session.posargs):
command.append(*session.posargs)
session.run(*command)
Expand All @@ -97,16 +99,18 @@ def coverage(session):
session.run_install(
"uv",
"sync",
"--frozen",
"--extra",
"tests",
"--frozen",
"--python",
PY_DEFAULT,
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)

try:
session.run("pytest", "--cov", "--cov-report=")
session.run("python", "-m", "pytest", "--cov", "--cov-report=")
finally:
report_cmd = ["coverage", "report"]
report_cmd = ["python", "-m", "coverage", "report"]
session.run(*report_cmd)

if summary := os.getenv("GITHUB_STEP_SUMMARY"):
Expand All @@ -118,21 +122,25 @@ def coverage(session):
output_buffer.flush()
session.run(*report_cmd, stdout=output_buffer)
else:
session.run("coverage", "html", "--skip-covered", "--skip-empty")
session.run(
"python", "-m", "coverage", "html", "--skip-covered", "--skip-empty"
)


@nox.session
def types(session):
session.run_install(
"uv",
"sync",
"--frozen",
"--extra",
"types",
"--frozen",
"--python",
PY_LATEST,
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)

command = ["mypy", "."]
command = ["python", "-m", "mypy", "."]
if session.posargs and all(arg for arg in session.posargs):
command.append(*session.posargs)
session.run(*command)
Expand Down

0 comments on commit 4998781

Please sign in to comment.