Skip to content

Commit 2b8ce67

Browse files
committed
Improved Logging
1 parent 43c4f2e commit 2b8ce67

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

scripts/hooks/update/60.pre-commit.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def run_pre_commit_cmd(path: Path, args: list[str], label: str) -> bool:
4040
stdout=subprocess.PIPE,
4141
stderr=subprocess.PIPE,
4242
)
43-
print_info(f"{label} succeeded in: {path}")
43+
print_info(f"{label} in {path.name}")
4444
return True
4545
except subprocess.CalledProcessError as e:
46-
print_error(f"{label} failed in {path}:\n{e.stderr.decode()}")
46+
print_error(f"{label} failed in {path.name}:\n{e.stderr.decode()}")
4747
return False
4848

4949

@@ -69,6 +69,8 @@ def ensure_pre_commit_available():
6969
return False
7070

7171
return True
72+
73+
7274
def collect_precommit_repos(base_path: Path) -> list[Path]:
7375
repos = []
7476
for root, dirs, files in os.walk(base_path):
@@ -91,17 +93,6 @@ def update(**_) -> bool:
9193
"Failed to ensure 'pre-commit' is available. Cannot install pre-commit hooks."
9294
)
9395
return False
94-
for root, _, _ in os.walk(base_path):
95-
root_path = Path(root)
96-
if is_git_repo(root_path):
97-
if has_pre_commit_config(root_path):
98-
if not is_pre_commit_installed(root_path):
99-
success &= install_pre_commit(root_path)
100-
count = count + 1 if success else count
101-
if count > 0:
102-
print_info(f"Installed pre-commit hooks in {count} repositories.")
103-
elif count == 0:
104-
print_info("No pre-commit hooks to install.")
10596

10697
repos = collect_precommit_repos(base_path)
10798

@@ -112,7 +103,7 @@ def update(**_) -> bool:
112103
# First: install hooks sequentially
113104
for repo in repos:
114105
if not is_pre_commit_installed(repo):
115-
if run_pre_commit_cmd(repo, ["install"], "Install pre-commit"):
106+
if run_pre_commit_cmd(repo, ["install"], "Installing pre-commit"):
116107
installed_count += 1
117108
else:
118109
success = False
@@ -122,7 +113,7 @@ def update(**_) -> bool:
122113
with ThreadPoolExecutor() as executor:
123114
futures = {
124115
executor.submit(
125-
run_pre_commit_cmd, repo, ["autoupdate"], "Autoupdate pre-commit"
116+
run_pre_commit_cmd, repo, ["autoupdate"], "Autoupdating pre-commit"
126117
): repo
127118
for repo in repos
128119
}

0 commit comments

Comments
 (0)