Skip to content

Commit ecf4224

Browse files
committed
feat(bigquery): add dynamic logging banner to nox mypy session
1 parent 0d2d40d commit ecf4224

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

packages/google-cloud-bigquery/noxfile.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
from __future__ import absolute_import
1616

17+
import contextlib
1718
from functools import wraps
1819
import os
1920
import pathlib
21+
from typing import Generator
2022
import re
2123
import shutil
2224
import time
@@ -80,6 +82,26 @@ def wrapper(*args, **kwargs):
8082
]
8183

8284

85+
@contextlib.contextmanager
86+
def log_package_context(session: nox.Session) -> Generator[None, None, None]:
87+
"""Logs a highly visible package context banner right before a session exits.
88+
89+
Ensures metadata is printed adjacent to Nox's final status log,
90+
even if the session fails or raises an exception.
91+
"""
92+
# Dynamically extract current folder name (e.g., 'google-cloud-bigquery')
93+
# Falls back to the root directory name if run from the repo root
94+
package_name = os.path.basename(os.getcwd())
95+
96+
try:
97+
# Hands control back to the session code block
98+
yield
99+
finally:
100+
# This executes AFTER test output finishes, immediately above Nox's summary line
101+
banner_text = f"Finished session for {package_name.lower()}"
102+
session.log(banner_text)
103+
104+
83105
def default(session, install_extras=True):
84106
"""Default unit test session.
85107
@@ -193,7 +215,8 @@ def mypy(session):
193215
"types-setuptools",
194216
)
195217
session.run("python", "-m", "pip", "freeze")
196-
session.run("mypy", "-p", "google", "--show-traceback")
218+
with log_package_context(session):
219+
session.run("mypy", "-p", "google", "--show-traceback")
197220

198221

199222
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)

0 commit comments

Comments
 (0)