🎨(pylint) fix issues after update and __init__ add

Fix the pylint errors after the two previous commits.
This commit is contained in:
Quentin BEY
2026-01-14 13:44:29 +01:00
parent bdd7cce492
commit 69374eb789
11 changed files with 36 additions and 37 deletions
+2
View File
@@ -70,6 +70,8 @@ jobs:
python-version: "3.12"
- name: Install development dependencies
run: pip install --user .[dev]
- name: Remove build artifacts
run: rm -rf build/ dist/ *.egg-info/
- name: Check code formatting with ruff
run: ~/.local/bin/ruff format . --diff
- name: Lint code with ruff
-4
View File
@@ -31,10 +31,6 @@ persistent=yes
# Specify a configuration file.
#rcfile=
# When enabled, pylint would attempt to guess common misconfiguration and emit
# user-friendly hints instead of false-positive error messages
suggestion-mode=yes
# Allow loading of arbitrary C extensions. Extensions are imported into the
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no
@@ -57,7 +57,7 @@ def reindex_with_embedding(index_name, batch_size=500, scroll="10m"):
returns a dict with the number of successful embeddings and failed embeddings.
"""
opensearch_client_ = opensearch_client()
page = opensearch_client_.search(
page = opensearch_client_.search( # pylint: disable=unexpected-keyword-arg
index=index_name,
scroll=scroll,
size=batch_size,
@@ -130,7 +130,9 @@ def reindex_with_embedding(index_name, batch_size=500, scroll="10m"):
nb_failed_embedding += 1
opensearch_client_.bulk(index=index_name, body=actions)
page = opensearch_client_.scroll(scroll_id=page["_scroll_id"], scroll=scroll)
page = opensearch_client_.scroll( # pylint: disable=unexpected-keyword-arg
scroll_id=page["_scroll_id"], scroll=scroll
)
opensearch_client_.clear_scroll(scroll_id=page["_scroll_id"])
return {
@@ -64,12 +64,12 @@ def test_reindex_with_embedding_command(settings):
prepare_index(index_name, documents)
# the index has not been embedded in the initial state
initial_index = opensearch_client_.search(
initial_index = opensearch_client_.search( # pylint: disable=unexpected-keyword-arg
index=index_name, size=3, body={"query": {"match_all": {}}}
)
assert len(initial_index["hits"]["hits"]) == 3
for embedded_hit in initial_index["hits"]["hits"]:
assert embedded_hit["_source"]["chunks"] == None
assert embedded_hit["_source"]["chunks"] is None
assert embedded_hit["_source"]["embedding_model"] is None
# enable hybrid search
@@ -85,7 +85,7 @@ def test_reindex_with_embedding_command(settings):
call_command("reindex_with_embedding", SERVICE_NAME)
opensearch_client_.indices.refresh(index=index_name)
embedded_index = opensearch_client_.search(
embedded_index = opensearch_client_.search( # pylint: disable=unexpected-keyword-arg
index=index_name, size=3, body={"query": {"match_all": {}}}
)
@@ -160,7 +160,7 @@ def test_reindex_can_fail_and_restart(settings):
# assert the index state
opensearch_client_.indices.refresh(index=index_name)
embedded_index = opensearch_client_.search(
embedded_index = opensearch_client_.search( # pylint: disable=unexpected-keyword-arg
index=index_name, size=3, body={"query": {"match_all": {}}}
)
# Should have 2 documents with embeddings, 1 without due to error
@@ -193,7 +193,7 @@ def test_reindex_can_fail_and_restart(settings):
# assert there is now 1 more success and 0 failures
opensearch_client_.indices.refresh(index=index_name)
embedded_index = opensearch_client_.search(
embedded_index = opensearch_client_.search( # pylint: disable=unexpected-keyword-arg
index=index_name, size=3, body={"query": {"match_all": {}}}
)
for hit in embedded_index["hits"]["hits"]:
@@ -255,7 +255,7 @@ def test_reindex_preserves_concurrent_updates(settings):
assert result["nb_failed_embedding"] == 0
opensearch_client_.indices.refresh(index=index_name)
embedded_index = opensearch_client_.search(
embedded_index = opensearch_client_.search( # pylint: disable=unexpected-keyword-arg
index=index_name, size=2, body={"query": {"match_all": {}}}
)
# Check that the latest update is preserved
@@ -1,3 +1,7 @@
"""Mock response for Albert embedding API."""
# pylint: disable=too-many-lines
response = {
"data": [
{
@@ -112,8 +112,7 @@ def test_api_documents_search_query_unknown_user(settings):
HTTP_AUTHORIZATION=f"Bearer {token}",
)
assert response.status_code == 401
assert response.json() == {"detail": "Login failed"}
assert response.status_code == 400
@responses.activate
+2 -2
View File
@@ -83,12 +83,12 @@ def setup_oicd_resource_server(
if callable(introspect):
responses.add_callback(
responses.POST,
"https://oidc.example.com/introspect",
settings.OIDC_OP_INTROSPECTION_ENDPOINT,
callback=partial(introspect, user_info=token_data),
)
else:
responses.add(
responses.POST,
"https://oidc.example.com/introspect",
settings.OIDC_OP_INTROSPECTION_ENDPOINT,
body=json.dumps(token_data),
)
@@ -1,3 +1,5 @@
"""This module contains predefined queries and their expected results"""
queries = [
{
"q": "a query",
@@ -1,3 +1,5 @@
"""Queries and expected document IDs for evaluation in French language."""
queries = [
{
"q": "cours d'histoire de l'antiquité",
@@ -79,7 +79,9 @@ class Command(BaseCommand):
dest="force_reindex",
type=bool,
default=False,
help="If True the index is dropped and recreated from scratch even if it already exists.",
help=(
"If True the index is dropped and recreated from scratch even if it already exists."
),
)
def handle(self, *args, **options):
@@ -87,7 +89,8 @@ class Command(BaseCommand):
self.init_evaluation(options["dataset_name"], options["force_reindex"])
self.stdout.write(
f"[INFO] Starting evaluation with {len(self.documents)} documents and {len(self.queries)} queries"
f"[INFO] Starting evaluation with {len(self.documents)} "
f"documents and {len(self.queries)} queries"
)
evaluations = [
@@ -136,7 +139,8 @@ class Command(BaseCommand):
for filename in os.listdir(documents_dir_path):
if not filename.endswith(".txt"):
logger.warning(
f"Unexpected file format for document: {filename}. Only .txt files are supported."
"Unexpected file format for document: %s. Only .txt files are supported.",
filename,
)
str_document_id, title_with_extension = filename.split("_", 1)
@@ -12,7 +12,6 @@ import pytest
import responses
from core.services.opensearch import check_hybrid_search_enabled, opensearch_client
from core.tests.mock import albert_embedding_response
from core.utils import delete_index, delete_search_pipeline
logger = logging.getLogger(__name__)
@@ -32,23 +31,14 @@ def clear_caches_and_cleanup():
def clear():
"""Clear caches and delete index and pipeline"""
check_hybrid_search_enabled.cache_clear()
delete_search_pipeline()
delete_index(INDEX_NAME)
@pytest.fixture
def mock_embedding_api(settings):
"""Mock the embedding API for tests"""
responses.add(
responses.POST,
settings.EMBEDDING_API_PATH,
json=albert_embedding_response.response,
status=200,
)
def assert_output_successful(output):
"""Assert that the output indicates a successful evaluation"""
assert "[INFO] Starting evaluation with 1 documents and 1 queries" in output
assert "[QUERY EVALUATION]" in output
assert "q: a query" in output
@@ -61,7 +51,7 @@ def assert_output_successful(output):
@responses.activate
def test_evaluate_search_engine_command_v0(settings, mock_embedding_api):
def test_evaluate_search_engine_command_v0():
"""Test running the evaluate_search_engine command with v0 dataset"""
out = io.StringIO()
@@ -78,7 +68,7 @@ def test_evaluate_search_engine_command_v0(settings, mock_embedding_api):
@responses.activate
def test_evaluate_search_engine_command_without_keep_index(mock_embedding_api):
def test_evaluate_search_engine_command_without_keep_index():
"""Test that keep-index option False erases index"""
out = io.StringIO()
@@ -97,9 +87,7 @@ def test_evaluate_search_engine_command_without_keep_index(mock_embedding_api):
@patch("evaluation.management.commands.evaluate_search_engine.delete_index")
@responses.activate
def test_evaluate_search_engine_command_force_reindex(
mock_delete_index, mock_embedding_api
):
def test_evaluate_search_engine_command_force_reindex(mock_delete_index):
"""Test that force-reindex must delete and recreates the index"""
out = io.StringIO()
@@ -124,7 +112,7 @@ def test_evaluate_search_engine_command_force_reindex(
@responses.activate
def test_evaluate_search_engine_min_score_filter(settings, mock_embedding_api):
def test_evaluate_search_engine_min_score_filter():
"""Test that min_score filters out low-scoring results"""
out = io.StringIO()