From 83c93631b2e47da3b7f8b2291535db1911f2efa7 Mon Sep 17 00:00:00 2001 From: zt Date: Thu, 14 Nov 2024 11:49:07 +0800 Subject: [PATCH] styling: lint --- collect_script.py | 62 ++++++++++++++++++++------------------- examples/data_analysis.py | 8 ++--- pyproject.toml | 8 +++++ src/tablegpt/__init__.py | 4 +-- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/collect_script.py b/collect_script.py index 72632ab..9cb2d30 100644 --- a/collect_script.py +++ b/collect_script.py @@ -1,49 +1,50 @@ import platform -import sys import subprocess -import traceback +import sys + def get_os_info(): return { - 'system': platform.system(), - 'node': platform.node(), - 'release': platform.release(), - 'version': platform.version(), - 'machine': platform.machine(), - 'processor': platform.processor(), + "system": platform.system(), + "node": platform.node(), + "release": platform.release(), + "version": platform.version(), + "machine": platform.machine(), + "processor": platform.processor(), } + def get_python_info(): return { - 'implementation': platform.python_implementation(), - 'version': platform.python_version(), - 'compiler': platform.python_compiler(), + "implementation": platform.python_implementation(), + "version": platform.python_version(), + "compiler": platform.python_compiler(), } + def get_pip_list(): - try: - result = subprocess.run([sys.executable, '-m', 'pip', 'list'], capture_output=True, text=True) - if result.returncode == 0: - return result.stdout - else: - return f"Failed to get pip list: {result.stderr}" - except Exception as e: - return f"An error occurred: {str(e)}" - -def write_to_log_file(content, filename='env_output.log'): - try: - with open(filename, 'w') as file: - file.write(content) - except Exception as e: - print(f"Error writing to file {filename}: {e}") - traceback.print_exc() + result = subprocess.run( + [sys.executable, "-m", "pip", "list"], + capture_output=True, + text=True, + check=False, + ) + if result.returncode == 0: + return result.stdout + + return f"Failed to get pip list: {result.stderr}" + + +def write_to_log_file(content, filename="env_output.log"): + with open(filename, "w") as file: + file.write(content) + def main(): os_info = get_os_info() python_info = get_python_info() pip_list = get_pip_list() - content = "Operating System Information:\n" for key, value in os_info.items(): content += f"{key}: {value}\n" @@ -56,10 +57,11 @@ def main(): content += pip_list # stdout - print(content) + print(content) # noqa: T201 # file write_to_log_file(content) + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/examples/data_analysis.py b/examples/data_analysis.py index ecd4dff..35a2ca4 100644 --- a/examples/data_analysis.py +++ b/examples/data_analysis.py @@ -27,9 +27,7 @@ async def main() -> None: ) # Use local pybox manager for development and testing - pybox_manager = LocalPyBoxManager( - profile_dir=DEFAULT_TABLEGPT_IPYKERNEL_PROFILE_DIR - ) + pybox_manager = LocalPyBoxManager(profile_dir=DEFAULT_TABLEGPT_IPYKERNEL_PROFILE_DIR) agent = create_tablegpt_graph( llm=llm, @@ -44,9 +42,7 @@ async def main() -> None: attachment_msg = HumanMessage( content="", # The dataset can be viewed in examples/datasets/titanic.csv. - additional_kwargs={ - "attachments": [Attachment(filename="examples/datasets/titanic.csv")] - }, + additional_kwargs={"attachments": [Attachment(filename="examples/datasets/titanic.csv")]}, ) await agent.ainvoke( input={ diff --git a/pyproject.toml b/pyproject.toml index 85ca7f6..bf4a217 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,3 +99,11 @@ exclude_lines = [ "if __name__ == .__main__.:", "if TYPE_CHECKING:", ] + +[tool.ruff] +# Exclude a variety of commonly ignored directories. +exclude = [ + "ipython" +] +# Allow lines to be as long as 120. +line-length = 120 diff --git a/src/tablegpt/__init__.py b/src/tablegpt/__init__.py index e3086fd..9a04f6d 100644 --- a/src/tablegpt/__init__.py +++ b/src/tablegpt/__init__.py @@ -1,6 +1,4 @@ import os import sys -DEFAULT_TABLEGPT_IPYKERNEL_PROFILE_DIR = os.path.join( - sys.prefix, "share/ipykernel/profile/tablegpt" -) +DEFAULT_TABLEGPT_IPYKERNEL_PROFILE_DIR = os.path.join(sys.prefix, "share/ipykernel/profile/tablegpt")