Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions python/private/stage2_bootstrap_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import runpy
import types
import uuid
import warnings
from functools import cache

# ===== Template substitutions start =====
Expand Down Expand Up @@ -585,4 +586,24 @@ def main():
sys.exit(0)


# To help eliminate nondeterministic output, particularly when remotely
# executing, we here wrap Python's formatwarning() to cause it to
# produce paths relative to the current directory as of the launch of
# the executable.

original_formatwarning = warnings.formatwarning
original_cwd = os.getcwd()


def relpath_formatwarning(message, category, filename, lineno, line=None):
relative_filename = (
os.path.relpath(filename, original_cwd) if os.path.isabs(filename) else filename
)
return original_formatwarning(
message, category, relative_filename, lineno, line=line
)


warnings.formatwarning = relpath_formatwarning

main()
Loading