Skip to content

Commit

Permalink
Use uv in CI and update for PEP 639.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Jan 16, 2025
1 parent 9079dc9 commit b28b61c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 60 deletions.
45 changes: 23 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,32 @@ on:
tags:
- "v*"
pull_request:
release:
types: [published]
schedule:
# Daily at 7:37
- cron: "37 7 * * *"
workflow_dispatch:

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

jobs:
list:
runs-on: ubuntu-latest
outputs:
noxenvs: ${{ steps.noxenvs-matrix.outputs.noxenvs }}
steps:
- uses: actions/checkout@v4
- name: Set up nox
uses: wntrblm/[email protected]
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- id: noxenvs-matrix
run: |
echo >>$GITHUB_OUTPUT noxenvs=$(
nox --list-sessions --json | jq '[.[].session]'
uvx nox --list-sessions --json | jq '[.[].session]'
)
ci:
needs: list
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
Expand All @@ -44,7 +41,7 @@ jobs:
posargs: [""]
include:
- os: ubuntu-latest
noxenv: "tests-3.11"
noxenv: tests-3.13
posargs: coverage github

steps:
Expand All @@ -59,39 +56,43 @@ 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 nox
uses: wntrblm/[email protected]

- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true

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

packaging:
needs: ci
runs-on: ubuntu-latest
environment:
name: PyPI
url: https://pypi.org/p/jsonschema-lexer

permissions:
contents: write
id-token: write

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
cache: pip
python-version: "3.x"
- name: Install dependencies
run: python -m pip install build
- name: Create packages
run: python -m build .
enable-cache: true

- name: Build our distributions
run: uv run --frozen --with 'build[uv]' -m build --installer=uv

- 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
56 changes: 32 additions & 24 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
REQUIREMENTS = dict(
tests=ROOT / "test-requirements.txt",
)
REQUIREMENTS_IN = {
path.parent / f"{path.stem}.in" for path in REQUIREMENTS.values()
}
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 = ["pypy3.10", "3.10", "3.11", "3.12"]
SUPPORTED = ["pypy3.10", "3.10", "3.11", "3.12", "3.13"]
LATEST = SUPPORTED[-1]

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


Expand All @@ -35,7 +35,7 @@ def _session(fn):
@session(python=SUPPORTED)
def tests(session):
"""
Run the test suite.
Run the test suite with a corresponding Python version.
"""
session.install("-r", REQUIREMENTS["tests"])

Expand All @@ -60,7 +60,7 @@ def tests(session):
stdout=summary,
)
else:
session.run("python", "-m", "pytest", *session.posargs, PACKAGE)
session.run("pytest", *session.posargs, PACKAGE)


@session(python=SUPPORTED)
Expand All @@ -77,9 +77,15 @@ def build(session):
"""
Build a distribution suitable for PyPI and check its validity.
"""
session.install("build", "twine")
session.install("build[uv]", "twine")
with TemporaryDirectory() as tmpdir:
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
session.run(
"pyproject-build",
"--installer=uv",
ROOT,
"--outdir",
tmpdir,
)
session.run("twine", "check", "--strict", tmpdir + "/*")


Expand All @@ -95,33 +101,35 @@ def secrets(session):
@session(tags=["style"])
def style(session):
"""
Check for coding style.
Check Python code style.
"""
session.install("ruff")
session.run("ruff", "check", ROOT)
session.run("ruff", "check", ROOT, __file__)


@session()
def typing(session):
"""
Statically check typing annotations.
Check static typing.
"""
session.install("pyright", ROOT)
session.run("pyright", PACKAGE)
session.run("pyright", *session.posargs, PACKAGE)


@session(default=False)
def requirements(session):
"""
Update requirements files.
Update the project's pinned requirements.
You should commit the result afterwards.
"""
session.install("pip-tools")
for each in 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)
23 changes: 9 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ name = "jsonschema-lexer"
description = "A Pygments lexer for JSON Schema"
requires-python = ">=3.10"
readme = "README.rst"
license = "MIT"
license-files = ["COPYING"]
keywords = ["json", "jsonschema"]
authors = [
{ name = "Julian Berman", email = "[email protected]" },
]
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: File Formats :: JSON",
Expand Down Expand Up @@ -56,24 +58,16 @@ skip_covered = true

[tool.doc8]
ignore = [
"D000", # see PyCQA/doc8#125
"D001", # one sentence per line, so max length doesn't make sense
"D000", # see PyCQA/doc8#125
"D001", # one sentence per line, so max length doesn't make sense
]

[tool.isort]
combine_as_imports = true
ensure_newline_before_comments = true
from_first = true
include_trailing_comma = true
multi_line_output = 3
use_parentheses = true

[tool.pyright]
reportUnnecessaryTypeIgnoreComment = true
strict = ["**/*.py"]
exclude = [
"**/tests/__init__.py",
"**/tests/test_*.py",
"**/tests/__init__.py",
"**/tests/test_*.py",
]

[tool.ruff]
Expand All @@ -85,6 +79,7 @@ ignore = [
"A001", # It's fine to shadow builtins
"A002",
"A003",
"A005",
"ARG", # This is all wrong whenever an interface is involved
"ANN", # Just let the type checker do this
"B006", # Mutable arguments require care but are OK if you don't abuse them
Expand Down
21 changes: 21 additions & 0 deletions uv.lock

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

0 comments on commit b28b61c

Please sign in to comment.