Skip to content

Commit

Permalink
pre-commit and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
wenting-zhao committed Sep 19, 2024
1 parent 92ebb97 commit 5795a7e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
run: uv run commit0 test-reference simpy tests/test_event.py::test_succeed
- name: Evaluate
run: uv run commit0 evaluate-reference simpy
- name: Lint
run: uv run commit0 lint repos/simpy/src/simpy/events.py
- name: Save
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
Expand Down
16 changes: 11 additions & 5 deletions baselines/commit0_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,31 +245,37 @@ def args2string(agent_config: AgentConfig) -> str:


def get_changed_files(repo: git.Repo) -> list[str]:
"""
Get a list of files that were changed in the latest commit of the provided Git repository.
"""Get a list of files that were changed in the latest commit of the provided Git repository.
Args:
----
repo (git.Repo): An instance of GitPython's Repo object representing the Git repository.
Returns:
-------
list[str]: A list of filenames (as strings) that were changed in the latest commit.
"""
latest_commit = repo.head.commit
# Get the list of files changed in the latest commit
files_changed = latest_commit.stats.files
return list(files_changed.keys())
files_changed = [str(one) for one in files_changed]
return files_changed


def get_lint_cmd(repo: git.Repo, use_lint_info: bool) -> str:
"""
Generate a linting command based on whether to include files changed in the latest commit.
"""Generate a linting command based on whether to include files changed in the latest commit.
Args:
----
repo (git.Repo): An instance of GitPython's Repo object representing the Git repository.
use_lint_info (bool): A flag indicating whether to include changed files in the lint command.
Returns:
-------
str: The generated linting command string. If `use_lint_info` is True, the command includes
the list of changed files. If False, returns an empty string.
"""
lint_cmd = "python -m commit0 lint "
if use_lint_info:
Expand Down
10 changes: 6 additions & 4 deletions commit0/harness/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from pathlib import Path


config = \
"""repos:
config = """repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
Expand Down Expand Up @@ -32,14 +31,17 @@ def main(base_dir: str, files: list[str]) -> None:
config_file = Path(".commit0.pre-commit-config.yaml")
if not config_file.is_file():
config_file.write_text(config)
command = ['pre-commit', 'run', '--config', config_file, '--files'] + files
command = ["pre-commit", "run", "--config", config_file, "--files"] + files
try:
result = subprocess.run(command, capture_output=True, text=True, check=True)
print(result.stdout)
sys.exit(result.returncode)
except subprocess.CalledProcessError as e:
raise Exception(f"Pre-commit checks failed\n{e.output}")
except FileNotFoundError as e:
except FileNotFoundError:
raise FileNotFoundError("Error: pre-commit command not found. Is it installed?")
except Exception as e:
raise Exception(f"An unexpected error occurred: {e}")


__all__ = []

0 comments on commit 5795a7e

Please sign in to comment.