Skip to content

Commit

Permalink
ping myself
Browse files Browse the repository at this point in the history
  • Loading branch information
ydshieh committed Sep 27, 2024
1 parent 54705c8 commit 03fd990
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions utils/check_commit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import re
import subprocess


Expand Down Expand Up @@ -28,55 +29,37 @@ def create_script(target_test):
fp.write(script.strip())


def create_script(target_test):

script = f"""
import os
import subprocess
def find_bad_commit(target_test, start_commit, end_commit):

create_script(target_test=target_test)

result = subprocess.run(
["python3", "-m", "pytest", "-v", f"{target_test}"],
capture_output = True,
text=True,
)
print(result.stdout)
if f"{target_test} FAILED" in result.stdout:
print("failed")
exit(2)
exit(0)
bash = f"""
git bisect reset
git bisect start {start_commit} {end_commit}
git bisect run python3 target_script.py
"""


with open("target_script.py", "w") as fp:
fp.write(script.strip())

def find_bad_commit(target_test):

create_script(target_test=target_test)
with open("run_git_bisect.sh", "w") as fp:
fp.write(bash.strip())

result = subprocess.run(
["python3", "-m", "pytest", "-v", f"{target_test}"],
["bash", "run_git_bisect.sh"],
capture_output = True,
text=True,
)
print(result.stdout)

pattern = r"(.+) is the first bad commit"
commits = re.findall(pattern, result.stdout)

print(result.stdout)

# git bisect start 317e069e 6d02968d

# # if a test not exist: should be a good commit instead of bad commit
# git bisect run "python3 target_script.py"

# git bisect reset

bad_commit = None
if len(commits) > 0:
bad_commit = commits[0]

return commit
print(f"Between `start_commit` {start_commit} and `end_commit` {end_commit}")
print(f"bad_commit: {bad_commit}\n")

return bad_commit


if __name__ == "__main__":
Expand All @@ -88,6 +71,7 @@ def find_bad_commit(target_test):
print(args.start_commit)
print(args.end_commit)

target_test = "tests/models/vit/test_modeling_vit.py::ViTModelTest::test_foo"
find_bad_commit(target_test=target_test, start_commit=args.start_commit, end_commit=args.end_commit)

target_test = "tests/models/vit/test_modeling_vit.py::ViTModelTest::test_foo"
find_bad_commit(target_test=target_test)
# python3 check_commit2.py --start_commit 54705c8a --end_commit 317e069e

0 comments on commit 03fd990

Please sign in to comment.