Skip to content

Commit 8d4ffda

Browse files
committed
chore(formatting): add black as the standard Python code formatter
1 parent 92c93db commit 8d4ffda

File tree

15 files changed

+199
-114
lines changed

15 files changed

+199
-114
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 25.1.0
4+
hooks:
5+
- id: black
6+
language_version: python3.13.3

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"**/.DS_Store": true
99
},
1010
"[python]": {
11-
"editor.defaultFormatter": "ms-python.autopep8",
11+
"editor.defaultFormatter": "ms-python.black-formatter",
1212
"editor.formatOnSave": true
1313
},
1414
"sonarlint.connectedMode.project": {

CONTRIBUTING.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@ We enforce quality via CI on every push and PR:
4444

4545
Failures must be fixed before review.
4646

47-
## 6. Code of Conduct & Support
47+
## 6. Formatting
48+
49+
We use [Black](https://black.readthedocs.io/) as the standard Python formatter in this project:
50+
51+
- All Python code must be formatted with Black before committing or pushing
52+
- You can install the pre-commit hook to automatically format your code before each commit
53+
54+
## 7. Code of Conduct & Support
4855

4956
- Please see `CODE_OF_CONDUCT.md` for behavioral expectations and reporting.
5057
- For quick questions or discussions, open an issue with the `discussion` label or mention a maintainer.
5158

5259
Thanks again for helping keep this project small, simple, and impactful!
60+

databases/player_database.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
The `STORAGE_PATH` environment variable controls the SQLite file location.
1010
"""
11+
1112
import logging
1213
import os
1314
from typing import AsyncGenerator
@@ -21,16 +22,11 @@
2122
logging.getLogger("sqlalchemy.engine.Engine").handlers = logger.handlers
2223

2324
async_engine = create_async_engine(
24-
DATABASE_URL,
25-
connect_args={"check_same_thread": False},
26-
echo=True
25+
DATABASE_URL, connect_args={"check_same_thread": False}, echo=True
2726
)
2827

2928
async_sessionmaker = sessionmaker(
30-
bind=async_engine,
31-
class_=AsyncSession,
32-
autocommit=False,
33-
autoflush=False
29+
bind=async_engine, class_=AsyncSession, autocommit=False, autoflush=False
3430
)
3531

3632
Base = declarative_base()

main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
This serves as the entry point for running the API server.
99
"""
10+
1011
from contextlib import asynccontextmanager
1112
import logging
1213
from typing import AsyncIterator
@@ -17,6 +18,7 @@
1718
UVICORN_LOGGER = "uvicorn.error"
1819
logger = logging.getLogger(UVICORN_LOGGER)
1920

21+
2022
@asynccontextmanager
2123
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
2224
"""
@@ -25,10 +27,13 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
2527
logger.info("Lifespan event handler execution complete.")
2628
yield
2729

28-
app = FastAPI(lifespan=lifespan,
29-
title="python-samples-fastapi-restful",
30-
description="🧪 Proof of Concept for a RESTful API made with Python 3 and FastAPI",
31-
version="1.0.0",)
30+
31+
app = FastAPI(
32+
lifespan=lifespan,
33+
title="python-samples-fastapi-restful",
34+
description="🧪 Proof of Concept for a RESTful API made with Python 3 and FastAPI",
35+
version="1.0.0",
36+
)
3237

3338
app.include_router(player_route.api_router)
3439
app.include_router(health_route.api_router)

models/player_model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
These models are used for data validation and serialization in the API.
88
"""
9+
910
from typing import Optional
1011
from pydantic import BaseModel, ConfigDict
1112
from pydantic.alias_generators import to_camel
@@ -24,6 +25,7 @@ class MainModel(BaseModel):
2425
Here, it uses `to_camel` to convert field names to camelCase.
2526
populate_by_name (bool): Allows population of fields by name when using Pydantic models.
2627
"""
28+
2729
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
2830

2931

@@ -44,6 +46,7 @@ class PlayerModel(MainModel):
4446
league (Optional[str]): The league where the team plays, if any.
4547
starting11 (Optional[bool]): Indicates if the Player is in the starting 11, if provided.
4648
"""
49+
4750
id: int
4851
first_name: str
4952
middle_name: Optional[str]

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.black]
2+
line-length = 88
3+
target-version = ['py312']

requirements-lint.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
flake8==7.2.0
2+
black==25.1.0

requirements-pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pre-commit==4.2.0

routes/health_route.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
Defines a simple endpoint to verify that the service is up and running.
55
Returns a JSON response with a "status" key set to "ok".
66
"""
7+
78
from fastapi import APIRouter
89

910
api_router = APIRouter()
1011

12+
1113
@api_router.get("/health", tags=["Health"])
1214
async def health_check():
1315
"""

0 commit comments

Comments
 (0)