From b3b6a1da1fbf141579f1e8ae12f2b60d5e9daa6a Mon Sep 17 00:00:00 2001 From: stef Date: Wed, 21 May 2025 07:34:09 +0100 Subject: [PATCH 1/2] Refine init script --- README.md | 4 +++- scripts/init_repo.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 scripts/init_repo.sh diff --git a/README.md b/README.md index 063a418..dbfb6c8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ A minimal, conservative Python project template configured with: ## Usage -- **Replace** all occurrences of "`template`" (e.g., in `pyproject.toml` and the top-level `template` directory) with your project name. +- **Initialize the repo**: `./scripts/init_repo.sh` + This replaces the placeholder package name using the repository's name and + pushes the changes to `main`. - **Install dependencies**: `poetry install` - **Run linting**: `make lint` - **Run type checks**: `make typecheck` diff --git a/scripts/init_repo.sh b/scripts/init_repo.sh new file mode 100755 index 0000000..ecf457d --- /dev/null +++ b/scripts/init_repo.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Initialize new project from template by replacing placeholder names. +# Usage: run this script from the repository root after creating a new repo +# from the template. The script will infer the project name from the +# repository directory and push a commit with the updated names to main. + +set -euo pipefail + +OLD_NAME="template" + +# Determine project name from repo root directory +PROJECT_NAME="$(basename "$(git rev-parse --show-toplevel)")" +# Convert any dashes to underscores for the Python package +NEW_NAME="${PROJECT_NAME//-/_}" + +# Rename package directory +if [ -d "$OLD_NAME" ]; then + git mv "$OLD_NAME" "$NEW_NAME" +fi + +# Rename test file if it exists +if [ -f "tests/test_${OLD_NAME}.py" ]; then + git mv "tests/test_${OLD_NAME}.py" "tests/test_${NEW_NAME}.py" +fi + +# Replace occurrences in key project files +FILES=(pyproject.toml README.md Makefile .github/workflows/ci.yml) +for file in "${FILES[@]}"; do + if [ -f "$file" ]; then + sed -i -E "s/\b${OLD_NAME}\b/${NEW_NAME}/g" "$file" + fi +done + +# Update README header with project name +sed -i "1s/.*/# ${PROJECT_NAME}/" README.md + +# Commit and push using existing git credentials + +git add -A +git commit -m "Initialize project with name $NEW_NAME" +git push -f origin main From 5b0b59816cbb099ff513bc36356ef853c781df8a Mon Sep 17 00:00:00 2001 From: stef Date: Sun, 25 May 2025 08:56:50 +0100 Subject: [PATCH 2/2] Merge main into work (#7) --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dbfb6c8..bdf3534 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,53 @@ # Template Python Repository -A minimal, conservative Python project template configured with: +This repository provides a minimal yet opinionated starting point for Python +projects. It bundles common development tools and a GitHub Actions workflow so +you can focus on writing code rather than configuring your environment. + +## Features + - **Poetry** for dependency management -- **Ruff** for linting & formatting -- **Pyright** for type-checking -- **Pytest** for testing -- **Wily** for code complexity analysis -- **GitHub Actions** for CI (lint, test, complexity check) +- **Ruff** for formatting and linting +- **Pyright** for static type checking +- **Pytest** for unit tests +- **Wily** for complexity metrics +- **GitHub Actions** for CI (lint, tests and complexity analysis) - **Makefile** with handy developer commands +## Getting Started + +1. **Replace** all occurrences of `template` with your project name. This is + primarily in `pyproject.toml` and the `template/` package directory. +2. **Install dependencies**: + + ```bash + poetry install + ``` +3. **Run code checks** (formatting, linting and type checking): + + ```bash + make check + ``` +4. **Execute tests**: + + ```bash + make test + ``` + +## Common Makefile Commands + +- **Format code**: `make format` +- **Run linter**: `make lint` +- **Auto-fix lint issues**: `make lint-fix` +- **Type check**: `make typecheck` +- **Watch tests**: `make watch` +- **Show all commands**: `make help` + +## Continuous Integration + +The included GitHub Actions workflow runs linting, type checks, unit tests and +complexity analysis for every push and pull request. + ## Usage - **Initialize the repo**: `./scripts/init_repo.sh`