Skip to content

Commit 045ab74

Browse files
authored
#1 - init repo (#2)
1 parent e2a0d71 commit 045ab74

File tree

21 files changed

+980
-2
lines changed

21 files changed

+980
-2
lines changed

.docker/python/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.13.3
2+
ARG PACKAGE="core"
3+
4+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
5+
6+
WORKDIR /app
7+
8+
COPY ../../shared/utils /app/shared/utils
9+
10+
RUN --mount=type=bind,source=uv.lock,target=uv.lock \
11+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
12+
uv sync --frozen --no-install-project --no-dev --package=$PACKAGE
13+
14+
COPY src/$PACKAGE /app/src/$PACKAGE
15+
16+
RUN --mount=type=bind,source=uv.lock,target=uv.lock \
17+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
18+
uv sync --frozen --no-dev --package=$PACKAGE
19+
20+
ENV PATH="/app/.venv/bin:$PATH"
21+
22+
ENTRYPOINT [ "uv", "run" ]

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.py]
12+
indent_size = 4
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Check PR Title
2+
on:
3+
workflow_call:
4+
5+
jobs:
6+
check-pr-title:
7+
name: Check PR title
8+
runs-on: ubuntu-24.04
9+
10+
steps:
11+
- uses: blumilksoftware/[email protected]

.github/workflows/code-quality.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Code Quality Analysis
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
jobs:
10+
analyze:
11+
name: Analyze
12+
runs-on: ubuntu-24.04
13+
permissions:
14+
actions: read
15+
contents: read
16+
security-events: write
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
language: [python]
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Initialize CodeQL
28+
uses: github/codeql-action/init@v3
29+
with:
30+
languages: ${{ matrix.language }}
31+
queries: +security-and-quality
32+
33+
- name: Autobuild
34+
uses: github/codeql-action/autobuild@v3
35+
36+
- name: Perform CodeQL Analysis
37+
uses: github/codeql-action/analyze@v3
38+
with:
39+
category: "/language:${{ matrix.language }}"

.github/workflows/python.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Test&Lint Python Codebase
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "**"
7+
8+
env:
9+
UV_VERSION: "0.6.5"
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build:
17+
env:
18+
UV_CACHE_DIR: /tmp/.uv-cache
19+
runs-on: ubuntu-24.04
20+
steps:
21+
- name: Checkout source code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up python
25+
id: setup-python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version-file: ".python-version"
29+
30+
- name: Set up uv
31+
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
32+
33+
- name: Restore uv cache
34+
uses: actions/cache@v4
35+
with:
36+
path: /tmp/.uv-cache
37+
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
38+
restore-keys: |
39+
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
40+
uv-${{ runner.os }}
41+
42+
- name: Install dependencies
43+
run: uv sync --all-extras --dev --frozen
44+
45+
- name: Set up pre-commit cache
46+
uses: actions/cache@v4
47+
with:
48+
path: ~/.cache/pre-commit
49+
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
50+
restore-keys: |
51+
pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
52+
pre-commit-${{ runner.os }}
53+
54+
- name: Run pre-commit checks
55+
run: uv run pre-commit run --all-files
56+
57+
- name: Test with pytest
58+
run: uv run pytest tests --cov=src
59+
60+
- name: Minimize uv cache
61+
run: uv cache prune --ci

.pre-commit-config.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
ci:
2+
skip: [pytest]
3+
4+
default_language_version:
5+
python: python3.13
6+
7+
repos:
8+
# general checks (see here: https://pre-commit.com/hooks.html)
9+
- repo: https://github.com/pre-commit/pre-commit-hooks
10+
rev: v5.0.0
11+
hooks:
12+
- id: check-yaml
13+
args: [--allow-multiple-documents]
14+
- id: end-of-file-fixer
15+
- id: trailing-whitespace
16+
17+
# ruff - linting + formatting
18+
- repo: https://github.com/astral-sh/ruff-pre-commit
19+
rev: "v0.9.10"
20+
hooks:
21+
- id: ruff
22+
name: ruff
23+
- id: ruff-format
24+
name: ruff-format
25+
26+
# mypy - lint-like type checking
27+
- repo: https://github.com/pre-commit/mirrors-mypy
28+
rev: v1.15.0
29+
hooks:
30+
- id: mypy
31+
name: mypy
32+
33+
# docformatter - formats docstrings to follow PEP 257
34+
- repo: https://github.com/pycqa/docformatter
35+
# todo: replace when >v1.7.5 will be published
36+
rev: 06907d0267368b49b9180eed423fae5697c1e909
37+
hooks:
38+
- id: docformatter
39+
name: docformatter
40+
args:
41+
[
42+
-r,
43+
-i,
44+
--pre-summary-newline,
45+
--make-summary-multi-line,
46+
--wrap-summaries,
47+
"90",
48+
--wrap-descriptions,
49+
"90",
50+
src,
51+
tests,
52+
]
53+
54+
# bandit - find common security issues
55+
- repo: https://github.com/pycqa/bandit
56+
rev: 1.8.3
57+
hooks:
58+
- id: bandit
59+
name: bandit
60+
exclude: ^tests/
61+
args:
62+
- -r
63+
- src
64+
65+
- repo: local
66+
hooks:
67+
- id: pytest
68+
name: pytest
69+
entry: uv run pytest tests --cov=src
70+
language: system
71+
types: [python]
72+
pass_filenames: false
73+
74+
# prettier - formatting JS, CSS, JSON, Markdown, ...
75+
- repo: https://github.com/pre-commit/mirrors-prettier
76+
rev: v3.1.0
77+
hooks:
78+
- id: prettier
79+
exclude: ^uv.lock

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13.2

.renovaterc.json5

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
$schema: "https://docs.renovatebot.com/renovate-schema.json",
3+
extends: [
4+
"config:recommended",
5+
"schedule:daily",
6+
"group:all",
7+
":prConcurrentLimitNone",
8+
":prHourlyLimitNone",
9+
":prImmediately",
10+
],
11+
labels: ["dependencies"],
12+
enabledManagers: [
13+
"dockerfile",
14+
"github-actions",
15+
"pre-commit",
16+
"pep621",
17+
"pyenv",
18+
],
19+
"pre-commit": {
20+
enabled: true,
21+
},
22+
}

README.md

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,109 @@
1-
# python-boilerplate
2-
Minimal Python boilerplate using uv for fast dependency management, isolated virtual environments, and modern project structure.
1+
# Python boilerplate
2+
3+
<p align="center">
4+
<a href="https://github.com/astral-sh/uv" target="blank"><img src="https://github.com/astral-sh/uv/blob/8674968a17e5f2ee0dda01d17aaf609f162939ca/docs/assets/logo-letter.svg" height="60" alt="uv logo" /></a>
5+
</p>
6+
7+
[![CodeQL](https://github.com/MrHDOLEK/python-boilerplate/actions/workflows/code-quality.yml/badge.svg?branch=main)](https://github.com/MrHDOLEK/python-boilerplate/actions/workflows/code-quality.yml)
8+
[![GitHub CI](https://github.com/MrHDOLEK/python-boilerplate/actions/workflows/python.yml/badge.svg?branch=main)](https://github.com/MrHDOLEK/python-boilerplate/actions/workflows/python.yml)
9+
[![GitHub license](https://img.shields.io/github/license/MrHDOLEK/python-boilerplate)](https://github.com/MrHDOLEK/python-boilerplate)
10+
[![Python](https://img.shields.io/badge/python-3.13-blue.svg?logo=python&logoColor=white)](https://www.python.org/)
11+
12+
---
13+
14+
#### A Python boilerplate using modern dev tools
15+
16+
## Project setup
17+
18+
### Development environment
19+
20+
```bash
21+
# Clone the repository
22+
git clone https://github.com/MrHDOLEK/python-boilerplate.git
23+
24+
# Navigate to project directory
25+
cd python-boilerplate/
26+
27+
# Checkout working branch
28+
git checkout <branch>
29+
30+
# Setup Python environment
31+
uv python install
32+
uv venv
33+
source .venv/bin/activate
34+
35+
# Install dependencies
36+
uv sync
37+
38+
# Install pre-commit hooks
39+
pre-commit install
40+
```
41+
42+
## Tools & Features
43+
44+
### uv
45+
46+
Fast Python package manager, written in Rust. Configuration in `pyproject.toml` and dependencies locked in `uv.lock`.
47+
48+
```bash
49+
# Install a package
50+
uv pip install <package>
51+
52+
# Run a command in the environment
53+
uv run pytest tests
54+
```
55+
56+
### pre-commit
57+
58+
Framework for managing git hooks. Configuration in `.pre-commit-config.yaml`.
59+
60+
```bash
61+
# Run against all files
62+
pre-commit run --all-files
63+
```
64+
65+
### ruff
66+
67+
Fast Python linter and formatter. Rules defined in `pyproject.toml`.
68+
69+
```bash
70+
# Format code
71+
uv run ruff format .
72+
73+
# Check code
74+
uv run ruff check .
75+
```
76+
77+
### Testing
78+
79+
Using pytest for tests:
80+
81+
```bash
82+
# Run tests
83+
uv run pytest tests
84+
85+
# Run tests with coverage
86+
uv run pytest tests --cov=src
87+
```
88+
89+
### Docker
90+
91+
```bash
92+
# Login to GitHub Container Registry
93+
echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin
94+
# Build production image
95+
docker buildx build -f .docker/python/Dockerfile -t my-python-application:latest .
96+
# Run the application
97+
docker run -it --rm my-python-application:latest
98+
```
99+
100+
## Documentation
101+
102+
Learn more at these links:
103+
104+
- [uv](https://github.com/astral-sh/uv)
105+
- [pre-commit](https://pre-commit.com/)
106+
- [ruff](https://github.com/astral-sh/ruff)
107+
- [mypy](http://mypy-lang.org/)
108+
- [bandit](https://bandit.readthedocs.io/)
109+
- [pytest](https://docs.pytest.org/)

0 commit comments

Comments
 (0)