Skip to content

Commit

Permalink
uv in the noxfile and CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Oct 8, 2024
1 parent 8eed933 commit 19de742
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 33 deletions.
33 changes: 16 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,17 @@ name: CI

on:
push:
branches-ignore:
- "wip*"
tags:
- "v*"
pull_request:
release:
types: [published]
schedule:
# Daily at 6:43
- cron: "43 6 * * *"

env:
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_NO_PYTHON_VERSION_WARNING: "1"
workflow_dispatch:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: pre-commit/[email protected]

list:
runs-on: ubuntu-latest
outputs:
Expand All @@ -40,6 +30,7 @@ jobs:
ci:
needs: list
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
Expand All @@ -58,16 +49,19 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: |
3.8
3.9
3.10
3.11
3.12
3.13
pypy3.10
allow-prereleases: true

- name: Set up uv
uses: hynek/setup-cached-uv@v2
- name: Set up nox
uses: wntrblm/[email protected]

- name: Run nox
run: nox -s "${{ matrix.noxenv }}" -- ${{ matrix.posargs }}

Expand All @@ -77,6 +71,7 @@ jobs:
environment:
name: PyPI
url: https://pypi.org/p/jsonschema-specifications

permissions:
contents: write
id-token: write
Expand All @@ -87,10 +82,14 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Set up uv
uses: hynek/setup-cached-uv@v2
- name: Install dependencies
run: python -m pip install build
run: uv pip install --system build

- name: Create packages
run: python -m build .

- name: Publish to PyPI
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
44 changes: 28 additions & 16 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@
DOCS = ROOT / "docs"
PACKAGE = ROOT / "jsonschema_specifications"

REQUIREMENTS = dict(
docs=DOCS / "requirements.txt",
)
REQUIREMENTS_IN = [ # this is actually ordered, as files depend on each other
(path.parent / f"{path.stem}.in", path) for path in REQUIREMENTS.values()
]

SUPPORTED = ["3.9", "3.10", "pypy3.10", "3.11", "3.12", "3.13"]
LATEST = "3.12" # until 3.13 matures

nox.options.default_venv_backend = "uv|virtualenv"
nox.options.sessions = []


def session(default=True, **kwargs): # noqa: D103
def session(default=True, python=LATEST, **kwargs): # noqa: D103
def _session(fn):
if default:
nox.options.sessions.append(kwargs.get("name", fn.__name__))
return nox.session(**kwargs)(fn)
return nox.session(python=python, **kwargs)(fn)

return _session


@session(python=["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3"])
@session(python=SUPPORTED)
def tests(session):
"""
Run the test suite with a corresponding Python version.
Expand Down Expand Up @@ -58,7 +68,7 @@ def style(session):
Check Python code style.
"""
session.install("ruff")
session.run("ruff", "check", ROOT)
session.run("ruff", "check", ROOT, __file__)


@session()
Expand Down Expand Up @@ -88,7 +98,7 @@ def docs(session, builder):
"""
Build the documentation using a specific Sphinx builder.
"""
session.install("-r", DOCS / "requirements.txt")
session.install("-r", REQUIREMENTS["docs"])
with TemporaryDirectory() as tmpdir_str:
tmpdir = Path(tmpdir_str)
argv = ["-n", "-T", "-W"]
Expand Down Expand Up @@ -123,15 +133,17 @@ def docs_style(session):
@session(default=False)
def requirements(session):
"""
Update the project's pinned requirements. Commit the result.
Update the project's pinned requirements.
You should commit the result afterwards.
"""
session.install("pip-tools")
for each in [DOCS / "requirements.in"]:
session.run(
"pip-compile",
"--resolver",
"backtracking",
"--strip-extras",
"-U",
each.relative_to(ROOT),
)
if session.venv_backend == "uv":
cmd = ["uv", "pip", "compile"]
else:
session.install("pip-tools")
cmd = ["pip-compile", "--resolver", "backtracking", "--strip-extras"]

for each, out in REQUIREMENTS_IN:
# otherwise output files end up with silly absolute path comments...
relative = each.relative_to(ROOT)
session.run(*cmd, "--upgrade", "--output-file", out, relative)

0 comments on commit 19de742

Please sign in to comment.