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
34 changes: 12 additions & 22 deletions .github/workflows/pre-commit-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,21 @@ name: pre-commit-main
on:
push:
branches: [main]
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run with tmate debugging enabled"
required: false
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# required to grab the history of the PR
fetch-depth: 0
# Not needed since uv installs python automatically
# - uses: actions/setup-python@v5
# with:
# python-version-file: ".python-version"
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
# Needed for mypy, since the pre-commit hook is run in "system" mode
- name: Install dependencies
run: |
uv sync --dev --frozen
# Workaround to allow pre-commit to find the venv where dependencies are installed
- run: |
echo "$PWD/.venv/bin" >> $GITHUB_PATH
uv pip install pip
- uses: pre-commit/[email protected]
pre-commit-all-files:
uses: Komorebi-AI/github-actions/.github/workflows/pre-commit-uv.yml@main
with:
uv-version: 0.8.0
debug-enabled: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
35 changes: 12 additions & 23 deletions .github/workflows/pre-commit-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,22 @@ name: pre-commit-pr

on:
pull_request:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run with tmate debugging enabled"
required: false
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# required to grab the history of the PR
fetch-depth: 0
# Not needed since uv installs python automatically
# - uses: actions/setup-python@v5
# with:
# python-version-file: ".python-version"
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
# Needed for mypy, since the pre-commit hook is run in "system" mode
- name: Install dependencies
run: uv sync --dev --frozen
# Workaround to allow pre-commit to find the venv where dependencies are installed
- run: |
echo "$PWD/.venv/bin" >> $GITHUB_PATH
uv pip install pip
- uses: pre-commit/[email protected]
with:
# Ejecutar solo en ficheros que hayan cambiado https://github.com/pre-commit/action/issues/7
extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
uses: Komorebi-AI/github-actions/.github/workflows/pre-commit-uv.yml@main
with:
uv-version: 0.8.0
debug-enabled: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
pre-commit-args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
34 changes: 12 additions & 22 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
name: Pytest
name: pytest

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run with tmate debugging enabled"
required: false
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
default-shell:
name: Default shell
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
- name: Test with pytest
run: |
uv sync --dev --frozen
uv run pytest
pytest:
uses: Komorebi-AI/github-actions/.github/workflows/pytest-uv.yml@main
with:
uv-version: 0.8.0
debug-enabled: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
19 changes: 4 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
args: [--maxkb=50000]
Expand All @@ -29,26 +29,15 @@ repos:
hooks:
- id: python-use-type-annotations
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
rev: v0.12.4
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
args: [--fix, --show-fixes, --exit-non-zero-on-fix]
- id: ruff-format
types_or: [python, pyi, jupyter]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.1
hooks:
- id: mypy
language: system
args: ["--install-types", "--non-interactive"]
# Esto tiene la desventaja de que siempre se va a ejecutar mypy
# sobre todos los ficheros del repo (incluidos en la conf de mypy)
# Se puede sustituir por `files:`
# Ref: https://www.kianmeng.org/2022/09/excluding-files-with-mypy-hook-for-pre.html
pass_filenames: false
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
Expand All @@ -60,7 +49,7 @@ repos:
types_or: [markdown, yaml]
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.4.9
rev: 0.8.0
hooks:
# Update the uv lockfile
- id: uv-lock
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ hooks:
hooks-update:
uv run pre-commit autoupdate

# Specific packages can be upgrade with `--upgrade-package PKG`
upgrade:
uv lock --upgrade

ruff:
uv run ruff format .
uv run ruff check --fix --show-fixes .
Expand Down
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- markdownlint-disable MD059 -->

# Template

![testing workflow](https://github.com/Komorebi-AI/python-template/actions/workflows/pytest.yml/badge.svg)
Expand All @@ -23,7 +25,6 @@ Tools:

- [uv](https://docs.astral.sh/uv/): manage dependencies, Python versions and virtual environments
- [ruff](https://docs.astral.sh/ruff/): lint and format Python code
- [mypy](https://mypy.readthedocs.io/): check types
- [pytest](https://docs.pytest.org/en/): run unit tests
- [pre-commit](https://pre-commit.com/): manage pre-commit hooks
- [prettier](https://prettier.io/): format YAML and Markdown
Expand Down Expand Up @@ -59,12 +60,18 @@ Install package and pinned dependencies with the [`uv`](https://docs.astral.sh/u

### Library

Install a specific version of the package with `pip` or `uv pip`:
If using `pip` or `uv pip`, a specific version of the package can be installed with:

```{bash}
pip install git+ssh://[email protected]/Komorebi-AI/[email protected]
```

It can also be added to the `requirements.in` or `pyproject.toml`. If using `uv`, it can be added as a dependency with:

```{bash}
uv add "python-template @ git+https://github.com/Komorebi-AI/[email protected]"
```

## Setup development environment (Unix)

Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/) and pre-commit hooks:
Expand Down Expand Up @@ -95,6 +102,18 @@ Remove dependency with:
uv remove <PACKAGE>
```

Upgrade all dependencies:

```{bash}
uv lock --upgrade
```

or a single package:

```{bash}
uv lock --upgrade-package ruff
```

In all cases `uv` will automatically update the `uv.lock` file and sync the virtual environment. This can also be done manually with:

```{bash}
Expand Down Expand Up @@ -122,9 +141,3 @@ make ruff
```{bash}
make test
```

#### Run type checker

```{bash}
make mypy
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ filterwarnings = ["error", "ignore::DeprecationWarning"]
dev-dependencies = [
"pytest",
"ruff",
"mypy",
"pre-commit",
"ipykernel",
"pre-commit-uv>=4.1.4",
]


4 changes: 2 additions & 2 deletions template/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
from __future__ import annotations
from __future__ import annotations # noqa: I001

from importlib.metadata import PackageNotFoundError, version

import typer
import typer # type: ignore

try:
__version__: str | None = version("template")
Expand Down
Loading