2024-07-17 10:54:29 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
directory = os.path.dirname(os.path.realpath(__file__))
|
2024-12-03 11:34:07 +00:00
|
|
|
|
|
|
|
BACKEND_DIR = "."
|
|
|
|
LIBS_DIR = "../autogpt_libs"
|
|
|
|
TARGET_DIRS = [BACKEND_DIR, LIBS_DIR]
|
2024-07-17 10:54:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def run(*command: str) -> None:
|
|
|
|
print(f">>>>> Running poetry run {' '.join(command)}")
|
|
|
|
subprocess.run(["poetry", "run"] + list(command), cwd=directory, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
def lint():
|
2024-07-19 16:10:16 +00:00
|
|
|
try:
|
2024-12-03 11:34:07 +00:00
|
|
|
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)
|
2024-07-19 16:10:16 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print("Lint failed, try running `poetry run format` to fix the issues: ", e)
|
|
|
|
raise e
|
2024-07-17 10:54:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def format():
|
2024-12-03 11:34:07 +00:00
|
|
|
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)
|