From 2ad99dfb939e9c4e8aeb91ee8a0e053c69d7baae Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 2 Apr 2024 10:02:12 -0700 Subject: [PATCH] add conditional to error formatting --- stdpopsim/cli.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stdpopsim/cli.py b/stdpopsim/cli.py index d8af80540..89747a544 100644 --- a/stdpopsim/cli.py +++ b/stdpopsim/cli.py @@ -13,6 +13,7 @@ import pathlib import shutil import os +import re import inspect import msprime @@ -54,6 +55,12 @@ class CLIFormatter(logging.Formatter): # DEBUG: Write out debug messages for the user/developer. def format(self, record): if record.name == "py.warnings": + if len(record.args) > 0: + # trim the ugly warnings.warn message + match = re.search( + r"Warning:\s*(.*?)\s*warnings.warn\(", record.args[0], re.DOTALL + ) + record.args = (match.group(1),) self._style = logging.PercentStyle("WARNING: %(message)s") else: if record.levelno == logging.WARNING: