diff --git a/.github/workflows/server-test.yml b/.github/workflows/build-and-test.yml similarity index 88% rename from .github/workflows/server-test.yml rename to .github/workflows/build-and-test.yml index b89ce1dd..62e32d1f 100644 --- a/.github/workflows/server-test.yml +++ b/.github/workflows/build-and-test.yml @@ -33,6 +33,11 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt + - name: Lint with Ruff + run: | + pip install ruff + ruff check --output-format=github . + - name: Test with pytest run: | pip install pytest pytest-cov diff --git a/.gitignore b/.gitignore index b30bf697..717b791f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ venv .next/ out/ +.ruff_cache/ # production build diff --git a/petercat_utils/rag_helper/task.py b/petercat_utils/rag_helper/task.py index fd26995b..e73bee7f 100644 --- a/petercat_utils/rag_helper/task.py +++ b/petercat_utils/rag_helper/task.py @@ -1,5 +1,6 @@ import json from typing import Optional +from github import Github import boto3 @@ -7,15 +8,14 @@ from .git_issue_task import GitIssueTask from .git_task import GitTask -# Create SQS client -sqs = boto3.client("sqs") - -from github import Github - from ..utils.env import get_env_variable from ..data_class import TaskStatus, TaskType from ..db.client.supabase import get_client +# Create SQS client +sqs = boto3.client("sqs") + + g = Github() TABLE_NAME = "rag_tasks" diff --git a/pyproject.toml b/pyproject.toml index 808ee806..6d545289 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,9 @@ authors = ["raoha.rh "] readme = "README.md" packages = [{include = "petercat_utils"}] +[tool.ruff] +builtins = ["_"] + [tool.poetry.dependencies] python = "^3.8" langchain_community = "^0.2.11" diff --git a/server/auth/get_user_info.py b/server/auth/get_user_info.py index 92aa3aad..7198ad98 100644 --- a/server/auth/get_user_info.py +++ b/server/auth/get_user_info.py @@ -1,5 +1,5 @@ from typing import Annotated -from fastapi import Cookie, HTTPException +from fastapi import Cookie import httpx import secrets import random @@ -8,7 +8,8 @@ from .get_oauth_token import get_oauth_token from petercat_utils import get_client, get_env_variable -random_str = lambda N: ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(N)) +def random_str(N): + return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(N)) AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN") @@ -70,7 +71,7 @@ async def get_user_id(petercat_user_token: Annotated[str | None, Cookie()] = Non user_info = await getUserInfoByToken(petercat_user_token) return user_info['id'] - except Exception as e: + except Exception: return None async def get_user_access_token(petercat_user_token: Annotated[str | None, Cookie()] = None): @@ -83,5 +84,5 @@ async def get_user_access_token(petercat_user_token: Annotated[str | None, Cooki access_token = await getUserAccessToken(user_id=user_info['id']) print(f"get_user_access_token: user_info={user_info}, access_token={access_token}") return access_token - except Exception as e: + except Exception: return None diff --git a/server/main.py b/server/main.py index 90beb75d..48270a30 100644 --- a/server/main.py +++ b/server/main.py @@ -1,6 +1,4 @@ -import os -import uvicorn from fastapi import FastAPI from starlette.middleware.sessions import SessionMiddleware from fastapi.middleware.cors import CORSMiddleware diff --git a/server/models/authorization.py b/server/models/authorization.py index c75423bd..f517c947 100644 --- a/server/models/authorization.py +++ b/server/models/authorization.py @@ -1,7 +1,7 @@ from datetime import datetime import json from pydantic import BaseModel, field_serializer -from typing import Any, Dict +from typing import Dict class Authorization(BaseModel): token: str diff --git a/server/requirements.txt b/server/requirements.txt index 5e29c17d..a6975102 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -6,7 +6,6 @@ mangum langserve langchain_community langchain -langchain-openai PyGithub GitPython python-multipart diff --git a/server/routers/github.py b/server/routers/github.py index 79349885..9b08d4c0 100644 --- a/server/routers/github.py +++ b/server/routers/github.py @@ -59,7 +59,7 @@ def get_app_installations_access_token(installation_id: str, jwt: str): return resp.json() def get_installation_repositories(access_token: str): - url = f"https://api.github.com/installation/repositories" + url = "https://api.github.com/installation/repositories" print("get_installation_repositories", url) resp = requests.get(url, headers={ 'X-GitHub-Api-Version': '2022-11-28', diff --git a/server/tools/bot_builder.py b/server/tools/bot_builder.py index 3b86dd4c..01363190 100644 --- a/server/tools/bot_builder.py +++ b/server/tools/bot_builder.py @@ -1,4 +1,3 @@ -import json from typing import List, Optional from fastapi.responses import JSONResponse from langchain.tools import tool