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

infra: add print rule to ruff #16221

Merged
merged 9 commits into from
Feb 10, 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
2 changes: 1 addition & 1 deletion .github/scripts/check_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
else:
pass
json_output = json.dumps(list(dirs_to_run))
print(f"dirs-to-run={json_output}")
print(f"dirs-to-run={json_output}") # noqa: T201
4 changes: 3 additions & 1 deletion .github/scripts/get_min_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ def get_min_version_from_toml(toml_path: str):
# Call the function to get the minimum versions
min_versions = get_min_version_from_toml(toml_file)

print(" ".join([f"{lib}=={version}" for lib, version in min_versions.items()]))
print(
" ".join([f"{lib}=={version}" for lib, version in min_versions.items()])
) # noqa: T201
2 changes: 1 addition & 1 deletion .github/workflows/extract_ignored_words_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
pyproject_toml.get("tool", {}).get("codespell", {}).get("ignore-words-list")
)

print(f"::set-output name=ignore_words_list::{ignore_words_list}")
print(f"::set-output name=ignore_words_list::{ignore_words_list}") # noqa: T201
3 changes: 2 additions & 1 deletion docs/api_reference/create_api_rst.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Script for auto-generating api_reference.rst."""

import importlib
import inspect
import os
Expand Down Expand Up @@ -186,7 +187,7 @@ def _load_package_modules(
modules_by_namespace[top_namespace] = _module_members

except ImportError as e:
print(f"Error: Unable to import module '{namespace}' with error: {e}")
print(f"Error: Unable to import module '{namespace}' with error: {e}") # noqa: T201

return modules_by_namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def __init__(self, name):
self.name = name

def greet(self):
print(f"Hello, {self.name}!")
print(f"Hello, {self.name}!") # noqa: T201


def main():
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/generate_api_reference_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def main():
global_imports = {}

for file in find_files(args.docs_dir):
print(f"Adding links for imports in {file}")
print(f"Adding links for imports in {file}") # noqa: T201
file_imports = replace_imports(file)

if file_imports:
Expand Down
1 change: 1 addition & 0 deletions libs/cli/langchain_cli/integration_template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"T201", # print
]

[tool.mypy]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
SourceFileLoader("x", file).load_module()
except Exception:
has_faillure = True
print(file)
print(file) # noqa: T201
traceback.print_exc()
print()
print() # noqa: T201

sys.exit(1 if has_failure else 0)
1 change: 1 addition & 0 deletions libs/cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"T201", # print
]

[tool.poe.tasks]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
if SPACE_KEY == "SPACE_KEY" or API_KEY == "API_KEY":
raise ValueError("❌ CHANGE SPACE AND API KEYS")
else:
print("✅ Arize client setup done! Now you can start using Arize!")
print("✅ Arize client setup done! Now you can start using Arize!") # noqa: T201

def on_llm_start(
self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any
Expand Down Expand Up @@ -161,9 +161,9 @@ def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None:
environment=Environments.PRODUCTION,
)
if response_from_arize.status_code == 200:
print("✅ Successfully logged data to Arize!")
print("✅ Successfully logged data to Arize!") # noqa: T201
else:
print(f'❌ Logging failed "{response_from_arize.text}"')
print(f'❌ Logging failed "{response_from_arize.text}"') # noqa: T201

def on_llm_error(self, error: BaseException, **kwargs: Any) -> None:
"""Do nothing."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ def flush_tracker(
target_filename=name,
)
except NotImplementedError as e:
print("Could not save model.")
print(repr(e))
print("Could not save model.") # noqa: T201
print(repr(e)) # noqa: T201
pass

# Cleanup after adding everything to ClearML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None:
output=output,
query=query,
)
print(f"Answer Relevancy: {result}")
print(f"Answer Relevancy: {result}") # noqa: T201
elif isinstance(metric, UnBiasedMetric):
score = metric.measure(output)
print(f"Bias Score: {score}")
print(f"Bias Score: {score}") # noqa: T201
elif isinstance(metric, NonToxicMetric):
score = metric.measure(output)
print(f"Toxic Score: {score}")
print(f"Toxic Score: {score}") # noqa: T201
else:
raise ValueError(
f"""Metric {metric.__name__} is not supported by deepeval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _send_to_infino(
},
}
if self.verbose:
print(f"Tracking {key} with Infino: {payload}")
print(f"Tracking {key} with Infino: {payload}") # noqa: T201

# Append to Infino time series only if is_ts is True, otherwise
# append to Infino log.
Expand Down Expand Up @@ -245,7 +245,7 @@ def on_chat_model_start(
self._send_to_infino("prompt_tokens", prompt_tokens)

if self.verbose:
print(
print( # noqa: T201
f"on_chat_model_start: is_chat_openai_model= \
{self.is_chat_openai_model}, \
chat_openai_model_name={self.chat_openai_model_name}"
Expand Down
14 changes: 8 additions & 6 deletions libs/community/langchain_community/callbacks/mlflow_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,11 @@ def on_retriever_end(
{
"page_content": doc.page_content,
"metadata": {
k: str(v)
if not isinstance(v, list)
else ",".join(str(x) for x in v)
k: (
str(v)
if not isinstance(v, list)
else ",".join(str(x) for x in v)
)
for k, v in doc.metadata.items()
},
}
Expand Down Expand Up @@ -757,15 +759,15 @@ def flush_tracker(self, langchain_asset: Any = None, finish: bool = False) -> No
langchain_asset.save_agent(langchain_asset_path)
self.mlflg.artifact(langchain_asset_path)
except AttributeError:
print("Could not save model.")
print("Could not save model.") # noqa: T201
traceback.print_exc()
pass
except NotImplementedError:
print("Could not save model.")
print("Could not save model.") # noqa: T201
traceback.print_exc()
pass
except NotImplementedError:
print("Could not save model.")
print("Could not save model.") # noqa: T201
traceback.print_exc()
pass
if finish:
Expand Down
12 changes: 7 additions & 5 deletions libs/community/langchain_community/callbacks/wandb_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ def flush_tracker(
model_artifact.add_file(str(langchain_asset_path))
model_artifact.metadata = load_json_to_dict(langchain_asset_path)
except NotImplementedError as e:
print("Could not save model.")
print(repr(e))
print("Could not save model.") # noqa: T201
print(repr(e)) # noqa: T201
pass
self.run.log_artifact(model_artifact)

Expand All @@ -577,7 +577,9 @@ def flush_tracker(
name=name if name else self.name,
notes=notes if notes else self.notes,
visualize=visualize if visualize else self.visualize,
complexity_metrics=complexity_metrics
if complexity_metrics
else self.complexity_metrics,
complexity_metrics=(
complexity_metrics
if complexity_metrics
else self.complexity_metrics
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RocksetChatMessageHistory(BaseChatMessageHistory):
history.add_user_message("hi!")
history.add_ai_message("whats up?")

print(history.messages)
print(history.messages) # noqa: T201
"""

# You should set these values based on your VI.
Expand Down
5 changes: 3 additions & 2 deletions libs/community/langchain_community/chat_models/deepinfra.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""deepinfra.com chat models wrapper"""

from __future__ import annotations

import json
Expand Down Expand Up @@ -207,7 +208,7 @@ def _completion_with_retry(**kwargs: Any) -> Any:
return response
except Exception as e:
# import pdb; pdb.set_trace()
print("EX", e)
print("EX", e) # noqa: T201
raise

return _completion_with_retry(**kwargs)
Expand All @@ -231,7 +232,7 @@ async def _completion_with_retry(**kwargs: Any) -> Any:
self._handle_status(response.status, response.text)
return await response.json()
except Exception as e:
print("EX", e)
print("EX", e) # noqa: T201
raise

return await _completion_with_retry(**kwargs)
Expand Down
7 changes: 4 additions & 3 deletions libs/community/langchain_community/chat_models/human.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ChatModel wrapper which returns user input as the response.."""

from io import StringIO
from typing import Any, Callable, Dict, List, Mapping, Optional

Expand Down Expand Up @@ -30,9 +31,9 @@ def _display_messages(messages: List[BaseMessage]) -> None:
width=10000,
line_break=None,
)
print("\n", "======= start of message =======", "\n\n")
print(yaml_string)
print("======= end of message =======", "\n\n")
print("\n", "======= start of message =======", "\n\n") # noqa: T201
print(yaml_string) # noqa: T201
print("======= end of message =======", "\n\n") # noqa: T201


def _collect_yaml_input(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def load(self) -> List[Document]:
)
transcript_response.raise_for_status()
except Exception as e:
print(f"An error occurred: {e}")
print(f"An error occurred: {e}") # noqa: T201
raise

transcript = transcript_response.json()["text"]
Expand All @@ -166,7 +166,7 @@ def load(self) -> List[Document]:
)
paragraphs_response.raise_for_status()
except Exception as e:
print(f"An error occurred: {e}")
print(f"An error occurred: {e}") # noqa: T201
raise

paragraphs = paragraphs_response.json()["paragraphs"]
Expand All @@ -181,7 +181,7 @@ def load(self) -> List[Document]:
)
sentences_response.raise_for_status()
except Exception as e:
print(f"An error occurred: {e}")
print(f"An error occurred: {e}") # noqa: T201
raise

sentences = sentences_response.json()["sentences"]
Expand All @@ -196,7 +196,7 @@ def load(self) -> List[Document]:
)
srt_response.raise_for_status()
except Exception as e:
print(f"An error occurred: {e}")
print(f"An error occurred: {e}") # noqa: T201
raise

srt = srt_response.text
Expand All @@ -211,7 +211,7 @@ def load(self) -> List[Document]:
)
vtt_response.raise_for_status()
except Exception as e:
print(f"An error occurred: {e}")
print(f"An error occurred: {e}") # noqa: T201
raise

vtt = vtt_response.text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ def load(self) -> List[Document]:
documents = []
for path in relative_paths:
url = self.base_url + path
print(f"Fetching documents from {url}")
print(f"Fetching documents from {url}") # noqa: T201
soup_info = self._scrape(url)
with contextlib.suppress(ValueError):
documents.extend(self._get_documents(soup_info))
return documents
else:
print(f"Fetching documents from {self.web_path}")
print(f"Fetching documents from {self.web_path}") # noqa: T201
soup_info = self.scrape()
self.folder_path = self._get_folder_path(soup_info)
return self._get_documents(soup_info)
Expand Down Expand Up @@ -295,4 +295,4 @@ def _parse_filename_from_url(self, url: str) -> str:
load_all_recursively=True,
)
documents = loader.load()
print(f"Loaded {len(documents)} pages of PDFs from {loader.web_path}")
print(f"Loaded {len(documents)} pages of PDFs from {loader.web_path}") # noqa: T201
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Use to load blobs from the local file system."""

from pathlib import Path
from typing import Callable, Iterable, Iterator, Optional, Sequence, TypeVar, Union

Expand Down Expand Up @@ -46,7 +47,7 @@ class FileSystemBlobLoader(BlobLoader):
from langchain_community.document_loaders.blob_loaders import FileSystemBlobLoader
loader = FileSystemBlobLoader("/path/to/directory")
for blob in loader.yield_blobs():
print(blob)
print(blob) # noqa: T201
""" # noqa: E501

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def process_attachment(
texts.append(text)
except requests.HTTPError as e:
if e.response.status_code == 404:
print(f"Attachment not found at {absolute_url}")
print(f"Attachment not found at {absolute_url}") # noqa: T201
continue
else:
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _load_file_from_path(self, file_path: str) -> Optional[Document]:
file_extension = os.path.splitext(file_path)[1].lower()

if file_extension == ".pdf":
print(f"File {file_path} type detected as .pdf")
print(f"File {file_path} type detected as .pdf") # noqa: T201
from langchain_community.document_loaders import UnstructuredPDFLoader

# Download it to a temporary file.
Expand All @@ -136,10 +136,10 @@ def _load_file_from_path(self, file_path: str) -> Optional[Document]:
if docs:
return docs[0]
except Exception as pdf_ex:
print(f"Error while trying to parse PDF {file_path}: {pdf_ex}")
print(f"Error while trying to parse PDF {file_path}: {pdf_ex}") # noqa: T201
return None
else:
print(
print( # noqa: T201
f"File {file_path} could not be decoded as pdf or text. Skipping."
)

Expand Down
Loading