Skip to content

Commit

Permalink
Add nox and github action for code formatting & type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
novanai committed Jan 14, 2025
1 parent 573e3e6 commit 95e1cb1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Format & Type Check

on: [push, pull_request]

jobs:
formatting:
runs-on: ubuntu-latest
name: "Check code style"
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Run ruff via nox
run: |
python -m pip install nox
python -m nox -s format
pyright:
runs-on: ubuntu-latest
name: "Type checking"
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Run pyright via nox
run: |
python -m pip install nox
python -m nox -s pyright
29 changes: 29 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os

import nox
from nox import options

PROJECT_PATH = os.path.join(".", "src")
SCRIPT_PATHS = [PROJECT_PATH, "noxfile.py"]

options.sessions = ["format_fix", "pyright"]


@nox.session()
def format_fix(session: nox.Session) -> None:
session.install("-r", "requirements_dev.txt")
session.run("python", "-m", "ruff", "format", *SCRIPT_PATHS)
session.run("python", "-m", "ruff", "check", *SCRIPT_PATHS, "--fix")


@nox.session()
def format_check(session: nox.Session) -> None:
session.install("-r", "requirements_dev.txt")
session.run("python", "-m", "ruff", "format", *SCRIPT_PATHS, "--check")
session.run("python", "-m", "ruff", "check", *SCRIPT_PATHS)


@nox.session()
def pyright(session: nox.Session) -> None:
session.install("-r", "requirements_dev.txt", "-r", "requirements.txt")
session.run("pyright", *SCRIPT_PATHS)
5 changes: 4 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
ruff==0.7.3
nox==2024.10.9
ruff==0.9.1
pre-commit==4.0.1
pyright==1.1.391

2 changes: 1 addition & 1 deletion src/extensions/fortune.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@arc.slash_command("fortune", "Send a user a random Fortune!")
async def fortune_command(
ctx: arc.GatewayContext,
user: arc.Option[hikari.User, arc.UserParams("A user")] = None,
user: arc.Option[hikari.User | None, arc.UserParams("A user")] = None,
) -> None:
"""Send a random Fortune!"""

Expand Down

0 comments on commit 95e1cb1

Please sign in to comment.