|
17 | 17 | from __future__ import absolute_import |
18 | 18 |
|
19 | 19 | import argparse |
| 20 | +import contextlib |
20 | 21 | import multiprocessing |
21 | 22 | import os |
22 | 23 | import pathlib |
23 | 24 | import re |
24 | 25 | import shutil |
25 | 26 | import time |
26 | | -from typing import Dict, List |
| 27 | +from typing import Dict, Generator, List |
27 | 28 |
|
28 | 29 | import nox |
29 | 30 | import nox.sessions |
|
135 | 136 | # Error if a python version is missing |
136 | 137 | nox.options.error_on_missing_interpreters = True |
137 | 138 |
|
| 139 | +@contextlib.contextmanager |
| 140 | +def log_package_context(session: nox.Session) -> Generator[None, None, None]: |
| 141 | + """Logs a highly visible package context banner right before a session exits. |
| 142 | +
|
| 143 | + Ensures metadata is printed adjacent to Nox's final status log, |
| 144 | + even if the session fails or raises an exception. |
| 145 | + """ |
| 146 | + # Dynamically extract current folder name (e.g., 'bigframes') |
| 147 | + # Falls back to the root directory name if run from the repo root |
| 148 | + package_name = os.path.basename(os.getcwd()) |
| 149 | + |
| 150 | + try: |
| 151 | + # Hands control back to the session code block |
| 152 | + yield |
| 153 | + finally: |
| 154 | + # This executes AFTER test output finishes, immediately above Nox's summary line |
| 155 | + banner_text = f" Finished session for package: {package_name.upper()} " |
| 156 | + session.log(banner_text) |
| 157 | + |
138 | 158 |
|
139 | 159 | @nox.session(python=DEFAULT_PYTHON_VERSION) |
140 | 160 | def lint(session): |
@@ -1086,14 +1106,16 @@ def mypy(session): |
1086 | 1106 |
|
1087 | 1107 | session.install(*deps) |
1088 | 1108 | shutil.rmtree(".mypy_cache", ignore_errors=True) |
1089 | | - session.log("--- Running mypy (DINOSAUR) ---") |
1090 | | - session.run( |
1091 | | - "mypy", |
1092 | | - f"--config-file={MYPY_CONFIG_FILE}", |
1093 | | - "bigframes", |
1094 | | - os.path.join("tests", "system"), |
1095 | | - os.path.join("tests", "unit"), |
1096 | | - "--check-untyped-defs", |
1097 | | - "--explicit-package-bases", |
1098 | | - '--exclude="^third_party"', |
1099 | | - ) |
| 1109 | + |
| 1110 | + # Wrap runtime execution steps to inject package name logging |
| 1111 | + with log_package_context(session): |
| 1112 | + session.run( |
| 1113 | + "mypy", |
| 1114 | + f"--config-file={MYPY_CONFIG_FILE}", |
| 1115 | + "bigframes", |
| 1116 | + os.path.join("tests", "system"), |
| 1117 | + os.path.join("tests", "unit"), |
| 1118 | + "--check-untyped-defs", |
| 1119 | + "--explicit-package-bases", |
| 1120 | + '--exclude="^third_party"', |
| 1121 | + ) |
0 commit comments