Skip to content

Commit

Permalink
Merge pull request #138 from reworkd/refactor
Browse files Browse the repository at this point in the history
✨ Delete unused files and prefix example related files with `example_`
  • Loading branch information
asim-shrestha authored Oct 20, 2024
2 parents bef253e + abf6beb commit 9bbd340
Show file tree
Hide file tree
Showing 30 changed files with 44 additions and 3,188 deletions.
118 changes: 0 additions & 118 deletions Makefile

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ Separately, there are specific `tags` that can be used further filter test inten
```python
import asyncio
from playwright.async_api import BrowserContext
from bananalyzer.data.schemas import Example
from bananalyzer.runner.agent_runner import AgentResult, AgentRunner
from bananalyzer import AgentResult, AgentRunner, Example


class NullAgentRunner(AgentRunner):
Expand Down
4 changes: 2 additions & 2 deletions bananalyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bananalyzer.__version import VERSION
from bananalyzer.data.examples import get_all_examples
from bananalyzer.data.schemas import Example, ExampleType
from bananalyzer.data.example_fetching import get_all_examples
from bananalyzer.data.example_schemas import ExampleType, Example
from bananalyzer.runner.agent_runner import AgentRunner, AgentResult
from bananalyzer.runner.evals import check_match, AllowedJSON

Expand Down
4 changes: 2 additions & 2 deletions bananalyzer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from urllib.parse import urlparse

from bananalyzer import AgentRunner
from bananalyzer.data.banana_seeds import download_har, download_mhtml
from bananalyzer.data.examples import (
from bananalyzer.data.example_fetching import (
download_examples,
get_examples_path,
get_test_examples,
get_training_examples,
)
from bananalyzer.data.example_s3 import download_har, download_mhtml
from bananalyzer.runner.generator import PytestTestGenerator
from bananalyzer.runner.runner import run_tests
from bananalyzer.schema import AgentRunnerClass, Args, PytestArgs, XDistArgs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json
from typing import Dict, Any

from bananalyzer.data.schemas import SchemaName
from bananalyzer.data.examples import get_examples_path
from bananalyzer.data.example_fetching import get_examples_path

"""
This file maps a schema_name to a JSON schema or goal string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from pathlib import Path
from typing import List, Optional

from bananalyzer.data.banana_seeds import download_examples_from_s3
from bananalyzer.data.schemas import Example
from bananalyzer.data.example_s3 import download_examples_from_s3
from bananalyzer.data.example_schemas import Example

local_examples_path: Path = Path(__file__).resolve().parent.parent.parent / "static"
downloaded_examples_path = Path.home() / ".bananalyzer_data"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def handle_json_match(self, result: AllowedJSON, field: Optional[str]) -> None:

class Example(BaseModel):
id: str
url: str | None
url: str
resource_path: Optional[str] = Field(
description="Local path of a HAR, S3 URL of a HAR directory's tar.gz, or remote URL of MHTML",
default=None,
Expand All @@ -142,7 +142,7 @@ def get_static_url(self) -> str:

@property
def har_file_path(self) -> Path:
from bananalyzer.data.examples import get_examples_path
from bananalyzer.data.example_fetching import get_examples_path

if self.source != "har":
raise ValueError("This example is not a HAR file")
Expand All @@ -166,7 +166,7 @@ def har_file_path(self) -> Path:

@model_validator(mode="before")
def set_schema_and_goal(cls, values: Dict[str, Any]) -> Dict[str, Any]:
from bananalyzer.data.fetch_schemas import get_fetch_schema, get_goal
from bananalyzer.data.example_detail_schemas import get_fetch_schema, get_goal

if values.get("schema_") is None:
print(f"Warning: Schema not found for Example {values['id']}")
Expand Down
157 changes: 0 additions & 157 deletions bananalyzer/data/generate_examples.py

This file was deleted.

2 changes: 1 addition & 1 deletion bananalyzer/runner/agent_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from playwright.async_api import Page

from bananalyzer.data.schemas import Example
from bananalyzer import Example
from bananalyzer.runner.evals import AllowedJSON

AgentResult = AllowedJSON
Expand Down
4 changes: 2 additions & 2 deletions bananalyzer/runner/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.parse import urlparse

from bananalyzer import Example
from bananalyzer.data.schemas import Eval
from bananalyzer.data.example_schemas import Eval
from bananalyzer.runner.runner import BananalyzerTest
from bananalyzer.schema import MARKER_PREFIX

Expand Down Expand Up @@ -89,7 +89,7 @@ async def test_{eval_.type}(self, page, result) -> None:
"""

def _generate_class_name(self, example: Example) -> str:
domain = urlparse(example.url).hostname
domain: str | None = urlparse(example.url).hostname
if not domain:
raise ValueError(f"Invalid URL (no domain name): {example.url}")
domain = domain.replace(".", "_")
Expand Down
3 changes: 2 additions & 1 deletion bananalyzer/runner/null_agent_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio

from playwright.async_api import Page

from bananalyzer.data.schemas import Example
from bananalyzer import Example
from bananalyzer.runner.agent_runner import AgentResult, AgentRunner


Expand Down
Loading

0 comments on commit 9bbd340

Please sign in to comment.