Skip to content

Commit 5795a7e

Browse files
committed
pre-commit and ci
1 parent 92ebb97 commit 5795a7e

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

.github/workflows/system.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
run: uv run commit0 test-reference simpy tests/test_event.py::test_succeed
2929
- name: Evaluate
3030
run: uv run commit0 evaluate-reference simpy
31+
- name: Lint
32+
run: uv run commit0 lint repos/simpy/src/simpy/events.py
3133
- name: Save
3234
env:
3335
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

baselines/commit0_utils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,31 +245,37 @@ def args2string(agent_config: AgentConfig) -> str:
245245

246246

247247
def get_changed_files(repo: git.Repo) -> list[str]:
248-
"""
249-
Get a list of files that were changed in the latest commit of the provided Git repository.
248+
"""Get a list of files that were changed in the latest commit of the provided Git repository.
250249
251250
Args:
251+
----
252252
repo (git.Repo): An instance of GitPython's Repo object representing the Git repository.
253253
254254
Returns:
255+
-------
255256
list[str]: A list of filenames (as strings) that were changed in the latest commit.
257+
256258
"""
257259
latest_commit = repo.head.commit
258260
# Get the list of files changed in the latest commit
259261
files_changed = latest_commit.stats.files
260-
return list(files_changed.keys())
262+
files_changed = [str(one) for one in files_changed]
263+
return files_changed
264+
261265

262266
def get_lint_cmd(repo: git.Repo, use_lint_info: bool) -> str:
263-
"""
264-
Generate a linting command based on whether to include files changed in the latest commit.
267+
"""Generate a linting command based on whether to include files changed in the latest commit.
265268
266269
Args:
270+
----
267271
repo (git.Repo): An instance of GitPython's Repo object representing the Git repository.
268272
use_lint_info (bool): A flag indicating whether to include changed files in the lint command.
269273
270274
Returns:
275+
-------
271276
str: The generated linting command string. If `use_lint_info` is True, the command includes
272277
the list of changed files. If False, returns an empty string.
278+
273279
"""
274280
lint_cmd = "python -m commit0 lint "
275281
if use_lint_info:

commit0/harness/lint.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from pathlib import Path
44

55

6-
config = \
7-
"""repos:
6+
config = """repos:
87
# Standard hooks
98
- repo: https://github.com/pre-commit/pre-commit-hooks
109
rev: v4.3.0
@@ -32,14 +31,17 @@ def main(base_dir: str, files: list[str]) -> None:
3231
config_file = Path(".commit0.pre-commit-config.yaml")
3332
if not config_file.is_file():
3433
config_file.write_text(config)
35-
command = ['pre-commit', 'run', '--config', config_file, '--files'] + files
34+
command = ["pre-commit", "run", "--config", config_file, "--files"] + files
3635
try:
3736
result = subprocess.run(command, capture_output=True, text=True, check=True)
3837
print(result.stdout)
3938
sys.exit(result.returncode)
4039
except subprocess.CalledProcessError as e:
4140
raise Exception(f"Pre-commit checks failed\n{e.output}")
42-
except FileNotFoundError as e:
41+
except FileNotFoundError:
4342
raise FileNotFoundError("Error: pre-commit command not found. Is it installed?")
4443
except Exception as e:
4544
raise Exception(f"An unexpected error occurred: {e}")
45+
46+
47+
__all__ = []

0 commit comments

Comments
 (0)