Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add various ruff rules #562

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libs/colbert/ragstack_colbert/cassandra_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,3 @@ def close(self) -> None:
"""
Cleans up any open resources.
"""
pass
1 change: 0 additions & 1 deletion libs/colbert/ragstack_colbert/colbert_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def close(self) -> None:
"""
Closes any open resources held by the retriever.
"""
pass

async def _query_relevant_chunks(
self, query_embedding: Embedding, top_k: int
Expand Down
1 change: 0 additions & 1 deletion libs/e2e-tests/e2e_tests/langchain/test_astra.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def test_wrong_connection_parameters(vectorstore: AstraDBVectorStore):
pytest.fail("Should have thrown exception")
except ConnectError as e:
print("Error:", e)
pass

# This is expected to be a valid endpoint,
# because we want to test an AUTHENTICATION error
Expand Down
8 changes: 5 additions & 3 deletions libs/e2e-tests/e2e_tests/langchain/test_unstructured.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import TYPE_CHECKING

import pytest
from langchain.text_splitter import TokenTextSplitter
from langchain_community.document_loaders import UnstructuredAPIFileLoader
Expand All @@ -15,9 +17,9 @@
)
from e2e_tests.langchain.rag_application import BASIC_QA_PROMPT
from e2e_tests.test_utils import get_local_resource_path
from e2e_tests.test_utils.vector_store_handler import (
VectorStoreTestContext,
)

cbornet marked this conversation as resolved.
Show resolved Hide resolved
if TYPE_CHECKING:
from e2e_tests.test_utils.vector_store_handler import VectorStoreTestContext


@pytest.mark.parametrize("vector_store", ["cassandra", "astra_db"])
Expand Down
1 change: 0 additions & 1 deletion libs/e2e-tests/e2e_tests/llama_index/test_astra.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def test_wrong_connection_parameters(environment: Environment):
pytest.fail("Should have thrown exception")
except ConnectError as e:
print("Error:", e)
pass

# This is expected to be a valid endpoint,
# because we want to test an AUTHENTICATION error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import TYPE_CHECKING

import pytest
from langchain.embeddings import HuggingFaceInferenceAPIEmbeddings
Expand Down Expand Up @@ -27,9 +28,9 @@
set_current_test_info,
)
from e2e_tests.test_utils import get_local_resource_path
from e2e_tests.test_utils.vector_store_handler import (
VectorStoreTestContext,
)

if TYPE_CHECKING:
from e2e_tests.test_utils.vector_store_handler import VectorStoreTestContext


def _openai_llm(**kwargs) -> OpenAI:
Expand Down
8 changes: 5 additions & 3 deletions libs/e2e-tests/e2e_tests/llama_index/test_llama_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
pytest.skip("llama_parse is not supported, skipping tests", allow_module_level=True)


from typing import TYPE_CHECKING

from llama_index.core import ServiceContext, StorageContext, VectorStoreIndex
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
Expand All @@ -15,9 +17,9 @@
set_current_test_info,
)
from e2e_tests.test_utils import get_local_resource_path
from e2e_tests.test_utils.vector_store_handler import (
VectorStoreTestContext,
)

if TYPE_CHECKING:
from e2e_tests.test_utils.vector_store_handler import VectorStoreTestContext


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def mmr_traversal_search(
# Select the best item, K times.
depths = {id: 0 for id in helper.candidate_ids()}
visited_tags = set()
for _ in range(0, k):
for _ in range(k):
selected_id = helper.pop_best()

if selected_id is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from typing import Any, List, Optional, Tuple
from typing import TYPE_CHECKING, Any, List, Optional, Tuple

from langchain_core.callbacks.manager import (
AsyncCallbackManagerForRetrieverRun,
CallbackManagerForRetrieverRun,
)
from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from ragstack_colbert import Chunk
from ragstack_colbert.base_retriever import BaseRetriever as ColbertBaseRetriever

if TYPE_CHECKING:
from ragstack_colbert import Chunk


class ColbertRetriever(BaseRetriever):
"""Chain for langchain retrieve using ColBERT vector store.
Expand Down
11 changes: 7 additions & 4 deletions libs/langchain/ragstack_langchain/graph_store/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from abc import abstractmethod
from typing import (
TYPE_CHECKING,
Any,
AsyncIterable,
ClassVar,
Expand All @@ -13,10 +14,6 @@
Set,
)

from langchain_core.callbacks import (
AsyncCallbackManagerForRetrieverRun,
CallbackManagerForRetrieverRun,
)
from langchain_core.documents import Document
from langchain_core.load import Serializable
from langchain_core.pydantic_v1 import Field
Expand All @@ -25,6 +22,12 @@

from ragstack_langchain.graph_store.links import METADATA_LINKS_KEY, Link

if TYPE_CHECKING:
from langchain_core.callbacks import (
AsyncCallbackManagerForRetrieverRun,
CallbackManagerForRetrieverRun,
)


def _has_next(iterator: Iterator) -> bool:
"""Checks if the iterator has more elements.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Generic, Iterable, Set, TypeVar
from typing import TYPE_CHECKING, Generic, Iterable, Set, TypeVar

from ragstack_langchain.graph_store.links import Link
if TYPE_CHECKING:
from ragstack_langchain.graph_store.links import Link

InputT = TypeVar("InputT")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Any, List, Optional, Tuple
from typing import TYPE_CHECKING, Any, List, Optional, Tuple

from llama_index.core.callbacks.base import CallbackManager
from llama_index.core.constants import DEFAULT_SIMILARITY_TOP_K
from llama_index.core.retrievers import BaseRetriever
from llama_index.core.schema import NodeWithScore, QueryBundle, TextNode
from ragstack_colbert import Chunk
from ragstack_colbert.base_retriever import BaseRetriever as ColbertBaseRetriever

if TYPE_CHECKING:
from ragstack_colbert import Chunk


class ColbertRetriever(BaseRetriever):
"""ColBERT vector store retriever.
Expand Down
2 changes: 1 addition & 1 deletion libs/ragulate/ragstack_ragulate/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,4 @@ def compare(self, recipes: List[str], output: str):
elif output == "histogram-grid":
self.output_histograms_by_dataset(df=df, metrics=metrics)
else:
raise ValueError()
raise ValueError
1 change: 0 additions & 1 deletion libs/ragulate/ragstack_ragulate/pipelines/base_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class BasePipeline(ABC):
@abstractmethod
def pipeline_type(self):
"""type of pipeline (ingest, query, cleanup)"""
pass

@property
@abstractmethod
Expand Down
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ extend-include = ["*.ipynb"]

[tool.ruff.lint]
ignore = [
"COM812", # Messes with the formatter
"ERA", # Do we want to activate (no commented code) ?
"ISC001", # Messes with the formatter
"PERF203", # Incorrect detection
"TRY003", # A bit too strict ?
]
Expand All @@ -67,20 +70,34 @@ select = [
"ASYNC",
"B",
"C4",
"COM",
"DTZ",
"E",
"EXE",
"F",
"FLY",
"FURB",
"I",
"ICN",
"INT",
"ISC",
"LOG",
"N",
"NPY",
"PERF",
"PIE",
"PGH",
"Q",
"RSE",
"RUF",
"SIM",
"SLOT",
"T10",
"TCH",
"TRY",
"UP",
"W",
"YTT",
]

[tool.ruff.lint.per-file-ignores]
Expand Down
Empty file modified scripts/ci-common-env.sh
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions scripts/format-example-notebooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import json
import os

Expand Down
2 changes: 2 additions & 0 deletions scripts/generate-changelog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

try:
import requests
except ImportError:
Expand Down
2 changes: 2 additions & 0 deletions scripts/generate-testspace-report.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import json
import os.path
import sys
Expand Down
2 changes: 2 additions & 0 deletions scripts/parse-snyk-report.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import json
import sys

Expand Down
Loading