Skip to content

Commit 1f78fc7

Browse files
committed
experiment: testing noxfile banner contextmanager
1 parent de4d787 commit 1f78fc7

1 file changed

Lines changed: 34 additions & 12 deletions

File tree

packages/bigframes/noxfile.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
from __future__ import absolute_import
1818

1919
import argparse
20+
import contextlib
2021
import multiprocessing
2122
import os
2223
import pathlib
2324
import re
2425
import shutil
2526
import time
26-
from typing import Dict, List
27+
from typing import Dict, Generator, List
2728

2829
import nox
2930
import nox.sessions
@@ -135,6 +136,25 @@
135136
# Error if a python version is missing
136137
nox.options.error_on_missing_interpreters = True
137138

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+
138158

139159
@nox.session(python=DEFAULT_PYTHON_VERSION)
140160
def lint(session):
@@ -1086,14 +1106,16 @@ def mypy(session):
10861106

10871107
session.install(*deps)
10881108
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

Comments
 (0)