diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3ea9a1d..e81e65a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,8 +10,8 @@ permissions: contents: read jobs: - tests: - name: tests + pytest: + name: Run tests runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 8cb584d..a83422f 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,28 @@ ![Nix Flakes](https://img.shields.io/badge/Nix-Flakes-blue?logo=nixos&logoColor=white) ![uv](https://img.shields.io/badge/Package_Manager-uv-blue) [![Tests](https://img.shields.io/badge/CI-Tests-green?logo=github&logoColor=white)](https://github.com/haztecaso/python-template/actions) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) A modern cookiecutter template for Python projects using `uv` as the package manager, Nix flakes for reproducibility, and a clean development setup. +## 🚀 Usage + +### Creating a new project + +If you want to keep your project in sync with this template, you can use +*cruft*. + +```bash +cruft create gh:haztecaso/python-template +``` + +Otherwise you can stick with *cookiecutter*. + +```bash +cookiecutter gh:haztecaso/python-template +``` + ## Features ### Current Features @@ -42,26 +58,3 @@ A modern cookiecutter template for Python projects using `uv` as the package man - 🔄 **Enhanced CI**: GitHub Action test matrix for multi-environment testing - 🐍 **PyPy**: Registry setup and GitHub Action for multi-interpreter testing -## 🚀 Usage - -This template requires the [Nix package manager](https://nixos.org/). You can install `cookiecutter` in your preferred way or create a temporal shell with it: - -```bash -nix-shell -p cookiecutter -``` - -### Creating a new project - -```bash -cookiecutter gh:haztecaso/python-template -``` - -### Initial setup - -```bash -# If you use direnv -direnv allow - -# manually activate the development environment -nix develop -``` diff --git a/hooks/post_gen_project.sh b/hooks/post_gen_project.sh index 2990c23..cbdebb6 100755 --- a/hooks/post_gen_project.sh +++ b/hooks/post_gen_project.sh @@ -13,5 +13,5 @@ uv sync --dev uv run black src tests uv run isort src tests nix build -git init && git branch -m "main" && git add . +git init --initial-branch=main && git add . uv run pre-commit install --hook-type commit-msg --hook-type pre-commit diff --git a/tests/test_template.py b/tests/test_template.py index 65a7e1f..cfa6d9b 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -121,6 +121,12 @@ def test_pytest_runs(project: Result): test_dir = project_path / "tests" assert test_dir.is_dir(), f"Expected tests directory not found: {test_dir}" + # Sync test dependencies + process = run_command("uv sync --group test", project_path) + assert ( + process.returncode == 0 + ), f"uv sync failed with error: {process.stderr}\nOutput: {process.stdout}" + process = run_command("uv run pytest -xvs", project_path) assert ( @@ -151,7 +157,7 @@ def test_mkdocs_runs(project: Result): assert ( process.returncode == 0 - ), f"pytest failed with error: {process.stderr}\nOutput: {process.stdout}" + ), f"mkdocs failed with error: {process.stderr}\nOutput: {process.stdout}" assert ( "Documentation built in" in process.stderr ), f"Expected 'Documentation built in' in mkdocs build stderr, but got: {process.stderr}" diff --git a/{{cookiecutter.project_slug}}/.github/workflows/docs.yml b/{{cookiecutter.project_slug}}/.github/workflows/docs.yml index baf0ed6..31a065b 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/docs.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/docs.yml @@ -1,11 +1,8 @@ -name: docs +name: Docs on: push: branches: [ "main" ] - pull_request: - branches: [ "main" ] - # Allow manual trigger workflow_dispatch: permissions: @@ -13,13 +10,13 @@ permissions: pages: write id-token: write -# Allow only one concurrent deployment concurrency: group: "pages" cancel-in-progress: false jobs: build: + name: Mkdocs build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -47,6 +44,7 @@ jobs: path: ./site deploy: + name: Deploy to github pages environment: name: github-pages url: {% raw -%}${{ github.event.repository.html_url }}/{%- endraw %} diff --git a/{{cookiecutter.project_slug}}/.github/workflows/test.yml b/{{cookiecutter.project_slug}}/.github/workflows/test.yml index a741956..90baf1d 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/test.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: test +name: Test on: push: @@ -10,8 +10,8 @@ permissions: contents: read jobs: - uv-example: - name: python + pytest: + name: Run tests runs-on: ubuntu-latest steps: diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index 4544e28..5440f4b 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -1,7 +1,15 @@ # {{ cookiecutter.project_name }} -{{ cookiecutter.project_short_description }} +
+*{{ cookiecutter.project_short_description }}* +
+ +
+![Test](https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/actions/workflows/test.yml/badge.svg) +
+ +--- {% if cookiecutter.use_mkdocs == 'y' %} -[docs](https://{{cookiecutter.github_username}}.github.io/{{cookiecutter.project_slug}}) +[**Documentation**](https://{{cookiecutter.github_username}}.github.io/{{cookiecutter.project_slug}}) {%- endif %} diff --git a/{{cookiecutter.project_slug}}/docs/index.md b/{{cookiecutter.project_slug}}/docs/index.md index a848124..808c67e 100644 --- a/{{cookiecutter.project_slug}}/docs/index.md +++ b/{{cookiecutter.project_slug}}/docs/index.md @@ -1,23 +1 @@ -{{ cookiecutter.project_short_description }} - -## Installation - -```bash -pip install {{ cookiecutter.project_slug }} -``` - -## Usage - -```python -from {{ cookiecutter.project_slug }} import example - -# Add usage examples here -``` - -## Features - -* Add your project features here - -## License - -{{ cookiecutter.open_source_license }} +{! include_markdown "../README.md" start="" !} diff --git a/{{cookiecutter.project_slug}}/mkdocs.yml b/{{cookiecutter.project_slug}}/mkdocs.yml index f19f8ab..8dfb256 100644 --- a/{{cookiecutter.project_slug}}/mkdocs.yml +++ b/{{cookiecutter.project_slug}}/mkdocs.yml @@ -34,9 +34,6 @@ markdown_extensions: - abbr - def_list - admonition - # We need the markdown-include to inject files into other files - - markdown_include.include: - base_path: docs - meta - toc: permalink: true @@ -65,7 +62,15 @@ markdown_extensions: - pymdownx.tilde plugins: - - search + - autolinks + - include-markdown: + opening_tag: "{!" + closing_tag: "!}" + - git-revision-date-localized: + type: timeago + fallback_to_build_date: true + - minify: + minify_html: true - mkdocstrings: handlers: python: @@ -73,12 +78,7 @@ plugins: show_source: true show_submodules: true docstring_style: google - - autolinks - - git-revision-date-localized: - type: timeago - fallback_to_build_date: true - - minify: - minify_html: true + - search - section-index nav: diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 2ab1c07..2487956 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -28,6 +28,8 @@ dev = [ "isort", "pre-commit", "pyright", +] +test = [ "pytest", {%- if cookiecutter.use_asyncio.lower() == "y" %} "pytest-asyncio", @@ -41,6 +43,7 @@ docs = [ "mkdocs-autolinks-plugin", "mkdocs-git-revision-date-localized-plugin", "mkdocs-htmlproofer-plugin", + "mkdocs-include-markdown-plugin", "mkdocs-material", "mkdocs-minify-plugin", "mkdocs-section-index",