From bb8966bb02c6bf8c6010b4b4290339f21c4f03d9 Mon Sep 17 00:00:00 2001 From: Bradley Axen Date: Tue, 3 Sep 2024 21:47:47 -0700 Subject: [PATCH] Apply ruff and add to CI (#40) --- .github/workflows/ci.yaml | 21 +++++++++++++-------- src/goose/cli/main.py | 12 ++++++++---- tests/cli/test_main.py | 13 +++++++++---- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ef5afb994..0fb1701e0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,14 +9,19 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Install UV - run: curl -LsSf https://astral.sh/uv/install.sh | sh + - name: Install UV + run: curl -LsSf https://astral.sh/uv/install.sh | sh - - name: Source Cargo Environment - run: source $HOME/.cargo/env + - name: Source Cargo Environment + run: source $HOME/.cargo/env - - name: Run tests - run: | - uv run pytest tests -m 'not integration' \ No newline at end of file + - name: Ruff + run: | + uvx ruff check + uvx ruff format --check + + - name: Run tests + run: | + uv run pytest tests -m 'not integration' diff --git a/src/goose/cli/main.py b/src/goose/cli/main.py index b79bbfab5..4ebcc2811 100644 --- a/src/goose/cli/main.py +++ b/src/goose/cli/main.py @@ -1,4 +1,3 @@ -import sys from datetime import datetime from pathlib import Path from typing import Dict, Optional @@ -12,10 +11,12 @@ from goose.utils import load_plugins from goose.utils.session_file import list_sorted_session_files + @click.group() def goose_cli() -> None: pass + @goose_cli.command() def version() -> None: """Lists the version of goose and any plugins""" @@ -100,14 +101,17 @@ def session_clear(keep: int) -> None: def get_session_files() -> Dict[str, Path]: return list_sorted_session_files(SESSIONS_PATH) + @click.group( - invoke_without_command=True, - name="goose", - help="AI-powered tool to assist in solving programming and operational tasks",) + invoke_without_command=True, + name="goose", + help="AI-powered tool to assist in solving programming and operational tasks", +) @click.pass_context def cli(_: click.Context, **kwargs: Dict) -> None: pass + all_cli_group_options = load_plugins("goose.cli.group_option") for option in all_cli_group_options.values(): cli = option()(cli) diff --git a/tests/cli/test_main.py b/tests/cli/test_main.py index 253aa3a3c..617b3d5c1 100644 --- a/tests/cli/test_main.py +++ b/tests/cli/test_main.py @@ -85,36 +85,41 @@ def test_session_clear_command(mock_session_files_path, create_session_file): def test_combined_group_option(): with patch("goose.utils.load_plugins") as mock_load_plugin: group_option_name = "--describe-commands" + def option_callback(ctx, *_): click.echo("Option callback") ctx.exit() + mock_group_options = { - 'option1': lambda: click.option( + "option1": lambda: click.option( group_option_name, is_flag=True, callback=option_callback, ), } + def side_effect_func(param): if param == "goose.cli.group_option": return mock_group_options elif param == "goose.cli.group": - return { } + return {} + mock_load_plugin.side_effect = side_effect_func # reload cli after mocking - importlib.reload(importlib.import_module('goose.cli.main')) + importlib.reload(importlib.import_module("goose.cli.main")) import goose.cli.main + cli = goose.cli.main.cli runner = CliRunner() result = runner.invoke(cli, [group_option_name]) assert result.exit_code == 0 + def test_combined_group_commands(mock_session): mock_session_class, mock_session_instance = mock_session runner = CliRunner() runner.invoke(cli, ["session", "resume", "session1", "--profile", "default"]) mock_session_class.assert_called_once_with(name="session1", profile="default") mock_session_instance.run.assert_called_once() -