Enable ruff, black, and pytest in pre-commit
This commit is contained in:
parent
7e54b9dc65
commit
c36c4bd3b8
9
.github/workflows/lint-and-test.yaml
vendored
9
.github/workflows/lint-and-test.yaml
vendored
@ -1,5 +1,8 @@
|
|||||||
name: 'Lint and Test'
|
# Shouldn't really be needed, what with the pre-commit setup (see `DEVELOPMENT.md`) -
|
||||||
on: push
|
# but, doesn't hurt!
|
||||||
|
name: 'Lint And Test'
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint_and_test:
|
lint_and_test:
|
||||||
@ -12,5 +15,7 @@ jobs:
|
|||||||
python-version: '3.x'
|
python-version: '3.x'
|
||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
- run: 'python3 -m pip install -r requirements.txt'
|
- run: 'python3 -m pip install -r requirements.txt'
|
||||||
|
- run: 'python3 -m pip install -r requirements-dev.txt'
|
||||||
- run: 'ruff check .'
|
- run: 'ruff check .'
|
||||||
|
- run: 'black --check .'
|
||||||
- run: 'pytest .'
|
- run: 'pytest .'
|
||||||
|
@ -4,3 +4,9 @@ In increasing complexity:
|
|||||||
|
|
||||||
* `./basic-run.sh` - just raw-dog it
|
* `./basic-run.sh` - just raw-dog it
|
||||||
* `docker compose up --build`
|
* `docker compose up --build`
|
||||||
|
|
||||||
|
# Pre-commit
|
||||||
|
|
||||||
|
This repo uses [pre-commit](https://pre-commit.com/). Install the tool with `pip install pre-commit` (or just `pip install -r requirements-dev.txt`), then install the hooks with `pre-commit install`
|
||||||
|
|
||||||
|
Not yet configured to run this in CI, as I'm the only contributor :P but I definitely should if I start getting contributions!
|
||||||
|
@ -10,15 +10,15 @@ from .players import list_players
|
|||||||
|
|
||||||
api_router = APIRouter(prefix="/deck", tags=["deck"])
|
api_router = APIRouter(prefix="/deck", tags=["deck"])
|
||||||
html_router = APIRouter(
|
html_router = APIRouter(
|
||||||
prefix="/deck",
|
prefix="/deck", include_in_schema=False, default_response_class=HTMLResponse
|
||||||
include_in_schema=False,
|
)
|
||||||
default_response_class=HTMLResponse)
|
|
||||||
|
|
||||||
|
|
||||||
########
|
########
|
||||||
# API Routes
|
# API Routes
|
||||||
########
|
########
|
||||||
|
|
||||||
|
|
||||||
@api_router.post("/", response_model=schemas.Deck, status_code=201)
|
@api_router.post("/", response_model=schemas.Deck, status_code=201)
|
||||||
def create_deck(deck: schemas.DeckCreate, db: Session = Depends(get_db)):
|
def create_deck(deck: schemas.DeckCreate, db: Session = Depends(get_db)):
|
||||||
db_player = crud.get_player_by_id(db, deck.owner_id)
|
db_player = crud.get_player_by_id(db, deck.owner_id)
|
||||||
@ -53,6 +53,7 @@ def delete_deck(deck_id: str, db=Depends(get_db)):
|
|||||||
# HTML Routes
|
# HTML Routes
|
||||||
########
|
########
|
||||||
|
|
||||||
|
|
||||||
@html_router.get("/create")
|
@html_router.get("/create")
|
||||||
def deck_create_html(request: Request, db=Depends(get_db)):
|
def deck_create_html(request: Request, db=Depends(get_db)):
|
||||||
players = list_players(db=db)
|
players = list_players(db=db)
|
||||||
|
@ -11,14 +11,14 @@ from ..sql.database import get_db
|
|||||||
|
|
||||||
api_router = APIRouter(prefix="/game", tags=["game"])
|
api_router = APIRouter(prefix="/game", tags=["game"])
|
||||||
html_router = APIRouter(
|
html_router = APIRouter(
|
||||||
prefix="/game",
|
prefix="/game", include_in_schema=False, default_response_class=HTMLResponse
|
||||||
include_in_schema=False,
|
)
|
||||||
default_response_class=HTMLResponse)
|
|
||||||
|
|
||||||
########
|
########
|
||||||
# API Routes
|
# API Routes
|
||||||
########
|
########
|
||||||
|
|
||||||
|
|
||||||
@api_router.post("/", response_model=schemas.Game, status_code=201)
|
@api_router.post("/", response_model=schemas.Game, status_code=201)
|
||||||
def create_game(game: schemas.GameCreate, db: Session = Depends(get_db)):
|
def create_game(game: schemas.GameCreate, db: Session = Depends(get_db)):
|
||||||
return crud.create_game(db=db, game=game)
|
return crud.create_game(db=db, game=game)
|
||||||
@ -46,23 +46,29 @@ def delete_game(game_id: str, db=Depends(get_db)):
|
|||||||
# HTML Routes
|
# HTML Routes
|
||||||
########
|
########
|
||||||
|
|
||||||
|
|
||||||
@html_router.get("/create", response_class=HTMLResponse)
|
@html_router.get("/create", response_class=HTMLResponse)
|
||||||
def game_create_html(request: Request, db=Depends(get_db)):
|
def game_create_html(request: Request, db=Depends(get_db)):
|
||||||
players = list_players(db=db)
|
players = list_players(db=db)
|
||||||
return jinja_templates.TemplateResponse(
|
return jinja_templates.TemplateResponse(
|
||||||
request, "games/create.html", {
|
request,
|
||||||
|
"games/create.html",
|
||||||
|
{
|
||||||
"players": players,
|
"players": players,
|
||||||
# `json.dumps` is necessary because otherwise
|
# `json.dumps` is necessary because otherwise
|
||||||
# the keys are surrounded with single-quotes,
|
# the keys are surrounded with single-quotes,
|
||||||
# on which JavaScript's `JSON.parse` will choke.
|
# on which JavaScript's `JSON.parse` will choke.
|
||||||
"player_decks": json.dumps({
|
"player_decks": json.dumps(
|
||||||
str(player.id): [{
|
{
|
||||||
key: getattr(deck, key)
|
str(player.id): [
|
||||||
for key in ['id', 'name']
|
{key: getattr(deck, key) for key in ["id", "name"]}
|
||||||
} for deck in player.decks]
|
for deck in player.decks
|
||||||
for player in players
|
]
|
||||||
})
|
for player in players
|
||||||
})
|
}
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO - pagination
|
# TODO - pagination
|
||||||
@ -80,4 +86,4 @@ def game_html(request: Request, game_id: str, db=Depends(get_db)):
|
|||||||
game_info = read_game(game_id, db)
|
game_info = read_game(game_id, db)
|
||||||
return jinja_templates.TemplateResponse(
|
return jinja_templates.TemplateResponse(
|
||||||
request, "games/detail.html", {"game": game_info}
|
request, "games/detail.html", {"game": game_info}
|
||||||
)
|
)
|
||||||
|
@ -8,9 +8,8 @@ from ..sql.database import get_db
|
|||||||
|
|
||||||
api_router = APIRouter(prefix="/player", tags=["player"])
|
api_router = APIRouter(prefix="/player", tags=["player"])
|
||||||
html_router = APIRouter(
|
html_router = APIRouter(
|
||||||
prefix="/player",
|
prefix="/player", include_in_schema=False, default_response_class=HTMLResponse
|
||||||
include_in_schema=False,
|
)
|
||||||
default_response_class=HTMLResponse)
|
|
||||||
|
|
||||||
########
|
########
|
||||||
# API Routes
|
# API Routes
|
||||||
@ -44,15 +43,18 @@ def delete_player(player_id: str, db=Depends(get_db)):
|
|||||||
# HTML Routes
|
# HTML Routes
|
||||||
########
|
########
|
||||||
|
|
||||||
|
|
||||||
@html_router.get("/create")
|
@html_router.get("/create")
|
||||||
def player_create_html(request: Request, db=Depends(get_db)):
|
def player_create_html(request: Request, db=Depends(get_db)):
|
||||||
return jinja_templates.TemplateResponse(request, "players/create.html")
|
return jinja_templates.TemplateResponse(request, "players/create.html")
|
||||||
|
|
||||||
|
|
||||||
@html_router.get("/list", response_class=HTMLResponse)
|
@html_router.get("/list", response_class=HTMLResponse)
|
||||||
def player_list_html(request: Request, db=Depends(get_db)):
|
def player_list_html(request: Request, db=Depends(get_db)):
|
||||||
players = list_players(db=db)
|
players = list_players(db=db)
|
||||||
return jinja_templates.TemplateResponse(
|
return jinja_templates.TemplateResponse(
|
||||||
request, "players/list.html", {"players": players})
|
request, "players/list.html", {"players": players}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# This must be after the static-path routes, lest it take priority over them
|
# This must be after the static-path routes, lest it take priority over them
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from . import models
|
from . import models
|
||||||
from .database import SessionLocal
|
from .database import SessionLocal
|
||||||
|
|
||||||
|
|
||||||
def prime_database():
|
def prime_database():
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
win_types = db.query(models.WinType).all()
|
win_types = db.query(models.WinType).all()
|
||||||
|
@ -25,7 +25,7 @@ class Deck(Base):
|
|||||||
|
|
||||||
|
|
||||||
class WinType(Base):
|
class WinType(Base):
|
||||||
__tablename__ = 'wintypes'
|
__tablename__ = "wintypes"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
name = Column(String, nullable=False)
|
name = Column(String, nullable=False)
|
||||||
|
10
requirements-dev.txt
Normal file
10
requirements-dev.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Meta tool for running pre-commits
|
||||||
|
pre-commit
|
||||||
|
|
||||||
|
# Linting
|
||||||
|
ruff
|
||||||
|
black
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
httpx
|
||||||
|
pytest
|
@ -2,10 +2,3 @@ fastapi
|
|||||||
uvicorn
|
uvicorn
|
||||||
sqlalchemy
|
sqlalchemy
|
||||||
Jinja2
|
Jinja2
|
||||||
|
|
||||||
# Linting
|
|
||||||
ruff
|
|
||||||
|
|
||||||
# Testing
|
|
||||||
httpx
|
|
||||||
pytest
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user