Skip to content

Commit c91fc75

Browse files
GWealecopybara-github
authored andcommitted
fix: exclude scripts/ from pre-commit compliance checks
scripts/compliance_checks.py documents and matches the very patterns it forbids, so the compliance-checks hook (which scanned every .py file) flagged itself and failed on every PR running pre-commit on all files. Skip the dev-only scripts/ directory. Also clears pre-existing pyink and end-of-file drift surfaced by the same all-files run. Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 940618068
1 parent c5b2caa commit c91fc75

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

.github/workflows/continuous-integration.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,3 @@ jobs:
152152
-n auto \
153153
--ignore=tests/unittests/artifacts/test_artifact_service.py \
154154
--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py
155-
156-

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ repos:
6161
entry: scripts/compliance_checks.py
6262
language: script
6363
files: \.py$
64+
# This script documents and matches the very patterns it forbids, so
65+
# it must not scan itself or other dev-only tooling.
66+
exclude: ^scripts/
6467
- repo: https://github.com/executablebooks/mdformat
6568
rev: 0.7.22
6669
hooks:

scripts/compliance_checks.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888

8989
def check_logger(content: str) -> bool:
90-
# Forbidden: 'logger = logging.getLogger(__name__)'
90+
# Forbidden: getLogger(__name__) without the 'google_adk.' prefix.
9191
pattern = re.compile(r'logger\s*=\s*logging\.getLogger\(__name__\)')
9292
return not pattern.search(content)
9393

@@ -142,14 +142,15 @@ def main() -> None:
142142
with open(f, 'r', encoding='utf-8') as file:
143143
content = file.read()
144144
except Exception as e: # pylint: disable=broad-except
145-
print(f"Error reading {f}: {e}")
145+
print(f'Error reading {f}: {e}')
146146
continue
147147

148148
# Run checks
149149
if not check_logger(content):
150150
print(
151-
f"❌ {f}: Found forbidden use of 'logger = logging.getLogger(__name__)'. "
152-
"Please use 'logger = logging.getLogger(\"google_adk.\" + __name__)' instead."
151+
f"❌ {f}: Found forbidden use of 'logger ="
152+
" logging.getLogger(__name__)'. Please use 'logger ="
153+
' logging.getLogger("google_adk." + __name__)\' instead.'
153154
)
154155
failed = True
155156

@@ -159,13 +160,15 @@ def main() -> None:
159160

160161
if not check_cli_import(content, f):
161162
print(
162-
f"❌ {f}: Do not import from the cli package outside of the cli package."
163+
f'❌ {f}: Do not import from the cli package outside of the cli'
164+
' package.'
163165
)
164166
failed = True
165167

166168
if not check_mtls(content, f):
167169
print(
168-
f"❌ {f}: Found hardcoded googleapis.com endpoints without mTLS support."
170+
f'❌ {f}: Found hardcoded googleapis.com endpoints without mTLS'
171+
' support.'
169172
)
170173
failed = True
171174

0 commit comments

Comments
 (0)