From 6f084ce5cd7eff6aab4ed94beb41211a084d6e96 Mon Sep 17 00:00:00 2001 From: Dave Hulbert Date: Sun, 3 Dec 2023 20:14:00 +0000 Subject: [PATCH] Linter fixes, dockblocks, clean up --- clipea/__main__.py | 9 +++++++-- clipea/commands.py | 13 +++++++------ tests/test_utils.py | 3 +++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/clipea/__main__.py b/clipea/__main__.py index b9a2dd2..eef29d9 100644 --- a/clipea/__main__.py +++ b/clipea/__main__.py @@ -6,11 +6,16 @@ def clipea_main() -> None: + """ + Main function for the Clipea. It checks if the "llm" dependency is installed + and then prompts the user for input. It then routes the user's input + to the appropriate command in the router. + """ if shutil.which("llm") is None: sys.exit('Error: dependency "llm" not found. Run "clipea setup" to install') - USER_PROMPT = " ".join(sys.argv[1:]) - router.commands_router(USER_PROMPT) + user_prompt = " ".join(sys.argv[1:]) + router.commands_router(user_prompt) if __name__ == "__main__": diff --git a/clipea/commands.py b/clipea/commands.py index de8b26c..728bdd8 100644 --- a/clipea/commands.py +++ b/clipea/commands.py @@ -8,7 +8,7 @@ def setup(): """Checks if `llm` has an openai key and prompt to change it or create one""" - import llm.cli + import llm.cli # pylint: disable=import-outside-toplevel should_setup = True path = llm.cli.user_dir() / "keys.json" @@ -22,7 +22,8 @@ def setup(): ) else: print("An OpenAI key is already set-up, proceed if you want to change it.") - llm.cli.keys_set() + # Trigger key setting (llm uses Click) + llm.cli.keys_set() # pylint: disable=no-value-for-parameter def clipea_execute_prompt(user_prompt: str): @@ -40,8 +41,8 @@ def clipea_execute_prompt(user_prompt: str): Args: user_prompt (str): user command input """ - from clipea import clipea_llm - from llm import Model, Response + from clipea import clipea_llm # pylint: disable=import-outside-toplevel + from llm import Model, Response # pylint: disable=import-outside-toplevel llm_name: str = '' if user_prompt.startswith('4 '): @@ -50,7 +51,7 @@ def clipea_execute_prompt(user_prompt: str): try: model: Model = clipea_llm.init_llm(llm_name) - except Exception as e: + except Exception as e: # pylint: disable=broad-exception-caught sys.exit(str(e)) user_data: str = cli.get_input() @@ -64,7 +65,7 @@ def clipea_execute_prompt(user_prompt: str): def alias(): """Gives zsh's alias (automatic command buffering) commands to the user""" shell: str = ENV["shell"] - if shell == "zsh" or shell == "-zsh": + if shell in ('zsh', '-zsh'): command: str = f"alias '??'='source {CLIPEA_DIR}/clipea.zsh'" user_prompt: str = f"Append this line to my {shell} startup file, \ watching out for quotes and escaping, then explain how to manually source it: {command}" diff --git a/tests/test_utils.py b/tests/test_utils.py index 3ae3622..a89906a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,9 @@ +"""Utils tests +""" from clipea import utils def test_anystr_force_str(): + """Basic test for anystr_force_str()""" assert utils.anystr_force_str(b'hello') == 'hello' assert utils.anystr_force_str('hello') == 'hello'