Skip to content

Commit fe97e96

Browse files
committed
Suppress output when installing pre-commit
1 parent 6741e51 commit fe97e96

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

repo_helper/cli/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
# stdlib
2727
import datetime
28+
import logging
2829
import os
29-
import sys
3030
import textwrap
3131
from typing import Iterable, Optional
3232

@@ -38,6 +38,7 @@
3838
from domdf_python_tools.terminal_colours import Fore
3939
from domdf_python_tools.typing import PathLike
4040
from dulwich.errors import CommitError
41+
from pre_commit.commands import install_uninstall # type: ignore
4142
from southwark import assert_clean
4243
from southwark.repo import Repo
4344

@@ -49,6 +50,11 @@
4950
"run_repo_helper",
5051
]
5152

53+
# Disable logging from pre-commit install command
54+
logging.getLogger(install_uninstall.__name__).addHandler(logging.NullHandler())
55+
logging.getLogger(install_uninstall.__name__).propagate = False
56+
logging.getLogger(install_uninstall.__name__).addFilter(lambda record: False)
57+
5258

5359
def commit_changed_files(
5460
repo_path: PathLike,
@@ -92,7 +98,6 @@ def commit_changed_files(
9298
if enable_pre_commit:
9399
with in_directory(repo_path):
94100
pre_commit.main.main(["install"])
95-
sys.stdout.flush()
96101

97102
if staged_files:
98103
click.echo("\nThe following files will be committed:")

tests/test_core_/test_via_run_repo_helper_stdout.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pre-commit installed at .git/hooks/pre-commit
21

32
The following files will be committed:
43
.dependabot/config.yml
@@ -41,5 +40,4 @@ The following files will be committed:
4140
tox.ini
4241

4342
Committed as 6d8cf72fff6adc4e570cb046ca417db7f2e10a3b
44-
pre-commit installed at .git/hooks/pre-commit
4543
Nothing to commit

0 commit comments

Comments
 (0)