mirror of
https://github.com/Significant-Gravitas/Auto-GPT.git
synced 2025-01-05 10:26:50 +08:00
dx(backend): Fix linting & formatting for autogpt_libs
(#8860)
- Resolves #8859 - Follow-up to #8751 ### Changes - Add `autogpt_libs` to the backend CI path filter - Add `ruff format` step for `autogpt_libs` to `linter.py` and `pre-commit` config - Run `poetry run format` with the new setup
This commit is contained in:
parent
96bba3c1bd
commit
5ccfb8e4c6
2
.github/workflows/platform-backend-ci.yml
vendored
2
.github/workflows/platform-backend-ci.yml
vendored
@ -6,11 +6,13 @@ on:
|
||||
paths:
|
||||
- ".github/workflows/platform-backend-ci.yml"
|
||||
- "autogpt_platform/backend/**"
|
||||
- "autogpt_platform/autogpt_libs/**"
|
||||
pull_request:
|
||||
branches: [master, dev, release-*]
|
||||
paths:
|
||||
- ".github/workflows/platform-backend-ci.yml"
|
||||
- "autogpt_platform/backend/**"
|
||||
- "autogpt_platform/autogpt_libs/**"
|
||||
merge_group:
|
||||
|
||||
concurrency:
|
||||
|
@ -98,6 +98,11 @@ repos:
|
||||
files: ^autogpt_platform/autogpt_libs/
|
||||
args: [--fix]
|
||||
|
||||
- id: ruff-format
|
||||
name: Format (Ruff) - AutoGPT Platform - Libs
|
||||
alias: ruff-lint-platform-libs
|
||||
files: ^autogpt_platform/autogpt_libs/
|
||||
|
||||
- repo: local
|
||||
# isort needs the context of which packages are installed to function, so we
|
||||
# can't use a vendored isort pre-commit hook (which runs in its own isolated venv).
|
||||
@ -140,7 +145,7 @@ repos:
|
||||
# everything in .gitignore, so it works fine without any config or arguments.
|
||||
hooks:
|
||||
- id: black
|
||||
name: Lint (Black)
|
||||
name: Format (Black)
|
||||
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 7.0.0
|
||||
|
@ -2,7 +2,10 @@ import os
|
||||
import subprocess
|
||||
|
||||
directory = os.path.dirname(os.path.realpath(__file__))
|
||||
target_dirs = ["../backend", "../autogpt_libs"]
|
||||
|
||||
BACKEND_DIR = "."
|
||||
LIBS_DIR = "../autogpt_libs"
|
||||
TARGET_DIRS = [BACKEND_DIR, LIBS_DIR]
|
||||
|
||||
|
||||
def run(*command: str) -> None:
|
||||
@ -12,17 +15,19 @@ def run(*command: str) -> None:
|
||||
|
||||
def lint():
|
||||
try:
|
||||
run("ruff", "check", *target_dirs, "--exit-zero")
|
||||
run("isort", "--diff", "--check", "--profile", "black", ".")
|
||||
run("black", "--diff", "--check", ".")
|
||||
run("pyright", *target_dirs)
|
||||
run("ruff", "check", *TARGET_DIRS, "--exit-zero")
|
||||
run("ruff", "format", "--diff", "--check", LIBS_DIR)
|
||||
run("isort", "--diff", "--check", "--profile", "black", BACKEND_DIR)
|
||||
run("black", "--diff", "--check", BACKEND_DIR)
|
||||
run("pyright", *TARGET_DIRS)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Lint failed, try running `poetry run format` to fix the issues: ", e)
|
||||
raise e
|
||||
|
||||
|
||||
def format():
|
||||
run("ruff", "check", "--fix", *target_dirs)
|
||||
run("isort", "--profile", "black", ".")
|
||||
run("black", ".")
|
||||
run("pyright", *target_dirs)
|
||||
run("ruff", "check", "--fix", *TARGET_DIRS)
|
||||
run("ruff", "format", LIBS_DIR)
|
||||
run("isort", "--profile", "black", BACKEND_DIR)
|
||||
run("black", BACKEND_DIR)
|
||||
run("pyright", *TARGET_DIRS)
|
||||
|
Loading…
Reference in New Issue
Block a user