Skip to content

Commit

Permalink
🚀 Upgrade linting to use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
awtkns committed Jan 15, 2024
1 parent 779e60c commit d593732
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 644 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
- run: poetry install
- name: Run isort check
run: poetry run isort --check .
- name: Run lint check
run: poetry run ruff check
- name: Run black check
run: poetry run black --check .
run: poetry run ruff format --check

mypy:
runs-on: ubuntu-latest
Expand Down
10 changes: 3 additions & 7 deletions bananalyzer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
import argparse
import ast
import importlib.util
import os
import sys
from pathlib import Path
from typing import List
from urllib.parse import urlparse

import requests

from bananalyzer import AgentRunner
from bananalyzer.data.examples import (
download_examples,
get_test_examples,
get_training_examples,
)
Expand Down Expand Up @@ -49,14 +45,14 @@ def print_intro() -> None:
def parse_args() -> Args:
file_name = "bananalyzer-agent.py"
parser = argparse.ArgumentParser(
description=f"Run the agent inside a bananalyzer agent definition file "
f"against the benchmark",
description="Run the agent inside a bananalyzer agent definition file "
"against the benchmark",
)
parser.add_argument(
"path", type=str, nargs="?", default=None, help=f"Path to the {file_name} file"
)
parser.add_argument(
"--headless", action="store_true", help=f"Whether to run headless or not"
"--headless", action="store_true", help="Whether to run headless or not"
)
parser.add_argument(
"-s",
Expand Down
2 changes: 1 addition & 1 deletion bananalyzer/data/generate_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, Dict, List

from openai import OpenAI
from playwright.async_api import Page, async_playwright
from playwright.async_api import async_playwright
from tarsier import GoogleVisionOCRService, Tarsier

from bananalyzer.data.examples import convert_to_crlf
Expand Down
11 changes: 3 additions & 8 deletions bananalyzer/data/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, Dict, List, Literal, Optional, Union

import pydantic
from playwright.async_api import Page
from pydantic import BaseModel, Field, model_validator

Expand Down Expand Up @@ -42,18 +41,14 @@ def eval_results(
if (
self.type == "json_match"
and field is not None
and type(self.expected) is dict
and isinstance(self.expected, dict)
):
return validate_field_match(self.expected, result, field)

if (
self.type == "json_match"
and type(self.expected) is dict
or type(self.expected) is list
):
if self.type == "json_match" and isinstance(self.expected, (list, dict)):
return validate_json_match(self.expected, result)

if self.type == "end_url_match" and type(self.expected) is str:
if self.type == "end_url_match" and isinstance(self.expected, str):
return validate_end_url_match(self.expected, page.url)

raise NotImplementedError("No evaluation type implemented")
Expand Down
893 changes: 280 additions & 613 deletions poetry.lock

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bananalyzer"
version = "0.7.3"
version = "0.7.4"

description = "Open source AI Agent evaluation framework for web tasks 🐒🍌"
authors = ["asim-shrestha <asim.shrestha@hotmail.com>"]
Expand All @@ -15,30 +15,23 @@ playwright = "^1.39.0"
pydantic = "^2.4.2"
pytest-asyncio = "^0.21.1"
deepdiff = "^6.7.0"
pytest-xdist = "^3.4.0"
black = { extras = ["jupyter"], version = "^23.11.0" }
pytest = "^7.4.2"
pytest-html = "^4.1.1"
pytest-xdist = "^3.4.0"
tabulate = "^0.9.0"
requests = "^2.31.0"
tarsier = "^0.5.0"
openai = "^1.3.7"

[tool.poetry.group.test.dependencies]
pytest = "^7.4.2"
pytest-mock = "^3.11.1"
pytest-cov = "^4.1.0"

[tool.poetry.group.dev.dependencies]
mypy = "^1.6.1"
black = { extras = ["jupyter"], version = "^23.11.0" }
types-requests = "^2.31.0.10"
isort = "^5.12.0"
types-tabulate = "^0.9.0.3"

[tool.isort]
profile = "black"
multi_line_output = 3
src_paths = ["bananalyzer", "tests"]
ruff = "^0.1.13"

[tool.mypy]
plugins = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_example_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_url_eval(mocker: MockFixture) -> None:


def create_default_example(
overrides: Optional[Dict[str, Any]] = None
overrides: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
default_example: Dict[str, Any] = {
"id": "1",
Expand Down

0 comments on commit d593732

Please sign in to comment.