Skip to content
Merged
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
Binary file modified .docs/images/format.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .docs/images/pre-commit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

113 changes: 113 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: CI Pipeline Template

'on':
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
lint-and-format:
name: Run Linters & Formatters
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.13

- name: Install dependencies
run: |
pip install poetry
poetry install --no-root --with dev

- name: Install pre-commit
run: pip install pre-commit
- name: Run linters and formatters
run: pre-commit run --all-files

tests:
name: Run Tests
runs-on: ubuntu-latest
needs: lint-and-format
timeout-minutes: 15
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: dev
POSTGRES_PASSWORD: dev
POSTGRES_DB: dev
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U dev -d dev"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
PROJECT_NAME: python-template
DATABASE_URL: postgresql://dev:dev@localhost:5432/dev
ASYNC_DATABASE_URL: postgresql+asyncpg://dev:dev@localhost:5432/dev
DATABASE_POOL_PRE_PING: True
DATABASE_POOL_SIZE: 5
DATABASE_POOL_RECYCLE: 3600
DATABASE_MAX_OVERFLOW: 10
LOG_LEVEL: DEBUG
SERVER_URL: example.com
ACCESS_TOKEN_EXPIRE_MINUTES: 15
JWT_SIGNING_KEY: your-signing-key
CELERY_BROKER_URL: amqp://guest:guest@rabbitmq:5672
CELERY_RESULT_BACKEND: redis://redis:6379/0
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.13

- name: Install dependencies
run: |
pip install poetry
poetry install --no-root --with dev

- name: Run tests with coverage
run: |
poetry run coverage run -m pytest
poetry run coverage report -m --fail-under=80

docker-build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: tests

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-

- name: Build image with cache
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: python-template:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ logs/*
.ptpython-history
.mypy_cache
.pytest_cache
.coverage
*.coverage

.devcontainer/commandhistory
!.devcontainer/commandhistory/.gitkeep
Expand Down
3 changes: 0 additions & 3 deletions .isort.cfg

This file was deleted.

32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# See https://pre-commit.com/hooks.html for more hooks
default_stages: [pre-commit, pre-push]
files: ^src/|^alembic/versions/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.5
hooks:
# Run the linter.
- id: ruff
args: [ --select=I, --fix ]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.8.0'
hooks:
- id: mypy
exclude: ^src/alembic/|^scripts/|^\\.devcontainer/|^\\.github/
additional_dependencies: [
pydantic==2.10.6,
SQLAlchemy==2.0.39,
types-mock==5.2.0.20250306
]
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# the repo. Unless a later match takes precedence,
# @pgrill, @m-revetria, @dcousin24 and @nicoache1 will be requested for
# review when someone opens a pull request.
* @pgrill @m-revetria @dcousin24 @nicoache1
* @pgrill @m-revetria @dcousin24 @nicoache1
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Alternatively, you must have:
- [Poetry](https://python-poetry.org/docs/#installation) (don't forget to install the dependencies from the lock file)
- [PostgreSQL](https://www.postgresql.org/) database, setting the corresponding environment variables for the database connection.

For making code changes, installing `pre-commit` is necessary (see section [Code tools: pre-commit](#pre-commit))

### Customization

The project's name (`python-template`) can be edited following next steps:
Expand All @@ -50,11 +52,25 @@ We use Alembic as database migration tool. You can run migration commands direct
## Code tools
Linters, formatters, etc.

- **Pycln**: Formatter for finding and removing unused import statements.
- **isort**: Tool to sort imports alphabetically and automatically separate into sections by type.
- **flake8**: Linting tool
- **ruff**: Linter and formatter
- **mypy**: Static type checker
- **black**: PEP 8 compliant opinionated formatter

### pre-commit
`pre-commit` is part of the `dev` group in the `pyproject.toml` and is installed by default.

Setup the `pre-commit` hooks, specified in `.pre-commit-config.yaml`:

pre-commit install

Ensure everything was set up correctly by running the hooks:

pre-commit run --all-files

![Screenshot](.docs/images/pre-commit.png)

#### Adding hooks

You can add new `pre-commit` hooks by editing `.pre-commit-config.yaml`. Whenever new hooks are added, you must run `pre-commit install` to ensure new hooks are run on commit.

There is a shortcut under the `/scripts` directory that runs all this tools for you (`./exec.sh format`) or just run `format` inside the dev container.

Expand Down
4 changes: 0 additions & 4 deletions mypy.ini

This file was deleted.

Loading