Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
command: make install
- run:
name: Pre-commit checks
command: SKIP=ruff-format uv run pre-commit run --all-files --show-diff-on-failure
command: SKIP=ruff-format,ruff-check,ty-check,generate-openapi uv run pre-commit run --all-files --show-diff-on-failure
- run:
name: Format Check
command: make format-check
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Code Quality

on:
pull_request:
paths:
- "**.py"
- "**.toml"
- "Makefile"
- "uv.lock"
- ".github/workflows/code-quality.yml"
push:
branches-ignore:
- master
Comment thread
Naramsim marked this conversation as resolved.
- staging
paths:
- "**.py"
- "**.toml"
- "Makefile"
- "uv.lock"
- ".github/workflows/code-quality.yml"

jobs:
ruff:
name: Ruff (lint)
runs-on: ubuntu-latest
# TODO: remove once the codebase is fully lint-clean
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup uv
uses: ./.github/actions/setup-uv
- name: Install dependencies
run: make install
- name: Lint
run: make lint-check || true
- name: Summary
if: always()
run: |
{
echo "## Ruff lint results"
echo
echo "<details><summary>Expand to see all errors (backlog while the codebase is being linted incrementally)</summary>"
echo
echo '```'
uv run ruff check --output-format=concise . || true
echo '```'
echo
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"

ty:
name: ty (type-check)
runs-on: ubuntu-latest
# TODO: remove once the codebase is fully typed
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup uv
uses: ./.github/actions/setup-uv
- name: Install dependencies
run: make install
- name: Type-check
run: make typecheck || true
- name: Summary
if: always()
run: |
{
echo "## ty type-check results"
echo
echo "<details><summary>Expand to see all errors (backlog while the codebase is being typed incrementally)</summary>"
echo
echo '```'
uv run ty check --output-format=concise || true
echo '```'
echo
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"
4 changes: 4 additions & 0 deletions .github/workflows/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Database

on:
pull_request:
push:
branches-ignore:
Comment thread
Naramsim marked this conversation as resolved.
- master
- staging

jobs:
csv:
Expand Down
29 changes: 21 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ repos:
args:
- --markdown-linebreak-ext=md

# TODO: Enable in the future when adding the ruff linter
# - repo: https://github.com/pre-commit/pygrep-hooks
# rev: v1.9.0
# hooks:
# - id: python-check-blanket-noqa
# - id: python-check-blanket-type-ignore
# - id: python-use-type-annotations

- repo: local
hooks:
- id: check-csv
Expand All @@ -37,13 +29,34 @@ repos:
args: [--encoding, utf-8]
files: \.csv$

- id: ruff-check
name: Ruff Check
entry: uv run ruff check .
language: system
types_or: [python, pyi]
pass_filenames: false

- id: ruff-format
name: Ruff Format
entry: uv run ruff format .
language: system
types_or: [python, pyi]
pass_filenames: false

- id: ty-check
name: Ty Check
entry: uv run ty check
language: system
types_or: [python, pyi]
pass_filenames: false

- id: generate-openapi
name: Generate OpenAPI Schema
entry: uv run manage.py spectacular --file openapi.yml --settings=config.docker_compose
language: system
files: ^(pokemon_v2/|config/|openapi\.yml)
pass_filenames: false

- id: build-and-test
name: Build and Test
entry: >-
Expand Down
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ git checkout -b my_new_branch
```
- Write some code, fix something, and add a test to prove that it works. **No pull request will be accepted without tests passing, or without new tests if new features are added.**

- Make sure your code passes the pre-commit hooks, if you have the hooks installed it should run automatically on commit. You can run them manually with:
- Make sure your code changes passes the pre-commit hooks, linting, formatting, and typechecking. You can run them manually with:
```bash
make pre-commit
# or
uv run pre-commit run --all-files
make pre-commit # or: uv run pre-commit run --all-files
make lint-check # or: uv run ruff check .
make format # or: uv run ruff format .
make typecheck # or: uv run ty check
```

> [!NOTE]
> As of right now we are not strictly enforcing linting and typechecking, but we will be in the future. Please try to make sure your code passes these checks.

- Commit your code and push it to GitHub

- [Open a new pull request](https://help.github.com/articles/creating-a-pull-request/) and describe the changes you have made.
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
veekun_pokedex_repository = ../pokedex
local_config = --settings=config.local
docker_config = --settings=config.docker-compose
docker_config = --settings=config.docker_compose
gql_compose_config_deprecated = -f docker-compose.yml -f docker-compose-dev.yml -f Resources/compose/docker-compose-prod-graphql.yml
gql_compose_config = -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml

Expand Down Expand Up @@ -101,6 +101,15 @@ format: check-uv # Format the source code
format-check: check-uv # Check the source code has been formatted
uv run ruff format . --check

lint-check: check-uv # Lint the source code
uv run ruff check .

lint-fix: check-uv # Lint the source code and fix issues
uv run ruff check . --fix

typecheck: check-uv # Type-check the source code with ty
uv run ty check

pull:
git checkout master
git pull
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ A RESTful API for Pokémon - [pokeapi.co](https://pokeapi.co)
> [!NOTE]
> Pre-commit hooks are optional but recommended for maintaining code quality and consistency. If you do not want it to automatically run on every commit, you can run it manually with `make pre-commit` before commiting and pushing your changes.

- Lint, format, and typecheck your code changes:

```sh
make lint-check # or: uv run ruff check .
make format # or: uv run ruff format .
make typecheck # or: uv run ty check
```

> [!NOTE]
> As of right now we are not strictly enforcing linting and typechecking, but we will be in the future. Please try to make sure your code passes these checks.

- Set up the local development environment using the following command:

```sh
Expand Down Expand Up @@ -107,8 +118,8 @@ If you don't have `make` on your machine you can use the following commands

```sh
docker compose up -d
docker compose exec -T app python manage.py migrate --settings=config.docker-compose
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'
docker compose exec -T app python manage.py migrate --settings=config.docker_compose
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker_compose'
```

Browse [localhost/api/v2/](http://localhost/api/v2/) or [localhost/api/v2/pokemon/bulbasaur/](http://localhost/api/v2/pokemon/bulbasaur/) on port `80`.
Expand Down Expand Up @@ -159,8 +170,8 @@ Configure `kubectl` to point to a cluster and then run the following commands to
kubectl apply -k Resources/k8s/kustomize/base/
kubectl config set-context --current --namespace pokeapi # (Optional) Set pokeapi ns as the working ns
# Wait for the cluster to spin up
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker-compose # Migrate the DB
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose' # Build the db
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker_compose # Migrate the DB
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker_compose' # Build the db
kubectl wait --namespace pokeapi --timeout=120s --for=condition=complete job/load-graphql # Wait for Graphql configuration job to finish
```

Expand Down
2 changes: 1 addition & 1 deletion Resources/docker/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ FROM python:3.14-alpine
RUN apk add --no-cache git

ENV PYTHONUNBUFFERED=1
ENV DJANGO_SETTINGS_MODULE='config.docker-compose'
ENV DJANGO_SETTINGS_MODULE='config.docker_compose'
ENV PATH="/code/.venv/bin:$PATH"

WORKDIR /code
Expand Down
4 changes: 2 additions & 2 deletions Resources/docker/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ Pokémon data isn't automatically present in this image. All Pokémon data is pe
When the container is up and running, run the following shell commands:

```sh
docker exec pokeapi python manage.py migrate --settings=config.docker-compose
docker exec pokeapi sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'
docker exec pokeapi python manage.py migrate --settings=config.docker_compose
docker exec pokeapi sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker_compose'
```
Empty file modified config/__init__.py
100755 → 100644
Comment thread
Naramsim marked this conversation as resolved.
Empty file.
16 changes: 16 additions & 0 deletions config/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for PokeAPI.
Comment thread
Naramsim marked this conversation as resolved.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

application = get_asgi_application()
12 changes: 9 additions & 3 deletions config/docker.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Docker settings
from .settings import *
# ruff: noqa: F405
# pyright: reportConstantRedefinition=false
from .settings import * # noqa: F403

DATABASES = {
DATABASES: dict[str, DatabaseSettings] = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "pokeapi",
Expand All @@ -13,7 +15,7 @@
}


CACHES = {
CACHES: dict[str, CacheSettings] = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
Expand All @@ -24,3 +26,7 @@
}

DEBUG = True

for template in TEMPLATES:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? Where is TEMPLATE defined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEMPLATE is defined in settings.py which is our base settings and we have custom config files which override based on runner/env

https://github.com/FallenDeity/pokeapi/blob/c5cc15b6fc9c29391e111a6f15a94c17f692406e/config/settings.py#L157

the previous TEMPLATE_DEBUG was now moved from django settings and now we need to define it in options so this sets that for cases where TEMPLATE_DEBUG was being set previously

https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/

if "OPTIONS" in template and "debug" in template["OPTIONS"]:
template["OPTIONS"]["debug"] = DEBUG
11 changes: 7 additions & 4 deletions config/docker-compose.py → config/docker_compose.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Docker settings
# ruff: noqa: F405
# pyright: reportConstantRedefinition=false
import os
from .settings import *

DATABASES = {
from .settings import * # noqa: F403

DATABASES: dict[str, DatabaseSettings] = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("POSTGRES_DB", "pokeapi"),
"USER": os.environ.get("POSTGRES_USER", "ash"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD", "pokemon"),
"HOST": os.environ.get("POSTGRES_HOST", "db"),
"PORT": os.environ.get("POSTGRES_PORT", 5432),
"PORT": os.environ.get("POSTGRES_PORT", "5432"),
}
}

CACHES = {
CACHES: dict[str, CacheSettings] = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": os.environ.get("REDIS_CONNECTION_STRING", "redis://cache:6379/1"),
Expand Down
12 changes: 9 additions & 3 deletions config/local.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from .settings import *
# pyright: reportConstantRedefinition=false
# ruff: noqa: F405
from .settings import * # noqa: F403

DATABASES = {
DATABASES: dict[str, DatabaseSettings] = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}

CACHES = {
CACHES: dict[str, CacheSettings] = {
"default": {
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
}
}

DEBUG = True

for template in TEMPLATES:
if "OPTIONS" in template and "debug" in template["OPTIONS"]:
template["OPTIONS"]["debug"] = DEBUG
Loading
Loading