1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-11-16 20:40:10 +01:00

Merge pull request #467 from vemonet/add-pre-commit

Add pre-commit to automatically run formatting when committing
This commit is contained in:
Piero Toffanin 2023-07-23 22:18:15 +02:00 committed by GitHub
commit 5aac8670c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 74 additions and 34 deletions

28
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,28 @@
# See https://pre-commit.com for more information
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
name: " 🐘 Check for added large files"
- id: check-toml
name: " ✔️ Check TOML"
- id: check-yaml
name: " ✔️ Check YAML"
args:
- --unsafe
- id: check-json
name: " ✔️ Check JSON"
- id: trailing-whitespace
name: " ✂️ Trim trailing whitespaces"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.277
hooks:
- id: ruff
name: " ⚡️ Formatting code with Ruff"
args:
- --fix
ci:
autofix_commit_msg: 🎨 [pre-commit] Auto format
autoupdate_commit_msg: ⬆ [pre-commit] pre-commit auto update

View File

@ -33,6 +33,8 @@ git clone https://github.com/LibreTranslate/LibreTranslate.git
cd LibreTranslate
```
Hatch will automatically install the required dependencies in a virtual environment, and enable [`pre-commit`](https://pre-commit.com/), which will run before each commit to run formatting. You can ignore `pre-commit` checks when committing if necessary: `git commit --no-verify -m "Fix"`
Run in development:
```bash
@ -72,6 +74,12 @@ You can also run the tests on multiple python versions:
hatch run all:test
```
You can clean the virtual environment with:
```bash
hatch env prune
```
## Run with Docker
Linux/macOS: `./run.sh [args]`

View File

@ -65,7 +65,7 @@ ltmanage = "libretranslate.manage:manage"
test = [
"pytest >=7.2.0",
"pytest-cov",
"ruff ==0.0.277",
"pre-commit >=3.0.0",
"types-requests",
]
@ -83,13 +83,16 @@ History = "https://github.com/LibreTranslate/LibreTranslate/releases"
features = [
"test",
]
post-install-commands = [
"pre-commit install",
]
[tool.hatch.envs.default.scripts]
dev = "python main.py {args}"
locales = "python scripts/compile_locales.py"
fmt = [
"ruff libretranslate scripts --fix",
"pre-commit run --all --all-files",
]
test = [
"fmt",

View File

@ -1,5 +1,6 @@
from libretranslate import main
def app(*args, **kwargs):
import sys
sys.argv = ['--wsgi']