Skip to content

Commit 1aaaf56

Browse files
committed
Update lint.py
1 parent 9b50bf8 commit 1aaaf56

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

  • .manager/src/pypackit/script

.manager/src/pypackit/script/lint.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,21 @@ def __init__(
9999

100100
self._from_ref = ref_range[0] if ref_range else None
101101
self._to_ref = ref_range[1] if ref_range else None
102-
self._files = files
102+
if files:
103+
self._files = files
104+
elif self._from_ref:
105+
files = self._git.changed_files(ref_start=self._from_ref, ref_end=self._to_ref)
106+
self._files = [
107+
filename
108+
for change_type in ("added", "modified", "copied_modified", "renamed_modified")
109+
for filename in files.get(change_type, [])
110+
]
103111
self._hook_id = hook_id
104112
self._hook_stage = hook_stage
105113

106114
self._command = _CMD_PREFIX + [
107-
part for part in [
115+
part
116+
for part in [
108117
"pre-commit",
109118
"run",
110119
hook_id,
@@ -116,12 +125,8 @@ def __init__(
116125
"--hook-stage" if hook_stage else None,
117126
hook_stage,
118127
"--all-files" if all_files else None,
119-
"--files" if files else None,
120-
*(files or []),
121-
"--from-ref" if ref_range else None,
122-
self._from_ref,
123-
"--to-ref" if ref_range else None,
124-
self._to_ref,
128+
"--files" if self._files else None,
129+
*(self._files or []),
125130
]
126131
if part
127132
]
@@ -169,7 +174,11 @@ def raise_error(error: str):
169174
log_level_exit_code="error" if validation_run else "notice",
170175
)
171176
if result.err:
172-
err_lines = [line for line in sgr.remove_sequence(result.err.strip()).splitlines() if line and not line.startswith("ERROR conda.cli.main_run")]
177+
err_lines = [
178+
line
179+
for line in sgr.remove_sequence(result.err.strip()).splitlines()
180+
if line and not line.startswith("ERROR conda.cli.main_run")
181+
]
173182
if err_lines:
174183
raise_error("\n".join(err_lines))
175184
out_plain = sgr.remove_sequence(result.out)
@@ -331,7 +340,9 @@ def process_last_entry(details: str) -> tuple[str, str]:
331340
details_cleaned = details.replace(info_text, "").strip()
332341
lines = details_cleaned.splitlines()
333342
diff_line_indices = [
334-
idx for idx, line in enumerate(lines) if line.strip() == "All changes made by hooks:"
343+
idx
344+
for idx, line in enumerate(lines)
345+
if line.strip() == "All changes made by hooks:"
335346
]
336347
if not diff_line_indices:
337348
return details_cleaned, ""
@@ -409,10 +420,11 @@ def cli_parser(subparsers: argparse._SubParsersAction | None = None) -> argparse
409420
help="Required positional argument.",
410421
)
411422
parser.add_argument(
412-
"-c", "--config",
423+
"-c",
424+
"--config",
413425
help="Path to the pre-commit configuration file.",
414426
default=".devcontainer/config/pre-commit.yaml",
415-
)
427+
)
416428

417429
hook_group = parser.add_mutually_exclusive_group()
418430
hook_group.add_argument("-i", "--hook-id", help="Only run the hook with the given ID.")
@@ -434,4 +446,3 @@ def cli_parser(subparsers: argparse._SubParsersAction | None = None) -> argparse
434446
logger.initialize(realtime_levels=list(range(1, 7)))
435447
parser = cli_parser()
436448
run_cli(parser, parser.parse_args())
437-

0 commit comments

Comments
 (0)