Skip to content

Commit 5ccfb8e

Browse files
authored
dx(backend): Fix linting & formatting for autogpt_libs (Significant-Gravitas#8860)
- Resolves Significant-Gravitas#8859 - Follow-up to Significant-Gravitas#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
1 parent 96bba3c commit 5ccfb8e

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

.github/workflows/platform-backend-ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ on:
66
paths:
77
- ".github/workflows/platform-backend-ci.yml"
88
- "autogpt_platform/backend/**"
9+
- "autogpt_platform/autogpt_libs/**"
910
pull_request:
1011
branches: [master, dev, release-*]
1112
paths:
1213
- ".github/workflows/platform-backend-ci.yml"
1314
- "autogpt_platform/backend/**"
15+
- "autogpt_platform/autogpt_libs/**"
1416
merge_group:
1517

1618
concurrency:

.pre-commit-config.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ repos:
9898
files: ^autogpt_platform/autogpt_libs/
9999
args: [--fix]
100100

101+
- id: ruff-format
102+
name: Format (Ruff) - AutoGPT Platform - Libs
103+
alias: ruff-lint-platform-libs
104+
files: ^autogpt_platform/autogpt_libs/
105+
101106
- repo: local
102107
# isort needs the context of which packages are installed to function, so we
103108
# can't use a vendored isort pre-commit hook (which runs in its own isolated venv).
@@ -140,7 +145,7 @@ repos:
140145
# everything in .gitignore, so it works fine without any config or arguments.
141146
hooks:
142147
- id: black
143-
name: Lint (Black)
148+
name: Format (Black)
144149

145150
- repo: https://github.com/PyCQA/flake8
146151
rev: 7.0.0

autogpt_platform/backend/linter.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import subprocess
33

44
directory = os.path.dirname(os.path.realpath(__file__))
5-
target_dirs = ["../backend", "../autogpt_libs"]
5+
6+
BACKEND_DIR = "."
7+
LIBS_DIR = "../autogpt_libs"
8+
TARGET_DIRS = [BACKEND_DIR, LIBS_DIR]
69

710

811
def run(*command: str) -> None:
@@ -12,17 +15,19 @@ def run(*command: str) -> None:
1215

1316
def lint():
1417
try:
15-
run("ruff", "check", *target_dirs, "--exit-zero")
16-
run("isort", "--diff", "--check", "--profile", "black", ".")
17-
run("black", "--diff", "--check", ".")
18-
run("pyright", *target_dirs)
18+
run("ruff", "check", *TARGET_DIRS, "--exit-zero")
19+
run("ruff", "format", "--diff", "--check", LIBS_DIR)
20+
run("isort", "--diff", "--check", "--profile", "black", BACKEND_DIR)
21+
run("black", "--diff", "--check", BACKEND_DIR)
22+
run("pyright", *TARGET_DIRS)
1923
except subprocess.CalledProcessError as e:
2024
print("Lint failed, try running `poetry run format` to fix the issues: ", e)
2125
raise e
2226

2327

2428
def format():
25-
run("ruff", "check", "--fix", *target_dirs)
26-
run("isort", "--profile", "black", ".")
27-
run("black", ".")
28-
run("pyright", *target_dirs)
29+
run("ruff", "check", "--fix", *TARGET_DIRS)
30+
run("ruff", "format", LIBS_DIR)
31+
run("isort", "--profile", "black", BACKEND_DIR)
32+
run("black", BACKEND_DIR)
33+
run("pyright", *TARGET_DIRS)

0 commit comments

Comments
 (0)