From 2496377afa5346582b66d51f55528f97ab322efd Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Feb 2026 01:02:55 +0000 Subject: [PATCH] Improve project template: add CI, fix deps, add examples - Add pytest, pytest-cov, pre-commit to dev dependencies - Add pytest configuration in pyproject.toml - Add lint/format targets to Makefile, remove unused PROJ_NAME - Add example module and test to give users a working starting point - Add GitHub Actions CI workflow (lint, format check, tests) - Add .editorconfig for cross-editor consistency - Fix README: remove incorrect .vscode reference, use make targets https://claude.ai/code/session_012TNv3qDVee7nBFUViVtRvM --- .editorconfig | 21 +++++++++++++++++++++ .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++++ Makefile | 10 +++++++--- README.md | 8 ++++---- pyproject.toml | 6 +++++- src/project_name/example.py | 6 ++++++ tests/test_example.py | 11 +++++++++++ 7 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/ci.yml create mode 100644 src/project_name/example.py create mode 100644 tests/test_example.py diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f457543 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true + +[*.py] +indent_style = space +indent_size = 4 + +[*.{yml,yaml,toml}] +indent_style = space +indent_size = 2 + +[Makefile] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e549132 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v4 + + - name: Set up Python + run: uv python install + + - name: Install dependencies + run: uv sync + + - name: Lint + run: uv run ruff check . + + - name: Check formatting + run: uv run ruff format --check . + + - name: Run tests + run: uv run pytest diff --git a/Makefile b/Makefile index 2b34040..e5dff91 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,4 @@ -PROJ_NAME=PROJ_NAME - -.PHONY: all dryrun test +.PHONY: all dryrun test lint format all: snakemake --cores all -r -p @@ -13,3 +11,9 @@ dag.svg: workflow/Snakefile test: uv run pytest + +lint: + uv run ruff check . + +format: + uv run ruff format . diff --git a/README.md b/README.md index c23350e..a9b1126 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ See [Python environment setup](https://yyahn.com/wiki/Python/Environment%20setup ## Linting and formatting -[ruff](https://docs.astral.sh/ruff/) is included as a dev dependency. VS Code settings (`.vscode/settings.json`) enable format on save. +[ruff](https://docs.astral.sh/ruff/) is included as a dev dependency. Use `make lint` to check for issues and `make format` to auto-format. ### Pre-commit hooks @@ -63,9 +63,9 @@ Use the following instructions to initialize. Commands: - `uv sync` — install dependencies -- `uv run pytest` — run tests -- `uv run ruff check .` — lint -- `uv run ruff format .` — format +- `make test` — run tests +- `make lint` — lint +- `make format` — format - `make all` — run Snakemake pipeline Conventions: diff --git a/pyproject.toml b/pyproject.toml index bdfc5d5..931ce86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,10 +14,14 @@ build-backend = "hatchling.build" packages = ["src/project_name"] [dependency-groups] -dev = ["ruff"] +dev = ["ruff", "pytest", "pytest-cov", "pre-commit"] [tool.ruff] line-length = 88 [tool.ruff.lint] select = ["E", "F", "I"] + +[tool.pytest.ini_options] +testpaths = ["tests"] +addopts = "--cov=project_name --cov-report=term-missing -q" diff --git a/src/project_name/example.py b/src/project_name/example.py new file mode 100644 index 0000000..624ae6c --- /dev/null +++ b/src/project_name/example.py @@ -0,0 +1,6 @@ +"""Example module — replace with your own code.""" + + +def hello(name: str = "world") -> str: + """Return a greeting string.""" + return f"Hello, {name}!" diff --git a/tests/test_example.py b/tests/test_example.py new file mode 100644 index 0000000..dccb0dc --- /dev/null +++ b/tests/test_example.py @@ -0,0 +1,11 @@ +"""Example tests — replace with your own tests.""" + +from project_name.example import hello + + +def test_hello_default() -> None: + assert hello() == "Hello, world!" + + +def test_hello_name() -> None: + assert hello("Alice") == "Hello, Alice!"