Skip to content

Commit

Permalink
add ruff rule ignore comment
Browse files Browse the repository at this point in the history
  • Loading branch information
XianBW committed Jun 12, 2024
1 parent a75ed2e commit 4e4c710
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
20 changes: 10 additions & 10 deletions rdagent/app/CI/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def __init__(self, project_path: Path | str, excludes: list[Path] | None = None,
excludes = [self.project_path / path for path in excludes]

git_ignored_output = subprocess.check_output(
["/usr/bin/git", "status", "--ignored", "-s"],
["/usr/bin/git", "status", "--ignored", "-s"], # noqa: S603
cwd=str(self.project_path),
stderr=subprocess.STDOUT,
text=True,
Expand Down Expand Up @@ -287,10 +287,10 @@ def __init__(self, command: str | None = None) -> None:

@staticmethod
def explain_rule(error_code: str) -> RuffRule:
explain_command = f"ruff rule {error_code} --output-format json".split()
explain_command = f"ruff rule {error_code} --output-format json"
try:
out = subprocess.check_output(
explain_command,
shlex.split(explain_command), # noqa: S603
stderr=subprocess.STDOUT,
text=True,
)
Expand All @@ -300,11 +300,11 @@ def explain_rule(error_code: str) -> RuffRule:
return RuffRule(**json.loads(out))


def evaluate(self, evo: Repo, **kwargs: Any) -> CIFeedback:
def evaluate(self, evo: Repo, **kwargs: Any) -> CIFeedback: # noqa: ARG002
"""Simply run ruff to get the feedbacks."""
try:
out = subprocess.check_output(
shlex.split(self.command),
shlex.split(self.command), # noqa: S603
cwd=evo.project_path,
stderr=subprocess.STDOUT,
text=True,
Expand Down Expand Up @@ -356,10 +356,10 @@ def __init__(self, command: str | None = None) -> None:
else:
self.command = command

def evaluate(self, evo: Repo, **kwargs: Any) -> CIFeedback:
def evaluate(self, evo: Repo, **kwargs: Any) -> CIFeedback: # noqa: ARG002
try:
out = subprocess.check_output(
shlex.split(self.command),
shlex.split(self.command), # noqa: S603
cwd=evo.project_path,
stderr=subprocess.STDOUT,
text=True,
Expand Down Expand Up @@ -419,12 +419,12 @@ def evaluate(self, evo: Repo, **kwargs: Any) -> CIFeedback:
return CIFeedback(errors=all_errors)

class CIEvoStr(EvolvingStrategy):
def evolve(
def evolve( # noqa: C901, PLR0912, PLR0915
self,
evo: Repo,
evolving_trace: list[EvoStep] | None = None,
knowledge_l: list[Knowledge] | None = None,
**kwargs: Any,
knowledge_l: list[Knowledge] | None = None, # noqa: ARG002
**kwargs: Any, # noqa: ARG002
) -> Repo:

@dataclass
Expand Down
2 changes: 1 addition & 1 deletion rdagent/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from fuzzywuzzy import fuzz


class RDAgentException(Exception):
class RDAgentException(Exception): # noqa: N818
pass


Expand Down
2 changes: 1 addition & 1 deletion rdagent/document_process/document_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def __deduplicate_factor_dict(factor_dict: dict[str, dict[str, str]]) -> list[li
return duplication_names_list


def deduplicate_factors_by_llm(
def deduplicate_factors_by_llm( # noqa: C901, PLR0912
factor_dict: dict[str, dict[str, str]],
factor_viability_dict: dict[str, dict[str, str]] | None = None,
) -> list[list[str]]:
Expand Down
2 changes: 1 addition & 1 deletion rdagent/knowledge_management/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def add_node(
self,
node: UndirectedNode,
neighbor: UndirectedNode = None,
same_node_threshold: float = 0.95,
same_node_threshold: float = 0.95, # noqa: ARG002
) -> None:
"""
add node and neighbor to the Graph
Expand Down
26 changes: 14 additions & 12 deletions rdagent/oai/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def build_chat_completion(self, user_prompt: str, **kwargs: Any) -> str:
"""
messages = self.build_chat_completion_message(user_prompt, **kwargs)

response = self.api_backend._try_create_chat_completion_or_embedding(
response = self.api_backend._try_create_chat_completion_or_embedding( # noqa: SLF001
messages=messages, chat_completion=True, **kwargs,
)
messages.append(
Expand All @@ -225,7 +225,7 @@ def display_history(self) -> None:


class APIBackend:
def __init__(
def __init__( # noqa: C901, PLR0912, PLR0915
self,
*,
chat_api_key: str | None = None,
Expand Down Expand Up @@ -285,7 +285,7 @@ def __init__(
self.gcr_endpoint_do_sample = self.cfg.gcr_endpoint_do_sample
self.gcr_endpoint_max_token = self.cfg.gcr_endpoint_max_token
if not os.environ.get("PYTHONHTTPSVERIFY", "") and hasattr(ssl, "_create_unverified_context"):
ssl._create_default_https_context = ssl._create_unverified_context
ssl._create_default_https_context = ssl._create_unverified_context # noqa: SLF001
self.encoder = None
else:
self.use_azure = self.cfg.use_azure
Expand Down Expand Up @@ -406,8 +406,9 @@ def build_messages_and_create_chat_completion(
user_prompt: str,
system_prompt: str | None = None,
former_messages: list | None = None,
shrink_multiple_break: bool = False,
chat_cache_prefix: str = "",
*,
shrink_multiple_break: bool = False,
**kwargs: Any,
) -> str:
if former_messages is None:
Expand Down Expand Up @@ -462,7 +463,7 @@ def _try_create_chat_completion_or_embedding(
return self._create_embedding_inner_function(**kwargs)
if chat_completion:
return self._create_chat_completion_auto_continue(**kwargs)
except openai.BadRequestError as e:
except openai.BadRequestError as e: # noqa: PERF203
print(e)
print(f"Retrying {i+1}th time...")
if "'messages' must contain the word 'json' in some form" in e.message:
Expand All @@ -471,14 +472,14 @@ def _try_create_chat_completion_or_embedding(
kwargs["input_content_list"] = [
content[: len(content) // 2] for content in kwargs.get("input_content_list", [])
]
except Exception as e:
except Exception as e: # noqa: BLE001
print(e)
print(f"Retrying {i+1}th time...")
time.sleep(self.retry_wait_seconds)
error_message = f"Failed to create chat completion after {max_retry} retries."
raise RuntimeError(error_message)

def _create_embedding_inner_function(self, input_content_list: list[str], **kwargs: Any) -> list[Any]:
def _create_embedding_inner_function(self, input_content_list: list[str], **kwargs: Any) -> list[Any]: # noqa: ARG002
content_to_embedding_dict = {}
filtered_input_content_list = []
if self.use_embedding_cache:
Expand Down Expand Up @@ -532,16 +533,17 @@ def log_response(self, response: str | None = None, *, stream: bool = False) ->
else:
FinCoLog().info(f"\n{LogColors.CYAN}Response:{response}{LogColors.END}")

def _create_chat_completion_inner_function(
def _create_chat_completion_inner_function( # noqa: C901, PLR0912, PLR0915
self,
messages: list[dict],
temperature: float | None = None,
max_tokens: int | None = None,
chat_cache_prefix: str = "",
json_mode: bool = False,
add_json_in_prompt: bool = False,
frequency_penalty: float | None = None,
presence_penalty: float | None = None,
*,
json_mode: bool = False,
add_json_in_prompt: bool = False,
) -> str:
self.log_messages(messages)
# TODO: fail to use loguru adaptor due to stream response
Expand Down Expand Up @@ -589,8 +591,8 @@ def _create_chat_completion_inner_function(
),
)

req = urllib.request.Request(self.gcr_endpoint, body, self.headers)
response = urllib.request.urlopen(req)
req = urllib.request.Request(self.gcr_endpoint, body, self.headers) # noqa: S310
response = urllib.request.urlopen(req) # noqa: S310
resp = json.loads(response.read().decode())["output"]
self.log_response(resp)
else:
Expand Down

0 comments on commit 4e4c710

Please sign in to comment.