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
54 changes: 52 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Check with mypy
run: |
python -m mypy .
test:
runs-on: ubuntu-latest
steps:
Expand All @@ -31,7 +52,36 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test]
pip install -e .[dev]
- name: Test with pytest
run: |
python -m pytest
python -m pytest --cov-report html
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: htmlcov
version-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Check version consistency
run: |
echo "Checking if versions in __init__.py and pyproject.toml match..."
INIT_VERSION=$(python -c "import example; print(example.__version__)")
TOML_VERSION=$(python -c "import tomli; print(tomli.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "Version in __init__.py: $INIT_VERSION"
echo "Version in pyproject.toml: $TOML_VERSION"
if [ "$INIT_VERSION" != "$TOML_VERSION" ]; then
echo "::error::Version mismatch! __init__.py has $INIT_VERSION but pyproject.toml has $TOML_VERSION"
exit 1
fi
echo "Versions match!"
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![python](https://img.shields.io/badge/Python-3.12-3776AB.svg?style=flat&logo=python&logoColor=ffd343)](https://docs.python.org/3.12/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

<!-- omit from toc -->
# Template Python Repository
This repository can be used as a template for a Python application.
Expand All @@ -9,15 +10,16 @@ This repository can be used as a template for a Python application.
- [Installing Dependencies](#installing-dependencies)
- [Testing](#testing)
- [Linting and Formatting](#linting-and-formatting)
- [Type Checking](#type-checking)

## Installing Dependencies
Install the required dependencies using `pip`:

pip install -e .

To install with `dev` and `test` dependencies:
To install with `dev` dependencies:

pip install -e .[dev,test]
pip install -e .[dev]

## Testing
This library uses Pytest for the unit tests.
Expand All @@ -37,3 +39,11 @@ To check the code for linting errors:
To format the code:

python -m ruff format .

## Type Checking
This library uses `mypy` for static type checking.
This is configured in `pyproject.toml`.

To check the code for type check errors:

python -m mypy .
34 changes: 27 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "template-python"
version = "1.0.0"
version = "0.1.0"
description = "An example pyproject.toml."
readme = "README.md"
requires-python = ">=3.12"
Expand All @@ -26,19 +26,18 @@ dependencies = [
[project.optional-dependencies]
dev = [
"ruff",
]

test = [
"mypy",
"pytest",
"pytest-cov",
"tomli",
]

[project.urls]
repository = "https://github.com/javidahmed64592/template-python"

[tool.pytest.ini_options]
addopts = [
"-vx",
"-vv",
"--cov",
"--cov-report",
"term-missing",
Expand Down Expand Up @@ -77,9 +76,9 @@ exclude = [
"venv",
]


[tool.ruff.lint]
select = [
"A",
"ANN",
"ASYNC",
"B",
Expand All @@ -96,15 +95,20 @@ select = [
"NPY",
"PD",
"PERF",
"PL",
"PT",
"RET",
"RUF",
"S",
"TRY",
"UP",
"W",
"YTT",
]
ignore = ["ANN101", "ANN102", "E501","E741","ISC001","N999"]
ignore = [
"PLR0913",
"S101"
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
Expand All @@ -118,3 +122,19 @@ quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.mypy]
warn_unused_configs = true
disallow_incomplete_defs = true
check_untyped_defs = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = true
warn_unreachable = true
pretty = true

[[tool.mypy.overrides]]
module = [
"numpy.*",
]
ignore_missing_imports = true
1 change: 1 addition & 0 deletions src/example/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
2 changes: 2 additions & 0 deletions src/example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def example_function() -> str:
return "This is an example function."
6 changes: 6 additions & 0 deletions tests/example/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from example.main import example_function


def test_example_function() -> None:
result = example_function()
assert result == "This is an example function."
3 changes: 0 additions & 3 deletions tests/test_script.py

This file was deleted.