Skip to content

Commit 0a5bc00

Browse files
authored
chore: release of 0.4.0
Merge pull request #16 from Logic-py/develop
2 parents f30b0aa + d209d1d commit 0a5bc00

9 files changed

Lines changed: 259 additions & 9 deletions

File tree

.github/workflows/ci_check_release.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,34 @@ jobs:
110110
run: |
111111
poetry run mypy --config-file pyproject.toml .
112112
113+
test:
114+
runs-on: ubuntu-latest
115+
needs: setup # Ensure setup job has succeeded
116+
117+
steps:
118+
- name: Checkout code
119+
uses: actions/checkout@v4
120+
121+
- name: Set up Python
122+
uses: actions/setup-python@v5
123+
with:
124+
python-version: '3.12'
125+
126+
- name: Install Poetry
127+
run: |
128+
pip install poetry
129+
130+
- name: Install dependencies
131+
run: |
132+
poetry install
133+
134+
- name: Run Unit Tests
135+
run: |
136+
poetry run pytest
137+
113138
create_release:
114139
runs-on: ubuntu-latest
115-
needs: [ lint, type-check ] # Ensure lint and type-check jobs have succeeded
140+
needs: [ lint, type-check, test ] # Ensure lint, type-check, and test jobs have succeeded
116141
if: github.ref == 'refs/heads/main' # Only run on main branch
117142

118143
steps:
@@ -146,4 +171,4 @@ jobs:
146171
draft: false
147172
prerelease: false
148173
env:
149-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
174+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ repos:
2424
types: [ python ]
2525
args: [ "--config", "pyproject.toml" ]
2626
pass_filenames: true
27+
exclude: tests
2728

2829
- id: mypy-type-check
2930
name: Type Checking

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Loïc Motheu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,119 @@
1-
# python-template
1+
# Python Template
22

3-
Used to templatize python projects.
3+
This is a template project for Python, designed to streamline the creation of Python projects using (What I think are)
4+
best practices.
5+
6+
## Table of Contents
7+
8+
- [Features](#features)
9+
- [Getting Started](#getting-started)
10+
- [CI/CD Workflow](#cicd-workflow)
11+
- [Dependencies](#dependencies)
12+
- [Code Quality](#code-quality)
13+
- [Pre-commit Hooks](#pre-commit-hooks)
14+
- [License](#license)
15+
16+
## Features
17+
18+
- Code formatting and linting using [Ruff](https://ruff.rs).
19+
- Type checking with [Mypy](https://mypy.readthedocs.io).
20+
- Pre-commit hooks to maintain code quality.
21+
22+
## Getting Started
23+
24+
Follow these steps to get started with this template:
25+
26+
1. **Clone the repository or use the template directly via GitHub.**
27+
28+
2. **Install Poetry:**
29+
30+
Ensure you have [Poetry](https://python-poetry.org/) installed. If not, you can install it using:
31+
```bash
32+
pip install poetry
33+
```
34+
> **Note:** This template is set up using Poetry version 1.8.3.
35+
36+
3. **Install dependencies:**
37+
38+
```bash
39+
poetry install
40+
```
41+
42+
4. **Ready to Implement:**
43+
44+
You are now ready to implement your project. Keep in mind that this is a base template and not a fully functioning
45+
application.
46+
47+
## CI/CD Workflow
48+
49+
This project includes a continuous integration (CI) workflow that is triggered on every push and pull request, using
50+
GitHub Actions to run the following jobs:
51+
52+
1. **Setup**: Checks out the code, sets up Python, and installs dependencies using Poetry.
53+
2. **Format**: Formats the code with Ruff.
54+
3. **Lint**: Runs linting on the codebase with Ruff.
55+
4. **Type Check**: Checks for type consistency using Mypy.
56+
5. **Create Release**: Automatically creates a GitHub release when code is pushed to the main branch.
57+
58+
### Workflow File
59+
60+
The CI workflow is defined in `.github/workflows/ci_check_release.yml`.
61+
62+
## Dependencies
63+
64+
This project includes the following dependencies:
65+
66+
- **Core Dependencies**:
67+
- `python`: ^3.12
68+
- `loguru`: ^0.7.2
69+
70+
- **Development Dependencies**:
71+
- `ruff`: ^0.6.7 (for code linting and formatting)
72+
- `mypy`: ^1.11.2 (for type checking)
73+
- `pre-commit`: ^3.8.0 (for managing Git hooks)
74+
- `pytest`: ^7.2.0 (for unit testing)
75+
76+
## Code Quality
77+
78+
This repository employs several tools to ensure code quality:
79+
80+
- **Ruff**: A fast Python linter and formatter that enforces a consistent style and detects potential errors.
81+
- **Mypy**: A static type checker for Python that ensures type safety.
82+
83+
## Pre-commit Hooks
84+
85+
To set up pre-commit hooks for automatic formatting and linting on commit, ensure `pre-commit` is installed:
86+
87+
```bash
88+
poetry install
89+
```
90+
91+
Then, install the hooks:
92+
93+
```bash
94+
pre-commit install
95+
```
96+
97+
Once installed, the hooks will run automatically before each commit.
98+
99+
### Pre-commit Hooks Configuration
100+
101+
This repository uses pre-commit hooks to enforce code quality and standards before committing changes. Here’s an
102+
overview of the configured hooks:
103+
104+
#### 1. Commitlint Hook
105+
106+
- **Purpose**: Ensures commit messages adhere to defined conventions for consistency and clarity.
107+
108+
#### 2. Local Hooks
109+
110+
- **Ruff Format**: Automatically formats Python code according to specified rules.
111+
- **Ruff Lint**: Performs linting to catch potential errors and maintain coding standards.
112+
- **Mypy Type Check**: Checks type annotations for consistency and correctness in Python code.
113+
- **Pytest**: Runs the tests found in the /tests folder.
114+
115+
For more information on pre-commit, visit [pre-commit.com](https://pre-commit.com).
116+
117+
## License
118+
119+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

poetry.lock

Lines changed: 58 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-template"
3-
version = "0.3.4"
3+
version = "0.4.0"
44
description = "Used to templatize python projects."
55
authors = ["Loïc Motheu <lmotheu@gmail.com>"]
66
readme = "README.md"
@@ -11,9 +11,10 @@ python = "^3.12"
1111
loguru = "^0.7.2"
1212

1313
[tool.poetry.group.dev.dependencies]
14-
ruff = "^0.6.7"
1514
mypy = "^1.11.2"
1615
pre-commit = "^3.8.0"
16+
pytest = "^8.3.3"
17+
ruff = "^0.6.7"
1718

1819
[tool.ruff]
1920
src = ["src"]
@@ -28,9 +29,10 @@ line-ending = "auto"
2829

2930
[tool.ruff.lint]
3031
select = ["ALL"]
31-
ignore = ["D203", "COM812", "ISC001", "D213"]
32+
ignore = ["D203", "COM812", "ISC001", "D213", "FA102"]
3233
fixable = ["ALL"]
3334
unfixable = []
35+
exclude = ["tests/*"]
3436

3537
[tool.mypy]
3638
exclude = "tests/*"

src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def example(data: str) -> None:
2222
a = 5
2323
b = 1
2424

25-
example(data="5")
25+
example(data=str(a + b))

tests/__init__.py

Whitespace-only changes.

tests/demo_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Demo Unit test Example."""
2+
3+
import pytest
4+
5+
6+
def add(a: int | float, b: int | float) -> int | float:
7+
return a + b
8+
9+
10+
def test_add_positive_numbers():
11+
assert add(1, 2) == 3
12+
13+
14+
def test_add_negative_numbers():
15+
assert add(-1, -1) == -2
16+
17+
18+
def test_add_mixed_numbers():
19+
assert add(-1, 1) == 0
20+
21+
22+
def test_add_zero():
23+
assert add(0, 0) == 0
24+
25+
26+
# The following is optional, as pytest will automatically find tests.
27+
if __name__ == "__main__":
28+
pytest.main()

0 commit comments

Comments
 (0)