Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

dx(backend): Fix linting & formatting for `autogpt_libs` (#8860)

Reinier van der Leer5ccfb8e4c65c
diff --git a/.github/workflows/platform-backend-ci.yml b/.github/workflows/platform-backend-ci.yml
index 8b168044c1..be0fdca31f 100644
--- a/.github/workflows/platform-backend-ci.yml
+++ b/.github/workflows/platform-backend-ci.yml
@@ -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:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f9ef30e34d..724eb8ef1c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -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
diff --git a/autogpt_platform/backend/linter.py b/autogpt_platform/backend/linter.py
index 9bba9d1963..a85fd6e9dc 100644
--- a/autogpt_platform/backend/linter.py
+++ b/autogpt_platform/backend/linter.py
@@ -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)