Skip to content

Commit 5a65576

Browse files
authored
Remove warnings on CLI start (#502)
* add and test * fix * move warning removal to init logger * revert logger changes * remove revert again
1 parent a1286a7 commit 5a65576

File tree

4 files changed

+4
-19
lines changed

4 files changed

+4
-19
lines changed

patchwork/common/utils/progress_bar.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import contextlib
44
import functools
5-
import warnings
65
from collections import Counter
76

87
from rich.progress import Progress, SpinnerColumn, TimeElapsedColumn
@@ -18,7 +17,6 @@ class PatchflowProgressBar:
1817
def __init__(self, patchflow: Step):
1918
self.__step_counter = Counter()
2019
self.__current_progress = 0.00
21-
self.__callbacks = []
2220
self.__patchflow_name = patchflow.__class__.__name__
2321

2422
patchflow_run_func = patchflow.run
@@ -30,13 +28,9 @@ def inner_run():
3028
self.__progress_bar_update(
3129
description=f"[bold green]Finished {self.__patchflow_name}", completed=self.__MAX_PROGRESS
3230
)
33-
self.__do_callbacks()
3431

3532
patchflow.run = inner_run
3633

37-
def register_callbacks(self, *callbacks):
38-
self.__callbacks.extend(callbacks)
39-
4034
def register_steps(self, *steps: Type[Step]):
4135
for step in steps:
4236
self.register_step(step)
@@ -69,7 +63,6 @@ def __progress_bar(self):
6963

7064
@functools.cached_property
7165
def __progress_bar_update(self):
72-
self.__suppress_warnings()
7366
progress = self.__progress_bar
7467
logger.register_progress_bar(progress)
7568
task_id = progress.add_task(
@@ -87,11 +80,3 @@ def __update(self, step: type):
8780
self.__step_counter[step] += 1
8881
yield
8982
return
90-
91-
def __suppress_warnings(self):
92-
warnings.simplefilter("ignore")
93-
self.__callbacks.append(warnings.resetwarnings)
94-
95-
def __do_callbacks(self):
96-
for callbacks in self.__callbacks:
97-
callbacks()

patchwork/logger.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import logging
55
import os
6+
import warnings
67
from functools import partial
78

89
import click
@@ -138,6 +139,7 @@ def inner(record: logging.LogRecord) -> bool:
138139
def init_cli_logger(log_level: str) -> logging.Logger:
139140
global logger, __noop
140141

142+
warnings.simplefilter("ignore")
141143
logger.removeHandler(__noop)
142144

143145
if not os.path.exists(HOME_FOLDER): # Check if HOME_FOLDER exists at this point

patchwork/steps/CallLLM/CallLLM.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,11 @@ def run(self) -> dict:
226226
self.set_status(StepStatus.SKIPPED, "No prompts to process")
227227
return dict(openai_responses=[])
228228

229-
if prompt_length > self.call_limit:
229+
if -1 < self.call_limit < prompt_length:
230230
logger.debug(
231231
f"Number of prompts ({prompt_length}) exceeds the call limit ({self.call_limit}). "
232232
f"Only the first {self.call_limit} prompts will be processed."
233233
)
234-
235-
if self.call_limit > 0:
236234
prompts = list(islice(self.prompts, self.call_limit))
237235
else:
238236
prompts = self.prompts

patchwork/steps/PreparePR/PreparePR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def run(self) -> dict:
4747
placeholder_inner_text = path
4848
# TODO: consider dealing with line numbers exceeding diff chunk
4949
# if start_line is not None and end_line is not None:
50-
# placeholder_inner_text = f"{path}:{start_line+1}:{end_line}"
50+
# placeholder_inner_text = f"{path}:{start_line+1}:{end_line}"
5151
# chunk_link = "{{" + placeholder_inner_text + "}}"
5252

5353
if title != "" and patch_msg == "":

0 commit comments

Comments
 (0)