Skip to content

Commit 67b3376

Browse files
authored
Add ruff rules for logging-format (#568)
1 parent beca788 commit 67b3376

File tree

19 files changed

+92
-74
lines changed

19 files changed

+92
-74
lines changed

examples/notebooks/conftest.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@ def get_required_env(name) -> str:
2828

2929
def try_delete_with_backoff(collection: str, sleep=1, max_tries=2):
3030
try:
31-
logging.info(f"deleting collection {collection}")
31+
logging.info("deleting collection %s", collection)
3232
response = client.delete_collection(collection)
33-
logging.info(f"delete collection {collection} response: {response!s}")
34-
except Exception as e:
33+
logging.info("delete collection %s response: %s", collection, response)
34+
except Exception:
3535
max_tries -= 1
3636
if max_tries < 0:
3737
raise
3838

39-
logging.warning(f"An exception occurred deleting collection {collection}: {e}")
39+
logging.warning(
40+
"An exception occurred deleting collection %s: ", collection, exc_info=True
41+
)
4042
time.sleep(sleep)
4143
try_delete_with_backoff(collection, sleep * 2, max_tries)
4244

4345

4446
def before_notebook():
4547
collections = client.get_collections().get("status").get("collections")
46-
logging.info(f"Existing collections: {collections}")
48+
logging.info("Existing collections: %s", collections)
4749
for collection in collections:
4850
try_delete_with_backoff(collection)

libs/colbert/ragstack_colbert/cassandra_database.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def _initialize(
9595
is_astra = False
9696

9797
logging.info(
98-
f"Cassandra store is running on "
99-
f"{'AstraDB' if is_astra else 'Apache Cassandra'}."
98+
"Cassandra store is running on %s",
99+
"AstraDB" if is_astra else "Apache Cassandra",
100100
)
101101

102102
self._table = ClusteredMetadataVectorCassandraTable(
@@ -114,12 +114,15 @@ def _log_insert_error(
114114
):
115115
if embedding_id == -1:
116116
logging.error(
117-
f"issue inserting document data: {doc_id} chunk: {chunk_id}: {exp}"
117+
"issue inserting document data: %s chunk: %s: %s", doc_id, chunk_id, exp
118118
)
119119
else:
120120
logging.error(
121-
f"issue inserting document embedding: {doc_id} chunk: {chunk_id} "
122-
f"embedding: {embedding_id}: {exp}"
121+
"issue inserting document embedding: %s chunk: %s embedding: %s: %s",
122+
doc_id,
123+
chunk_id,
124+
embedding_id,
125+
exp,
123126
)
124127

125128
def add_chunks(self, chunks: List[Chunk]) -> List[Tuple[str, int]]:
@@ -298,13 +301,13 @@ def delete_chunks(self, doc_ids: List[str]) -> bool:
298301
try:
299302
self._table.delete_partition(partition_id=doc_id)
300303
except Exception:
301-
logging.exception(f"issue on delete of document: {doc_id}")
304+
logging.exception("issue on delete of document: %s", doc_id)
302305
failed_docs.append(doc_id)
303306

304307
if len(failed_docs) > 0:
305308
raise CassandraDatabaseError(
306-
f"delete failed for these docs: {failed_docs}. "
307-
f"See error logs for more info."
309+
"delete failed for these docs: %s. See error logs for more info.",
310+
failed_docs,
308311
)
309312

310313
return True
@@ -353,7 +356,7 @@ async def adelete_chunks(
353356

354357
for doc_id, exp in results:
355358
if exp is not None:
356-
logging.error(f"issue deleting document: {doc_id}: {exp}")
359+
logging.error("issue deleting document: %s: %s", doc_id, exp)
357360
success = False
358361
failed_docs.append(doc_id)
359362

libs/colbert/ragstack_colbert/colbert_retriever.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ def all_gpus_support_fp16(is_cuda: Optional[bool] = False):
4040
compute_capability[0] == 5 and compute_capability[1] < 3
4141
):
4242
logging.info(
43-
f"Device {device_id} with compute capability {compute_capability} "
44-
f"does not support FP16 (half-precision) operations. "
45-
f"Using FP32 (full-precision) operations."
43+
"Device %s with compute capability %s does not support FP16 "
44+
"(half-precision) operations. Using FP32 (full-precision) operations.",
45+
device_id,
46+
compute_capability,
4647
)
4748
return False
4849

@@ -186,8 +187,9 @@ async def _query_relevant_chunks(
186187
for result in results:
187188
if isinstance(result, Exception):
188189
logging.error(
189-
f"Issue on database.get_relevant_chunks(): "
190-
f"{result} at {get_trace(result)}"
190+
"Issue on database.get_relevant_chunks(): %s at %s",
191+
result,
192+
get_trace(result),
191193
)
192194
else:
193195
chunks.update(result)
@@ -209,8 +211,9 @@ async def _get_chunk_embeddings(self, chunks: Set[Chunk]) -> List[Chunk]:
209211
for result in results:
210212
if isinstance(result, Exception):
211213
logging.error(
212-
f"Issue on database.get_chunk_embeddings(): "
213-
f"{result} at {get_trace(result)}"
214+
"Issue on database.get_chunk_embeddings(): %s at %s",
215+
result,
216+
get_trace(result),
214217
)
215218

216219
return results
@@ -261,8 +264,9 @@ async def _get_chunk_data(
261264
for result in results:
262265
if isinstance(result, Exception):
263266
logging.error(
264-
f"Issue on database.get_chunk_data(): "
265-
f"{result} at {get_trace(result)}"
267+
"Issue on database.get_chunk_data(): %s at %s",
268+
result,
269+
get_trace(result),
266270
)
267271

268272
return results
@@ -335,8 +339,10 @@ async def aembedding_search(
335339

336340
top_k = max(math.floor(len(query_embedding) / 2), 16)
337341
logging.debug(
338-
f"based on query length of {len(query_embedding)} tokens, "
339-
f"retrieving {top_k} results per token-embedding"
342+
"based on query length of %s tokens, retrieving %s results per "
343+
"token-embedding",
344+
len(query_embedding),
345+
top_k,
340346
)
341347

342348
# search for relevant chunks (only with `doc_id` and `chunk_id` set)

libs/colbert/ragstack_colbert/text_encoder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, config: ColBERTConfig, verbose: Optional[int] = 3) -> None:
5757
verbose (int): The level of logging to use
5858
"""
5959

60-
logging.info(f"Cuda enabled GPU available: {torch.cuda.is_available()}")
60+
logging.info("Cuda enabled GPU available: %s", torch.cuda.is_available())
6161

6262
self._checkpoint = Checkpoint(
6363
config.checkpoint, colbert_config=config, verbose=verbose
@@ -79,7 +79,7 @@ def encode_chunks(self, chunks: List[Chunk], batch_size: int = 640) -> List[Chun
7979
document lengths.
8080
"""
8181

82-
logging.debug(f"#> Encoding {len(chunks)} chunks..")
82+
logging.debug("#> Encoding %s chunks..", len(chunks))
8383

8484
embedded_chunks: List[Chunk] = []
8585

@@ -115,7 +115,7 @@ def encode_query(
115115
if query_maxlen < 0:
116116
tokens = self._checkpoint.query_tokenizer.tokenize([text])
117117
query_maxlen = calculate_query_maxlen(tokens)
118-
logging.debug(f"Calculated dynamic query_maxlen of {query_maxlen}")
118+
logging.debug("Calculated dynamic query_maxlen of %s", query_maxlen)
119119

120120
prev_query_maxlen = self._checkpoint.query_tokenizer.query_maxlen
121121
self._checkpoint.query_tokenizer.query_maxlen = query_maxlen

libs/colbert/tests/integration_tests/test_embedding_retrieval.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ def chunk_texts(text, chunk_size, overlap_size):
7878
)
7979
assert len(chunk_scores) == 5
8080
for chunk, score in chunk_scores:
81-
logging.info(f"got chunk_id {chunk.chunk_id} with score {score}")
81+
logging.info("got chunk_id %s with score %s", chunk.chunk_id, score)
8282

8383
best_chunk = chunk_scores[0][0]
8484
assert len(best_chunk.text) > 0
8585
logging.info(
86-
f"Highest scoring chunk_id: {best_chunk.chunk_id} with text: {best_chunk.text}"
86+
"Highest scoring chunk_id: %s with text: %s",
87+
best_chunk.chunk_id,
88+
best_chunk.text,
8789
)

libs/colbert/tests/unit_tests/test_colbert_baseline_embeddings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_embeddings_with_baseline():
9595
assert similarity.shape == torch.Size([1]) # this has to be scalar
9696
# debug code to identify which token deviates
9797
if similarity.item() < 0.99:
98-
logging.warning(f"n = {n}, similarity = {similarity.item()}")
98+
logging.warning("n = %s, similarity = %s", n, similarity.item())
9999
assert similarity.item() > 0.99
100100
n = n + 1
101101

@@ -131,7 +131,7 @@ def test_colbert_embedding_against_vanilla_impl():
131131

132132

133133
def model_embedding(model: str):
134-
logging.info(f"test model compatibility {model}")
134+
logging.info("test model compatibility %s", model)
135135
colbert_svc = ColbertEmbeddingModel(
136136
checkpoint=model,
137137
query_maxlen=32,

libs/e2e-tests/e2e_tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def pytest_runtest_makereport(item, call):
100100
if not info:
101101
test_path = pathlib.PurePath(item.path)
102102
info = test_path.parent.name + "::" + test_path.name + "::" + item.name
103-
logging.info(f"Test {info} took: {total_time} seconds")
103+
logging.info("Test %s took: %s seconds", info, total_time)
104104
paths = str(item.path).split(os.sep)
105105
is_langchain = False
106106
is_llamaindex = False
@@ -127,7 +127,7 @@ def pytest_runtest_makereport(item, call):
127127
or "unconditional skip" in result
128128
)
129129
if not skip_report_line:
130-
logging.info("Test report line: " + report_line)
130+
logging.info("Test report line: %s", report_line)
131131
if rep.outcome != "passed":
132132
# also keep skipped tests in the report
133133
failed_report_lines.append(report_line)
@@ -149,7 +149,7 @@ def pytest_runtest_makereport(item, call):
149149
elif is_llamaindex:
150150
llamaindex_report_lines.append(report_line)
151151
else:
152-
logging.info("Skipping test report line: " + result)
152+
logging.info("Skipping test report line: %s", result)
153153
os.environ["RAGSTACK_E2E_TESTS_TEST_INFO"] = ""
154154

155155
if rep.when == "call":

libs/e2e-tests/e2e_tests/langchain/rag_application.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def run_rag_custom_chain(
196196
run_id = cb.traced_runs[0].id
197197
record_langsmith_sharelink(run_id, record_property)
198198

199-
logging.info("Got response: " + response)
199+
logging.info("Got response: %s", response)
200200
assert "2020" in response, f"Expected 2020 in the answer but got: {response}"
201201

202202

@@ -209,7 +209,7 @@ def run_conversational_rag(
209209
logging.info("Starting to add texts to vector store")
210210
start = time.perf_counter_ns()
211211
vector_store.add_texts(SAMPLE_DATA)
212-
logging.info(f"Added texts in {(time.perf_counter_ns() - start) / 1e9} seconds")
212+
logging.info("Added texts in %s seconds", (time.perf_counter_ns() - start) / 1e9)
213213
retriever = vector_store.as_retriever()
214214
memory = ConversationSummaryMemory(
215215
llm=llm,
@@ -229,13 +229,13 @@ def run_conversational_rag(
229229
result = conversation.invoke({"question": "what is MyFakeProductForTesting?"})
230230
run_id = cb.traced_runs[0].id
231231
record_langsmith_sharelink(run_id, record_property)
232-
logging.info("First result: " + str(result))
232+
logging.info("First result: %s", result)
233233

234234
with callbacks.collect_runs() as cb:
235235
result = conversation.invoke({"question": "and when was it released?"})
236236
run_id = cb.traced_runs[0].id
237237
record_langsmith_sharelink(run_id, record_property)
238-
logging.info("Second result: " + str(result))
238+
logging.info("Second result: %s", result)
239239

240240
answer = result["answer"]
241241
assert "2020" in answer, f"Expected 2020 in the answer but got: {answer}"

libs/e2e-tests/e2e_tests/langchain/test_compatibility_rag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def embed_query(self, text: str) -> List[float]:
465465
f"Tell me which one of these products it is part of. "
466466
f"Only include product from the ones below: {docs_str}."
467467
)
468-
logging.info(f"Prompt: {prompt}")
468+
logging.info("Prompt: %s", prompt)
469469

470470
text_message = {
471471
"type": "text",

libs/e2e-tests/e2e_tests/llama_index/test_astra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,5 @@ def _get_text_embedding(self, text: str) -> List[float]:
231231
@staticmethod
232232
def mock_embedding(text: str):
233233
res = [len(text) / 2, len(text) / 5, len(text) / 10]
234-
logging.debug("mock_embedding for " + text + " : " + str(res))
234+
logging.debug("mock_embedding for %s : %s", text, res)
235235
return res

0 commit comments

Comments
 (0)