Skip to content

Commit

Permalink
Merge pull request #6 from max-pfeiffer/feature/github_workflow
Browse files Browse the repository at this point in the history
Feature/GitHub workflow
  • Loading branch information
max-pfeiffer authored Jan 6, 2024
2 parents 02dbc3a + 59443bc commit b28eb07
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 100 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ repos:
- id: detect-private-key
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 23.11.0
rev: 23.12.1
hooks:
- id: black
language_version: python3.9
language_version: python3.11
args:
- "--config"
- "./pyproject.toml"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![codecov](https://codecov.io/gh/max-pfeiffer/uvicorn-poetry-project-template/branch/main/graph/badge.svg?token=WQI2SJJLZN)](https://codecov.io/gh/max-pfeiffer/uvicorn-poetry-project-template)
[![codecov](https://codecov.io/gh/max-pfeiffer/uvicorn-poetry-fastapi-project-template/graph/badge.svg?token=OFQU8YVFAR)](https://codecov.io/gh/max-pfeiffer/uvicorn-poetry-fastapi-project-template)
![pipeline workflow](https://github.com/max-pfeiffer/uvicorn-poetry-project-template/actions/workflows/pipeline.yml/badge.svg)
# uvicorn-poetry-project-template
[Cookiecutter](https://github.com/cookiecutter/cookiecutter) project template for starting a containerized Fast API project.
Expand Down
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"author_email": "",
"python_version": ["3.12.0", "3.11.6", "3.10.13"],
"operating_system_variant": ["slim-bookworm", "bookworm"],
"github_workflow": [true, false],
"_extensions": ["cookiecutter.extensions.SlugifyExtension"]
}
11 changes: 11 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pathlib import Path
from shutil import rmtree

REMOVE_PATHS: list[str] = [
"{% if not cookiecutter.github_workflow %}.github{% endif %}",
]

for path in REMOVE_PATHS:
if path and Path(path.strip()).exists():
path_object: Path = Path(path.strip())
path_object.unlink() if path_object.is_file() else rmtree(path_object)
172 changes: 86 additions & 86 deletions poetry.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[tool.poetry]
name = "fast-api-micro-service-template"
version = "1.1.0"
version = "1.3.0"
description = "A Cookiecutter template for spinning up a micro service"
authors = ["Max Pfeiffer <[email protected]>"]

[tool.poetry.dependencies]
python = "3.11.*"

[tool.poetry.dev-dependencies]
black = "23.12.0"
black = "23.12.1"
cookiecutter = "2.5.0"
coverage = "7.3.3"
coverage = "7.4.0"
docker = "7.0.0"
furl = "2.1.3"
httpx = "0.25.2"
pytest = "7.4.3"
httpx = "0.26.0"
pytest = "7.4.4"
pre-commit = "3.6.0"
pytest-cookies = "0.7.0"
pytest-cov = "4.1.0"
Expand Down
7 changes: 7 additions & 0 deletions tests/test_custom_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_custom_config(cookies) -> None:
"author_email": "[email protected]",
"python_version": "3.10.13",
"operating_system_variant": "bookworm",
"github_workflow": False,
}
)

Expand All @@ -46,3 +47,9 @@ def test_custom_config(cookies) -> None:

assert dfp.is_multistage
assert all(["3.10.13-bookworm" in image for image in dfp.parent_images])

# Check for GitHub workflow
workflow: Path = (
result.project_path / ".github" / "workflows" / "pipeline.yml"
)
assert not workflow.exists()
6 changes: 6 additions & 0 deletions tests/test_default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ def test_default_config(cookies) -> None:

assert dfp.is_multistage
assert all(["3.12.0-slim-bookworm" in image for image in dfp.parent_images])

# Check for GitHub workflow
workflow: Path = (
result.project_path / ".github" / "workflows" / "pipeline.yml"
)
assert workflow.exists()
63 changes: 63 additions & 0 deletions {{cookiecutter.project_slug}}/.github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Pipeline

on: push

jobs:
code-quality:
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: {{ cookiecutter.python_version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.7.1
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-{{ "${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}" }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
- name: Run pylint and black
run: |
source .venv/bin/activate
black --check .
run-tests:
needs: code-quality
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: {{ cookiecutter.python_version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.7.1
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-{{ "${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}" }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
- name: Run tests
run: |
source .venv/bin/activate
pytest
4 changes: 1 addition & 3 deletions {{cookiecutter.project_slug}}/app/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from typing import Dict

from fastapi import FastAPI

app = FastAPI()

HELLO_WORLD: str = "Hello World!"
ITEMS: Dict[str, str] = {"1": "sausage", "2": "ham", "3": "tofu"}
ITEMS: dict[str, str] = {"1": "sausage", "2": "ham", "3": "tofu"}


@app.get("/")
Expand Down
6 changes: 3 additions & 3 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ uvicorn = {version = "0.24.0.post1", extras = ["standard"]}
fastapi = "0.104.1"

[tool.poetry.dev-dependencies]
black = "23.11.0"
coverage = "7.3.3"
black = "23.12.1"
coverage = "7.4.0"
httpx = "0.26.0"
pre-commit = "3.6.0"
pytest = "7.4.3"
pytest = "7.4.4"
pytest-cov = "4.1.0"
requests = "2.28.1"

Expand Down

0 comments on commit b28eb07

Please sign in to comment.