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
56 changes: 28 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,40 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.12"
- uses: actions/cache@v4
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: "Set up Python"
uses: actions/setup-python@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
python-version-file: ".python-version"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
uv sync --extra dev
- name: Check with mypy
run: |
python -m mypy .
uv run -m mypy .
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.12"
- uses: actions/cache@v4
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: "Set up Python"
uses: actions/setup-python@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
python-version-file: ".python-version"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
uv sync --extra dev
- name: Test with pytest
run: |
python -m pytest --cov-report html
uv run -m pytest --cov-report html
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
Expand All @@ -65,19 +61,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version-file: ".python-version"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
uv sync --extra 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'])")
INIT_VERSION=$(uv run python -c "import example; print(example.__version__)")
TOML_VERSION=$(uv run 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
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
51 changes: 21 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
[![python](https://img.shields.io/badge/Python-3.12-3776AB.svg?style=flat&logo=python&logoColor=ffd343)](https://docs.python.org/3.12/)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
[![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)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

<!-- omit from toc -->
# Template Python Repository
This repository can be used as a template for a Python application.

<!-- omit from toc -->
## Table of Contents
- [uv](#uv)
- [Installing Dependencies](#installing-dependencies)
- [Testing](#testing)
- [Linting and Formatting](#linting-and-formatting)
- [Type Checking](#type-checking)
- [Testing, Linting, and Type Checking](#testing-linting-and-type-checking)

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

pip install -e .

To install with `dev` dependencies:

pip install -e .[dev]
## uv
This repository is managed using the `uv` Python project manager: https://docs.astral.sh/uv/

## Testing
This library uses Pytest for the unit tests.
These tests are located in the `tests` directory.
To run the tests:
To install `uv`:

python -m pytest tests
```sh
curl -LsSf https://astral.sh/uv/install.sh | sh # Linux/Mac
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" # Windows
```

## Linting and Formatting
This library uses `ruff` for linting and formatting.
This is configured in `pyproject.toml`.

To check the code for linting errors:

python -m ruff check .
## Installing Dependencies
Install the required dependencies using `pip`:

To format the code:
uv sync

python -m ruff format .
To install with `dev` dependencies:

## Type Checking
This library uses `mypy` for static type checking.
This is configured in `pyproject.toml`.
uv sync --extra dev

To check the code for type check errors:
## Testing, Linting, and Type Checking

python -m mypy .
- **Run tests:** `uv run pytest`
- **Lint code:** `uv run ruff check .`
- **Format code:** `uv run ruff format .`
- **Type check:** `uv run mypy .`
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ exclude = [
"venv",
]

extend-exclude = [
"src/**/__init__.py",
]

[tool.ruff.lint]
select = [
"A",
"ANN",
"ASYNC",
"B",
"C4",
"D",
"E",
"EM",
"F",
Expand All @@ -106,6 +111,8 @@ select = [
"YTT",
]
ignore = [
"D203",
"D213",
"PLR0913",
"S101"
]
Expand Down
4 changes: 4 additions & 0 deletions src/example/main.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
"""Example main module."""


def example_function() -> str:
"""Return a string."""
return "This is an example function."
3 changes: 3 additions & 0 deletions tests/example/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Unit tests for the example.main module."""

from example.main import example_function


def test_example_function() -> None:
"""Test the example_function."""
result = example_function()
assert result == "This is an example function."
Loading