From 29a2a7ba3a8edae210ea860e94bb12cbc6532751 Mon Sep 17 00:00:00 2001 From: Daniel O'Connell Date: Tue, 20 May 2025 22:02:31 +0200 Subject: [PATCH] fix ruff --- .github/workflows/ci.yml | 26 +++++++++++++++++++ ...20250504_125653_update_field_for_chunks.py | 1 - src/memory/common/qdrant.py | 2 +- tests/memory/common/parsers/test_comic.py | 9 +++---- .../common/parsers/test_email_parsers.py | 9 ++++--- tests/memory/common/test_extract.py | 1 - .../memory/workers/tasks/test_email_tasks.py | 2 -- tests/memory/workers/test_email.py | 8 +----- 8 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..062bef6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + +jobs: + lint-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install .[all] + pip install ruff==0.11.10 pylint + - name: Run linters + run: | + ruff check . + pylint $(git ls-files '*.py') + - name: Run tests + run: pytest -vv diff --git a/db/migrations/versions/20250504_125653_update_field_for_chunks.py b/db/migrations/versions/20250504_125653_update_field_for_chunks.py index 7654d82..4f497b3 100644 --- a/db/migrations/versions/20250504_125653_update_field_for_chunks.py +++ b/db/migrations/versions/20250504_125653_update_field_for_chunks.py @@ -10,7 +10,6 @@ from typing import Sequence, Union from alembic import op import sqlalchemy as sa -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = "d292d48ec74e" diff --git a/src/memory/common/qdrant.py b/src/memory/common/qdrant.py index 03e4105..2bf7637 100644 --- a/src/memory/common/qdrant.py +++ b/src/memory/common/qdrant.py @@ -93,7 +93,7 @@ def initialize_collections( if collections is None: collections = ALL_COLLECTIONS - logger.info(f"Initializing collections:") + logger.info("Initializing collections:") for name, params in collections.items(): logger.info(f" - {name}") ensure_collection_exists( diff --git a/tests/memory/common/parsers/test_comic.py b/tests/memory/common/parsers/test_comic.py index 79f22e6..3f1bea7 100644 --- a/tests/memory/common/parsers/test_comic.py +++ b/tests/memory/common/parsers/test_comic.py @@ -1,9 +1,8 @@ -import textwrap -from memory.common.parsers.comics import extract_smbc, extract_xkcd -import pytest -from unittest.mock import patch, Mock -import requests +from unittest.mock import patch +import pytest + +from memory.common.parsers.comics import extract_smbc, extract_xkcd MOCK_SMBC_HTML = """ diff --git a/tests/memory/common/parsers/test_email_parsers.py b/tests/memory/common/parsers/test_email_parsers.py index 415900e..d4936e6 100644 --- a/tests/memory/common/parsers/test_email_parsers.py +++ b/tests/memory/common/parsers/test_email_parsers.py @@ -5,7 +5,7 @@ import email.mime.base from datetime import datetime from email.utils import formatdate -from unittest.mock import ANY, patch +from unittest.mock import ANY import pytest from memory.common.parsers.email import ( compute_message_hash, @@ -17,9 +17,10 @@ from memory.common.parsers.email import ( ) - # Use a simple counter to generate unique message IDs without calling make_msgid _msg_id_counter = 0 + + def _generate_test_message_id(): """Generate a simple message ID for testing without expensive calls""" global _msg_id_counter @@ -248,8 +249,8 @@ def test_parse_simple_email(): "body": "Test body content\n", "attachments": [], "sent_at": ANY, - "hash": b'\xed\xa0\x9b\xd4\t4\x06\xb9l\xa4\xb3*\xe4NpZ\x19\xc2\x9b\x87' - + b'\xa6\x12\r\x7fS\xb6\xf1\xbe\x95\x9c\x99\xf1', + "hash": b"\xed\xa0\x9b\xd4\t4\x06\xb9l\xa4\xb3*\xe4NpZ\x19\xc2\x9b\x87" + + b"\xa6\x12\r\x7fS\xb6\xf1\xbe\x95\x9c\x99\xf1", } assert abs(result["sent_at"].timestamp() - test_date.timestamp()) < 86400 diff --git a/tests/memory/common/test_extract.py b/tests/memory/common/test_extract.py index 41a5da5..8e07c6c 100644 --- a/tests/memory/common/test_extract.py +++ b/tests/memory/common/test_extract.py @@ -8,7 +8,6 @@ from memory.common.extract import ( as_file, extract_text, extract_content, - Page, doc_to_images, extract_image, docx_to_pdf, diff --git a/tests/memory/workers/tasks/test_email_tasks.py b/tests/memory/workers/tasks/test_email_tasks.py index 92428cf..8ae3db3 100644 --- a/tests/memory/workers/tasks/test_email_tasks.py +++ b/tests/memory/workers/tasks/test_email_tasks.py @@ -1,6 +1,4 @@ -from unittest import mock import pytest -from datetime import datetime, timedelta from unittest.mock import patch from memory.common.db.models import ( EmailAccount, diff --git a/tests/memory/workers/test_email.py b/tests/memory/workers/test_email.py index 0577aca..bef72f5 100644 --- a/tests/memory/workers/test_email.py +++ b/tests/memory/workers/test_email.py @@ -1,16 +1,10 @@ -import email -import email.mime.multipart -import email.mime.text -import email.mime.base import base64 import pathlib from datetime import datetime -from email.utils import formatdate -from unittest.mock import ANY, MagicMock, patch +from unittest.mock import MagicMock, patch import pytest from memory.common.db.models import ( - SourceItem, MailMessage, EmailAttachment, EmailAccount,