Skip to content

Commit

Permalink
warnings.showwarning: set earlier (spack#48462)
Browse files Browse the repository at this point in the history
Co-authored-by: haampie <haampie@users.noreply.github.com>
  • Loading branch information
haampie and haampie authored Jan 8, 2025
1 parent 434a8d5 commit 55d9fe2
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/spack/spack/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def make_argument_parser(**kwargs):
return parser


def send_warning_to_tty(message, category, filename, lineno, file=None, line=None):
def showwarning(message, category, filename, lineno, file=None, line=None):
"""Redirects messages to tty.warn."""
if category is spack.error.SpackAPIWarning:
tty.warn(f"{filename}:{lineno}: {message}")
Expand All @@ -513,9 +513,6 @@ def send_warning_to_tty(message, category, filename, lineno, file=None, line=Non

def setup_main_options(args):
"""Configure spack globals based on the basic options."""
# Assign a custom function to show warnings
warnings.showwarning = send_warning_to_tty

# Set up environment based on args.
tty.set_verbose(args.verbose)
tty.set_debug(args.debug)
Expand Down Expand Up @@ -906,9 +903,10 @@ def _main(argv=None):
# main() is tricky to get right, so be careful where you put things.
#
# Things in this first part of `main()` should *not* require any
# configuration. This doesn't include much -- setting up th parser,
# configuration. This doesn't include much -- setting up the parser,
# restoring some key environment variables, very simple CLI options, etc.
# ------------------------------------------------------------------------
warnings.showwarning = showwarning

# Create a parser with a simple positional argument first. We'll
# lazily load the subcommand(s) we need later. This allows us to
Expand Down

0 comments on commit 55d9fe2

Please sign in to comment.