diff --git a/github_resolver/io_utils.py b/github_resolver/io_utils.py new file mode 100644 index 0000000..00aa7f9 --- /dev/null +++ b/github_resolver/io_utils.py @@ -0,0 +1,11 @@ +import json +from github_resolver.resolver_output import ResolverOutput + + +def load_resolver_output(output_jsonl: str, issue_number: int) -> ResolverOutput: + with open(output_jsonl, "r") as f: + for line in f: + data = json.loads(line) + if data["issue"]["number"] == issue_number: + return ResolverOutput.model_validate(data) + raise ValueError(f"Issue number {issue_number} not found in {output_jsonl}") diff --git a/github_resolver/send_pull_request.py b/github_resolver/send_pull_request.py index 418cba9..c50aa49 100644 --- a/github_resolver/send_pull_request.py +++ b/github_resolver/send_pull_request.py @@ -1,23 +1,13 @@ import argparse import os -import json import shutil from github_resolver.github_issue import GithubIssue -from github_resolver.resolver_output import ResolverOutput +from github_resolver.io_utils import load_resolver_output import requests import subprocess import whatthepatch -def load_resolver_output(output_jsonl: str, issue_number: int) -> ResolverOutput: - with open(output_jsonl, 'r') as f: - for line in f: - data = json.loads(line) - if data['issue']['number'] == issue_number: - return ResolverOutput.model_validate(data) - raise ValueError(f"Issue number {issue_number} not found in {output_jsonl}") - - def apply_patch(repo_dir: str, patch: str) -> None: diffs = whatthepatch.parse_patch(patch) diff --git a/github_resolver/utils.py b/github_resolver/utils.py index 7eb4779..abf96b0 100644 --- a/github_resolver/utils.py +++ b/github_resolver/utils.py @@ -12,7 +12,6 @@ from openhands.events.action import Action from openhands.events.action.message import MessageAction - def codeact_user_response( state: State, encapsulate_solution: bool = False, diff --git a/github_resolver/visualize_resolver_output.py b/github_resolver/visualize_resolver_output.py new file mode 100644 index 0000000..ddd379e --- /dev/null +++ b/github_resolver/visualize_resolver_output.py @@ -0,0 +1,42 @@ +import argparse +import os +from github_resolver.io_utils import load_resolver_output + + +def visualize_resolver_output(issue_number: int, output_dir: str, vis_method: str): + output_jsonl = os.path.join(output_dir, "output.jsonl") + resolver_output = load_resolver_output(output_jsonl, issue_number) + if vis_method == "json": + print(resolver_output.model_dump_json(indent=4)) + else: + raise ValueError(f"Invalid visualization method: {vis_method}") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Visualize a patch.") + parser.add_argument( + "--issue-number", + type=int, + required=True, + help="Issue number to send the pull request for.", + ) + parser.add_argument( + "--output-dir", + type=str, + default="output", + help="Output directory to write the results.", + ) + parser.add_argument( + "--vis-method", + type=str, + default="json", + choices=["json"], + help="Method to visualize the patch [json].", + ) + my_args = parser.parse_args() + + visualize_resolver_output( + issue_number=my_args.issue_number, + output_dir=my_args.output_dir, + vis_method=my_args.vis_method, + ) diff --git a/poetry.lock b/poetry.lock index 3ea321d..8d9f2a8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -342,6 +342,50 @@ charset-normalizer = ["charset-normalizer"] html5lib = ["html5lib"] lxml = ["lxml"] +[[package]] +name = "black" +version = "24.8.0" +description = "The uncompromising code formatter." +optional = false +python-versions = ">=3.8" +files = [ + {file = "black-24.8.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:09cdeb74d494ec023ded657f7092ba518e8cf78fa8386155e4a03fdcc44679e6"}, + {file = "black-24.8.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:81c6742da39f33b08e791da38410f32e27d632260e599df7245cccee2064afeb"}, + {file = "black-24.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:707a1ca89221bc8a1a64fb5e15ef39cd755633daa672a9db7498d1c19de66a42"}, + {file = "black-24.8.0-cp310-cp310-win_amd64.whl", hash = "sha256:d6417535d99c37cee4091a2f24eb2b6d5ec42b144d50f1f2e436d9fe1916fe1a"}, + {file = "black-24.8.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:fb6e2c0b86bbd43dee042e48059c9ad7830abd5c94b0bc518c0eeec57c3eddc1"}, + {file = "black-24.8.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:837fd281f1908d0076844bc2b801ad2d369c78c45cf800cad7b61686051041af"}, + {file = "black-24.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:62e8730977f0b77998029da7971fa896ceefa2c4c4933fcd593fa599ecbf97a4"}, + {file = "black-24.8.0-cp311-cp311-win_amd64.whl", hash = "sha256:72901b4913cbac8972ad911dc4098d5753704d1f3c56e44ae8dce99eecb0e3af"}, + {file = "black-24.8.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:7c046c1d1eeb7aea9335da62472481d3bbf3fd986e093cffd35f4385c94ae368"}, + {file = "black-24.8.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:649f6d84ccbae73ab767e206772cc2d7a393a001070a4c814a546afd0d423aed"}, + {file = "black-24.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2b59b250fdba5f9a9cd9d0ece6e6d993d91ce877d121d161e4698af3eb9c1018"}, + {file = "black-24.8.0-cp312-cp312-win_amd64.whl", hash = "sha256:6e55d30d44bed36593c3163b9bc63bf58b3b30e4611e4d88a0c3c239930ed5b2"}, + {file = "black-24.8.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:505289f17ceda596658ae81b61ebbe2d9b25aa78067035184ed0a9d855d18afd"}, + {file = "black-24.8.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b19c9ad992c7883ad84c9b22aaa73562a16b819c1d8db7a1a1a49fb7ec13c7d2"}, + {file = "black-24.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1f13f7f386f86f8121d76599114bb8c17b69d962137fc70efe56137727c7047e"}, + {file = "black-24.8.0-cp38-cp38-win_amd64.whl", hash = "sha256:f490dbd59680d809ca31efdae20e634f3fae27fba3ce0ba3208333b713bc3920"}, + {file = "black-24.8.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:eab4dd44ce80dea27dc69db40dab62d4ca96112f87996bca68cd75639aeb2e4c"}, + {file = "black-24.8.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3c4285573d4897a7610054af5a890bde7c65cb466040c5f0c8b732812d7f0e5e"}, + {file = "black-24.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9e84e33b37be070ba135176c123ae52a51f82306def9f7d063ee302ecab2cf47"}, + {file = "black-24.8.0-cp39-cp39-win_amd64.whl", hash = "sha256:73bbf84ed136e45d451a260c6b73ed674652f90a2b3211d6a35e78054563a9bb"}, + {file = "black-24.8.0-py3-none-any.whl", hash = "sha256:972085c618ee94f402da1af548a4f218c754ea7e5dc70acb168bfaca4c2542ed"}, + {file = "black-24.8.0.tar.gz", hash = "sha256:2500945420b6784c38b9ee885af039f5e7471ef284ab03fa35ecdde4688cd83f"}, +] + +[package.dependencies] +click = ">=8.0.0" +mypy-extensions = ">=0.4.3" +packaging = ">=22.0" +pathspec = ">=0.9.0" +platformdirs = ">=2" + +[package.extras] +colorama = ["colorama (>=0.4.3)"] +d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"] +jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] +uvloop = ["uvloop (>=0.15.2)"] + [[package]] name = "blinker" version = "1.8.2" @@ -3271,6 +3315,22 @@ tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "pa typing = ["typing-extensions"] xmp = ["defusedxml"] +[[package]] +name = "platformdirs" +version = "4.2.2" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`." +optional = false +python-versions = ">=3.8" +files = [ + {file = "platformdirs-4.2.2-py3-none-any.whl", hash = "sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee"}, + {file = "platformdirs-4.2.2.tar.gz", hash = "sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3"}, +] + +[package.extras] +docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] +type = ["mypy (>=1.8)"] + [[package]] name = "playwright" version = "1.39.0" @@ -5374,4 +5434,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "4b31962fa300bf5d98a38ae3ee191f20886d9ed0849d1f52aa5a263633b6d17a" +content-hash = "805887e73bde9c89ac60dedbeb7edceed9a71e8081eecbfe35b5d65377958f50" diff --git a/pyproject.toml b/pyproject.toml index 200a4b5..62005a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ whatthepatch = "*" [tool.poetry.group.dev.dependencies] mypy = "*" ruff = "*" +black = "*" types-requests = "*" types-whatthepatch = "*"