|
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +# python-template-uv |
| 4 | + |
| 5 | +A modern, batteries‑included [Copier](https://github.com/copier-org/copier) template for bootstrapping Python packages and applications managed with [uv](https://github.com/Astral-Projects/uv) |
| 6 | + |
| 7 | +[](https://copier.readthedocs.io/) |
| 8 | +[](https://github.com/astral-sh/uv) |
| 9 | +[]() |
| 10 | + |
| 11 | +[](https://conventionalcommits.org) |
| 12 | +[](https://github.com/astral-sh/ruff) |
| 13 | +[](https://github.com/pre-commit/pre-commit) |
| 14 | +[](https://github.com/bassemkaroui/python-template-uv/blob/main/LICENSE) |
| 15 | + |
| 16 | + |
| 17 | +</div> |
| 18 | + |
| 19 | +## 🚀 Features |
| 20 | + |
| 21 | +- **Copier-powered scaffolding**: |
| 22 | + Effortlessly generate or update projects with one command. |
| 23 | + |
| 24 | +- **Task runner integration**: |
| 25 | + Project tasks are organized using [duty](https://github.com/pawamoy/duty) and exposed via a [Makefile](https://github.com/bassemkaroui/python-template-uv/blob/main/template/Makefile.jinja) for easy command-line usage. |
| 26 | + Simply run tasks with `make <task>` (e.g. `make check`, `make docs`). |
| 27 | + |
| 28 | +- **Quality & standards** |
| 29 | + - **Formatting** and **Linting**: [Ruff](https://github.com/astral-sh/ruff) ➜ `make format` & `make check-quality` |
| 30 | + - **Type checking**: [Mypy](https://github.com/python/mypy) ➜ `make check-types` |
| 31 | + - **Pre-commit hooks**: [pre-commit](https://pre-commit.com/) |
| 32 | + |
| 33 | +- **Testing & coverage** |
| 34 | + - [**pytest**](https://github.com/pytest-dev/pytest) ➜ `make test` |
| 35 | + - [**Coverage**](https://github.com/nedbat/coveragepy) (text, HTML, XML) ➜ `make coverage` |
| 36 | + - Compatibility testing for multiple versions of Python with [**Tox**](https://github.com/tox-dev/tox) and its plugin [tox-uv](https://github.com/tox-dev/tox-uv) ➜ `make tox` |
| 37 | + |
| 38 | +- **Documentation** |
| 39 | + - [**MkDocs**](https://github.com/mkdocs/mkdocs) with [mkdocs-material](https://github.com/squidfunk/mkdocs-material) theme |
| 40 | + - Live server: `make docs` (serves on localhost:8080) |
| 41 | + - Deploy to GitHub Pages: `make docs-deploy` |
| 42 | + |
| 43 | +- **Release & changelog** |
| 44 | + - [Conventional Commits](https://www.conventionalcommits.org/) + [Commitizen](https://github.com/commitizen-tools/commitizen) + [gitmoji](https://github.com/ljnsn/cz-conventional-gitmoji) |
| 45 | + - Automated `CHANGELOG.md` updates |
| 46 | + - Release new versions ➜ `make release` |
| 47 | + |
| 48 | + |
| 49 | +- **Docker & Docker Compose** |
| 50 | + - Generate `Dockerfile` + `compose.yml` for local development and deployment (GPU support) |
| 51 | + - Docker targets: `make docker-build`, `make docker-start`, `make docker-stop` |
| 52 | + |
| 53 | +- **Optional tooling** |
| 54 | + - Typer CLI scaffold |
| 55 | + - Strict typing |
| 56 | + - Run tests with parallel execution via pytest-xdist |
| 57 | + - Preconfigured dependency categories (ML, data, web, etc.) |
| 58 | + |
| 59 | +- **Future CI support**: |
| 60 | + CI workflows are scaffolded for upcoming releases. |
| 61 | + |
| 62 | + |
| 63 | +## 🛠 Prerequisites |
| 64 | + |
| 65 | +- **Python** ≥ 3.10 |
| 66 | +- **Copier** ≥ 9.6.0 |
| 67 | +- **copier-template-extensions** ≥ 0.3.1 |
| 68 | +- **uv** (if not installed check [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/)) |
| 69 | + |
| 70 | + |
| 71 | +## 🎉 Quickstart |
| 72 | + |
| 73 | +```bash |
| 74 | +# 1. Scaffold a new project |
| 75 | + |
| 76 | +# Option 1: Use uvx to run Copier with extensions |
| 77 | +uvx --with copier-templates-extensions copier copy --trust gh:bassemkaroui/python-template-uv /path/to/my-project |
| 78 | + |
| 79 | +# Option 2: Install Copier globally |
| 80 | +uv tool install copier --with copier-templates-extensions |
| 81 | + |
| 82 | +# Then run |
| 83 | +copier copy --trust gh:bassemkaroui/python-template-uv /path/to/my-project |
| 84 | + |
| 85 | +# Notes: |
| 86 | +# • copier.yaml automatically runs `git init`, so `--trust` is required |
| 87 | +# • Add `--prereleases` to include pre-release versions |
| 88 | +# • Add `--vcs-ref=HEAD` to use the latest commit |
| 89 | + |
| 90 | +# 2. Enter your project |
| 91 | +cd /path/to/my-project |
| 92 | + |
| 93 | +# 3. Set up development environment and hooks |
| 94 | +make setup-dev |
| 95 | + |
| 96 | +# 4. (Optional) Install your CLI globally via uv |
| 97 | +make setup-cli |
| 98 | + |
| 99 | +# 5. Run quality & tests |
| 100 | +make check # runs all checks: lint, types, docs build, API, etc. |
| 101 | +``` |
| 102 | + |
| 103 | +**Stay up to date** |
| 104 | +```bash |
| 105 | +cd /path/to/my-project |
| 106 | + |
| 107 | +uvx copier update --trust --exclude src/ --exclude tests/ . |
| 108 | +``` |
| 109 | + |
| 110 | +> [!WARNING] |
| 111 | +> To be able to [update your project](https://copier.readthedocs.io/en/stable/updating/), do not delete or manually modify the generated `.copier-answers.yml` file. |
| 112 | +
|
| 113 | + |
| 114 | +## 📋 Available Duties |
| 115 | + |
| 116 | +All tasks are defined in `duties.py` and exposed through `make`. Common duties include: |
| 117 | + |
| 118 | +``` |
| 119 | +build Build source and wheel distributions. |
| 120 | +check Check it all! |
| 121 | +check-api Check for API breaking changes. |
| 122 | +check-docs Check if the documentation builds correctly. |
| 123 | +check-quality Run linters and format checks. |
| 124 | +check-types Run static type checks. |
| 125 | +clean Delete build artifacts. |
| 126 | +clean-cache Remove cache files. |
| 127 | +coverage Generate coverage reports (text, HTML, XML). |
| 128 | +docker-build Build Docker images. |
| 129 | +docker-exec-* Dockerized executions of checks, tests, docs, coverage. |
| 130 | +docker-start Start Docker Compose services. |
| 131 | +docker-stop Stop and remove Docker Compose services. |
| 132 | +docs Serve the documentation (localhost:8080). |
| 133 | +docs-deploy Publish docs to GitHub Pages. |
| 134 | +format Auto-format code (Ruff). |
| 135 | +publish Upload distributions to PyPI. |
| 136 | +release Automate version bump, changelog, and publish. |
| 137 | +setup Bootstrap prod environment. |
| 138 | +setup-cli Install the project's CLI globally via uv. |
| 139 | +setup-dev Bootstrap dev environment & install pre-commit hooks. |
| 140 | +test Run tests with pytest. |
| 141 | +tox Run tests across multiple Python versions. |
| 142 | +``` |
| 143 | + |
| 144 | +For the full list and details, see [duties.py](https://github.com/bassemkaroui/python-template-uv/blob/main/template/duties.py.jinja). |
| 145 | + |
| 146 | + |
| 147 | +## 🔧 Template Variables |
| 148 | + |
| 149 | +When running `copier`, you’ll be prompted for: |
| 150 | + |
| 151 | +| Variable | Description | Default | |
| 152 | +| -------------------------- | ---------------------------------------------------------------- | ------------------ | |
| 153 | +| `project_name` | Your project’s **name** (lowercase, letters/digits/dashes) | *—* | |
| 154 | +| `project_description` | A short summary of what your project does | *—* | |
| 155 | +| `author_fullname` | Your full name | from `git` | |
| 156 | +| `author_email` | Your email address | from `git` | |
| 157 | +| `repository_provider` | Where you host your repo (`github` or `other`) | `github` | |
| 158 | +| `homepage` | Project homepage URL | `https://<user>.github.io/<proj>` | |
| 159 | +| `python_version` | Default Python interpreter for development | `3.12` | |
| 160 | +| `min_python_version` | Minimum supported Python version | `3.10` | |
| 161 | +| `with_typer_cli` | Include a Typer CLI scaffold? | `false` | |
| 162 | +| `with_strict_typing` | Enable strict typing enforcement? | `false` | |
| 163 | +| `tox` | Include Tox configuration? | `true` | |
| 164 | +| `coverage_threshold` | Minimum test coverage % | `100` | |
| 165 | +| `with_conventional_commits`| Enforce Conventional Commits? | `true` | |
| 166 | +| `cz_gitmoji` | Include emojis in commit messages? | `true` | |
| 167 | +| `dockerfile` | Generate Dockerfile and Compose file? | `true` | |
| 168 | +| `gpus` | Enable GPU support in Docker builds? | `false` | |
| 169 | + |
| 170 | +> See the full list in [copier.yaml](https://github.com/bassemkaroui/python-template-uv/blob/main/copier.yaml). |
| 171 | +
|
| 172 | + |
| 173 | +## 📄 License |
| 174 | + |
| 175 | +This project is released under the **MIT License**. See [LICENSE](https://github.com/bassemkaroui/python-template-uv/blob/main/LICENSE) for details. |
0 commit comments