mirror of
https://github.com/Significant-Gravitas/Auto-GPT.git
synced 2025-01-07 03:17:23 +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:
|
paths:
|
||||||
- ".github/workflows/platform-backend-ci.yml"
|
- ".github/workflows/platform-backend-ci.yml"
|
||||||
- "autogpt_platform/backend/**"
|
- "autogpt_platform/backend/**"
|
||||||
|
- "autogpt_platform/autogpt_libs/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [master, dev, release-*]
|
branches: [master, dev, release-*]
|
||||||
paths:
|
paths:
|
||||||
- ".github/workflows/platform-backend-ci.yml"
|
- ".github/workflows/platform-backend-ci.yml"
|
||||||
- "autogpt_platform/backend/**"
|
- "autogpt_platform/backend/**"
|
||||||
|
- "autogpt_platform/autogpt_libs/**"
|
||||||
merge_group:
|
merge_group:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
|
@ -98,6 +98,11 @@ repos:
|
|||||||
files: ^autogpt_platform/autogpt_libs/
|
files: ^autogpt_platform/autogpt_libs/
|
||||||
args: [--fix]
|
args: [--fix]
|
||||||
|
|
||||||
|
- id: ruff-format
|
||||||
|
name: Format (Ruff) - AutoGPT Platform - Libs
|
||||||
|
alias: ruff-lint-platform-libs
|
||||||
|
files: ^autogpt_platform/autogpt_libs/
|
||||||
|
|
||||||
- repo: local
|
- repo: local
|
||||||
# isort needs the context of which packages are installed to function, so we
|
# 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).
|
# 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.
|
# everything in .gitignore, so it works fine without any config or arguments.
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
name: Lint (Black)
|
name: Format (Black)
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://github.com/PyCQA/flake8
|
||||||
rev: 7.0.0
|
rev: 7.0.0
|
||||||
|
@ -2,7 +2,10 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
directory = os.path.dirname(os.path.realpath(__file__))
|
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:
|
def run(*command: str) -> None:
|
||||||
@ -12,17 +15,19 @@ def run(*command: str) -> None:
|
|||||||
|
|
||||||
def lint():
|
def lint():
|
||||||
try:
|
try:
|
||||||
run("ruff", "check", *target_dirs, "--exit-zero")
|
run("ruff", "check", *TARGET_DIRS, "--exit-zero")
|
||||||
run("isort", "--diff", "--check", "--profile", "black", ".")
|
run("ruff", "format", "--diff", "--check", LIBS_DIR)
|
||||||
run("black", "--diff", "--check", ".")
|
run("isort", "--diff", "--check", "--profile", "black", BACKEND_DIR)
|
||||||
run("pyright", *target_dirs)
|
run("black", "--diff", "--check", BACKEND_DIR)
|
||||||
|
run("pyright", *TARGET_DIRS)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print("Lint failed, try running `poetry run format` to fix the issues: ", e)
|
print("Lint failed, try running `poetry run format` to fix the issues: ", e)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def format():
|
def format():
|
||||||
run("ruff", "check", "--fix", *target_dirs)
|
run("ruff", "check", "--fix", *TARGET_DIRS)
|
||||||
run("isort", "--profile", "black", ".")
|
run("ruff", "format", LIBS_DIR)
|
||||||
run("black", ".")
|
run("isort", "--profile", "black", BACKEND_DIR)
|
||||||
run("pyright", *target_dirs)
|
run("black", BACKEND_DIR)
|
||||||
|
run("pyright", *TARGET_DIRS)
|
||||||
|
Loading…
Reference in New Issue
Block a user