Skip to content

Commit

Permalink
Merge pull request #20 from Komorebi-AI/pre-commit
Browse files Browse the repository at this point in the history
Añade configuracion pre-commit
  • Loading branch information
albertotb authored Oct 19, 2023
2 parents d00cd8e + 72a7986 commit 340789b
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/autoblack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ name: autoblack
on: [push]
jobs:
build:
if: ${{ false }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with: # https://github.com/stefanzweifel/git-auto-commit-action#checkout-the-correct-branch
ref: ${{ github.head_ref }}
- uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.11'
- run: pip install black
- run: black --check .
- name: If needed, commit black changes to a new pull request
if: failure()
run: |
black .
git config --global user.name github-actions
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
# git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git commit -am "fixup! Format Python code with psf/black push"
git push # --force origin HEAD:$GITHUB_REF
6 changes: 3 additions & 3 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mypy

# Controls when the action will run.
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
Expand All @@ -22,8 +22,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.11'
- name: Test with mypy
run: |
pip install mypy
mypy
mypy
22 changes: 22 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# required to grab the history of the PR
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- 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 }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml → .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Pytest

# Controls when the action will run.
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
Expand All @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.11'
- name: Test with pytest
run: |
pip install -r requirements.txt
Expand Down
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
args: [--maxkb=50000]
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-json
exclude: .vscode/settings.json
- id: check-toml
- id: check-yaml
- id: check-merge-conflict
- id: fix-encoding-pragma
args: [--remove]
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
- id: pretty-format-json
args: [--autofix, --no-ensure-ascii]
exclude: .vscode/settings.json
- repo: https://github.com/psf/black
rev: 23.10.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/jazzband/pip-tools
rev: 7.3.0
hooks:
- id: pip-compile
name: pip-compile requirements
args: [pyproject.toml]
files: ^(pyproject\.toml|requirements\.txt)$
- id: pip-compile
name: pip-compile requirements-dev
args: [--constraint=requirements.txt, --extra=dev, --output-file=requirements-dev.txt, pyproject.toml]
files: ^(pyproject\.toml|requirements-dev\.txt)$
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@ all: env install
env:
conda create -n python-template python=3.11

activate:
activate:
$(CONDA_ACTIVATE) python-template

install:
pip install -r requirements-dev.txt
pip install -e .[dev]

compile:
pip-compile
pip-compile pyproject.toml
pip-compile --extra dev -o requirements-dev.txt -c requirements.txt pyproject.toml

sync:
pip-sync
pip install -e .[dev]

hooks:
pre-commit install
pre-commit run --all-files

docker: build run

build:
Expand All @@ -43,4 +47,4 @@ debug:

push:
docker login https://ghcr.io/komorebi-ai -u $(GH_USER) --password-stdin < $(GH_TOKEN_FILE)
docker push $(DOCKER_IMG_NAME):latest
docker push $(DOCKER_IMG_NAME):latest
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Tools:
- [mypy](https://mypy.readthedocs.io/)
- [pytest](https://docs.pytest.org/en/)
- [pip-tools](https://github.com/jazzband/pip-tools)
- [pre-commit](https://pre-commit.com/)

## Installation

Expand Down Expand Up @@ -61,6 +62,13 @@ Install package in editable mode:
pip install -e .[dev]
```

Install and run pre-commit hooks:

```{bash}
pre-commit install
pre-commit run --all-files
```

Alternatively, you can use the included `env.yml` file that performs all the previous steps:

```{bash}
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pip-tools
pytest
black
mypy
mypy
pre-commit
26 changes: 22 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,47 @@ anyio==3.7.1
# -c requirements.txt
# fastapi
# starlette
black==23.9.1
black==23.10.0
# via template (pyproject.toml)
build==1.0.3
# via pip-tools
cfgv==3.4.0
# via pre-commit
click==8.1.7
# via
# -c requirements.txt
# black
# pip-tools
# typer
# uvicorn
fastapi==0.103.2
distlib==0.3.7
# via virtualenv
fastapi==0.104.0
# via
# -c requirements.txt
# template (pyproject.toml)
filelock==3.12.4
# via virtualenv
h11==0.14.0
# via
# -c requirements.txt
# uvicorn
identify==2.5.30
# via pre-commit
idna==3.4
# via
# -c requirements.txt
# anyio
iniconfig==2.0.0
# via pytest
mypy==1.6.0
mypy==1.6.1
# via template (pyproject.toml)
mypy-extensions==1.0.0
# via
# black
# mypy
nodeenv==1.8.0
# via pre-commit
numpy==1.26.1
# via
# -c requirements.txt
Expand All @@ -63,9 +73,13 @@ pathspec==0.11.2
pip-tools==7.3.0
# via template (pyproject.toml)
platformdirs==3.11.0
# via black
# via
# black
# virtualenv
pluggy==1.3.0
# via pytest
pre-commit==3.5.0
# via template (pyproject.toml)
pydantic==2.4.2
# via
# -c requirements.txt
Expand All @@ -86,6 +100,8 @@ pytz==2023.3.post1
# via
# -c requirements.txt
# pandas
pyyaml==6.0.1
# via pre-commit
six==1.16.0
# via
# -c requirements.txt
Expand Down Expand Up @@ -118,6 +134,8 @@ uvicorn==0.23.2
# via
# -c requirements.txt
# template (pyproject.toml)
virtualenv==20.24.5
# via pre-commit
wheel==0.41.2
# via pip-tools

Expand Down
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile
# pip-compile pyproject.toml
#
annotated-types==0.6.0
# via pydantic
Expand All @@ -14,18 +14,18 @@ click==8.1.7
# via
# typer
# uvicorn
fastapi==0.103.2
# via -r requirements.in
fastapi==0.104.0
# via template (pyproject.toml)
h11==0.14.0
# via uvicorn
idna==3.4
# via anyio
numpy==1.26.1
# via
# -r requirements.in
# pandas
# template (pyproject.toml)
pandas==2.1.1
# via -r requirements.in
# via template (pyproject.toml)
pydantic==2.4.2
# via fastapi
pydantic-core==2.10.1
Expand All @@ -41,7 +41,7 @@ sniffio==1.3.0
starlette==0.27.0
# via fastapi
typer==0.9.0
# via -r requirements.in
# via template (pyproject.toml)
typing-extensions==4.8.0
# via
# fastapi
Expand All @@ -51,4 +51,4 @@ typing-extensions==4.8.0
tzdata==2023.3
# via pandas
uvicorn==0.23.2
# via -r requirements.in
# via template (pyproject.toml)
Empty file modified template/main.py
100644 → 100755
Empty file.

0 comments on commit 340789b

Please sign in to comment.