From 733a5082b643804f9dc7f806c33d3e4cafadfcc7 Mon Sep 17 00:00:00 2001 From: zhanglei Date: Sun, 3 Nov 2024 00:34:16 +0800 Subject: [PATCH] Enhance flake8 and black checks in Makefile and adjust imports --- Makefile | 8 ++++---- gitlab_bot.py | 10 ++++++++-- pyproject.toml | 2 +- tests/test_llm.py | 1 - tests/test_prompts.py | 9 ++++++--- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 015bc3e..3769a3e 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,12 @@ init: pip install . '.[lint]' '.[test]' '.[package]' lint: - @pflake8 ./src + @pflake8 ./src ./tests ./gitlab_bot.py || (echo "Run 'make fmt' to fix the issues" && exit 1) + @black --check ./src ./tests ./gitlab_bot.py || (echo "Run 'make fmt' to fix the issues" && exit 1) fmt: - @black ./src - @isort --profile black ./src - @$(MAKE) lint + @black ./src ./tests ./gitlab_bot.py + @isort --profile black ./src ./tests ./gitlab_bot.py coverage: lint @pytest --cov=an_copilot tests diff --git a/gitlab_bot.py b/gitlab_bot.py index 544d7be..d412e91 100644 --- a/gitlab_bot.py +++ b/gitlab_bot.py @@ -19,7 +19,13 @@ load_dotenv() # isort:skip -from src.config import bot_gitlab_username, bot_gitlab_url, bot_gitlab_token, bot_port, bot_host +from src.config import ( + bot_gitlab_token, + bot_gitlab_url, + bot_gitlab_username, + bot_host, + bot_port, +) from src.issue_hook import IssueHooks from src.logs import print_event from src.merge_request_hook import MergeRequestHooks @@ -69,7 +75,7 @@ async def merge_request_updated_event(event, gl, *args, **kwargs): @bot.router.register("Merge Request Hook", action="reopen") -async def merge_request_updated_event(event, gl, *args, **kwargs): +async def merge_request_reopen_event(event, gl, *args, **kwargs): if not ignore_event(event): await merge_request_hooks.merge_request_reopen_event(event, gl, args, kwargs) diff --git a/pyproject.toml b/pyproject.toml index 2918ad5..f5a6f53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ package = [ [tool.flake8] max-line-length = 300 -ignore = ['E231', 'E241', 'W291', 'W293', 'W503'] +ignore = ['E231', 'E241', 'W291', 'W293', 'W503', 'E402'] per-file-ignores = [ '__init__.py:F401', ] diff --git a/tests/test_llm.py b/tests/test_llm.py index 1881cdb..19afc0d 100644 --- a/tests/test_llm.py +++ b/tests/test_llm.py @@ -6,7 +6,6 @@ class TestLLM(TestCase): - def test_ai_diffs_summary(self): with open("git_diff.json", "r") as f: git_diff_json = json.loads(f.read()) diff --git a/tests/test_prompts.py b/tests/test_prompts.py index 1e1ea01..0e9c990 100644 --- a/tests/test_prompts.py +++ b/tests/test_prompts.py @@ -5,12 +5,15 @@ class TestPrompts(TestCase): - def test_load_prompt(self): - self.assertIn("你是一个精通多种编程语言的智能机器人", get_prompt_text("DIFFS_SUMMARY_PROMPTS_TEMPLATE", "zh")) + self.assertIn( + "你是一个精通多种编程语言的智能机器人", + get_prompt_text("DIFFS_SUMMARY_PROMPTS_TEMPLATE", "zh"), + ) self.assertIn( "You are an intelligent robot proficient in multiple programming languages and good at reading git-dff reports", - get_prompt_text("DIFFS_SUMMARY_PROMPTS_TEMPLATE", "en")) + get_prompt_text("DIFFS_SUMMARY_PROMPTS_TEMPLATE", "en"), + ) if __name__ == "__main__":