|
14 | 14 |
|
15 | 15 | from __future__ import absolute_import |
16 | 16 |
|
| 17 | +import contextlib |
17 | 18 | from functools import wraps |
18 | 19 | import os |
19 | 20 | import pathlib |
| 21 | +from typing import Generator |
20 | 22 | import re |
21 | 23 | import shutil |
22 | 24 | import time |
@@ -80,6 +82,26 @@ def wrapper(*args, **kwargs): |
80 | 82 | ] |
81 | 83 |
|
82 | 84 |
|
| 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 | + |
83 | 105 | def default(session, install_extras=True): |
84 | 106 | """Default unit test session. |
85 | 107 |
|
@@ -193,7 +215,8 @@ def mypy(session): |
193 | 215 | "types-setuptools", |
194 | 216 | ) |
195 | 217 | 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") |
197 | 220 |
|
198 | 221 |
|
199 | 222 | @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) |
|
0 commit comments